Skip to content

Missing file pybind11Targets.cmake? #1733

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
VictorEijkhout opened this issue Mar 19, 2019 · 5 comments · Fixed by #2338
Closed

Missing file pybind11Targets.cmake? #1733

VictorEijkhout opened this issue Mar 19, 2019 · 5 comments · Fixed by #2338

Comments

@VictorEijkhout
Copy link

I have what looks like a successful installation of pybind11, but building another package on top of it causes a message that pybind11Targets.cmake is missing. Which it is.

There are one or two more tickets about this, but they kinda seem to have "gone away of their own accord".

My installation is nothing special:

cmake \ 
    -D CMAKE_INSTALL_PREFIX=${PYBIND11_INSTALL} \ 
    -D PYTHON_EXECUTABLE=`which python3` \ 
    -D PYBIND11_INSTALL=ON \ 
    -D PYBIND11_MASTER_PROJECT=ON \
    -D PYBIND11_TEST=OFF \ 
   ${PYBIND11_SRC}```

(Some of those options are pure voodoo programming....)
@VictorEijkhout
Copy link
Author

No?

@espdev
Copy link

espdev commented Apr 9, 2019

I have the same error while configuring onnx project via cmake (3.8.2).

CMake Error at C:/B/pybind11/install/cmake/pybind11/pybind11Config.cmake:108 (include):
  include could not find load file:

    C:/B/pybind11/install/cmake/pybind11/pybind11Targets.cmake
Call Stack (most recent call first):
  CMakeLists.txt:365 (find_package)

The file "pybind11Targets.cmake" just missing in cmake/pybind11 directory after configuring and installing pybind11 project.

@espdev
Copy link

espdev commented Apr 9, 2019

And I do not know why the targets file was not created.

The code in CMakeLists.txt where Targets file should be created looks right.

  if(NOT (CMAKE_VERSION VERSION_LESS 3.0))
    if(NOT PYBIND11_EXPORT_NAME)
      set(PYBIND11_EXPORT_NAME "${PROJECT_NAME}Targets")
    endif()

    install(TARGETS pybind11 module embed
            EXPORT "${PYBIND11_EXPORT_NAME}")  # <--- create targets file
    if(PYBIND11_MASTER_PROJECT)
      install(EXPORT "${PYBIND11_EXPORT_NAME}"
              NAMESPACE "${PROJECT_NAME}::"
              DESTINATION ${PYBIND11_CMAKECONFIG_INSTALL_DIR})
    endif()
  endif()

I change CMakeLists.txt (just add message) and rebuilt INSTALL project in VS and the file was created. I do not know what's happening... maybe a bug in cmake.

@costrau
Copy link

costrau commented Jun 26, 2019

I have the same issue and found a solution. In my case pybind11 was used in cmake using add_subdirectory(). Thus, the pybind11 check for being a master project in CMakesLists.txt line 22

# Check if pybind11 is being used directly or via add_subdirectory
set(PYBIND11_MASTER_PROJECT OFF)
if (CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR)
  set(PYBIND11_MASTER_PROJECT ON)
endif()

ended up with PYBIND11_MASTER_PROJECT being turned off. This again only changes the behaviour in line 151

    if(PYBIND11_MASTER_PROJECT)
      install(EXPORT "${PYBIND11_EXPORT_NAME}"
              NAMESPACE "${PROJECT_NAME}::"
              DESTINATION ${PYBIND11_CMAKECONFIG_INSTALL_DIR})
    endif()

All in all, disabling the check and setting PYBIND11_MASTER_PROJECT to on solved the issue for me.

@ZedThree
Copy link

I've just run into this problem when trying to create a library that uses pybind11. I managed to work around it by installing the targets in my CMakeLists.txt, but I'm worried this is pretty fragile.

What breaks if the check on L151 is removed? I guess the targets don't need to be installed for an executable, but they are required for libraries.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants