Skip to content

Missing file pybind11Targets.cmake? #1733

Closed

Description

@VictorEijkhout

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....)

Activity

  1. VictorEijkhout commented on Mar 25, 2019

    @VictorEijkhout
    Author

    No?

  2. espdev commented on Apr 9, 2019

    @espdev

    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.

  3. espdev commented on Apr 9, 2019

    @espdev

    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.

  4. costrau commented on Jun 26, 2019

    @costrau

    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.

  5. ZedThree commented on Jun 24, 2020

    @ZedThree

    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions