diff --git a/CMakeLists.txt b/CMakeLists.txt index ea14ee2dcb..81e0d85987 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -247,6 +247,7 @@ else() set(PYBIND11_INSTALL OFF) endif() +set(_pybind11_is_config OFF) include("${CMAKE_CURRENT_SOURCE_DIR}/tools/pybind11Common.cmake") # https://github.com/jtojnar/cmake-snips/#concatenating-paths-when-building-pkg-config-files # TODO: cmake 3.20 adds the cmake_path() function, which obsoletes this snippet diff --git a/tools/pybind11Common.cmake b/tools/pybind11Common.cmake index 0cbec2b2b3..d8ed0c8878 100644 --- a/tools/pybind11Common.cmake +++ b/tools/pybind11Common.cmake @@ -28,11 +28,7 @@ endif() # are in CONFIG mode, they should be "normal" targets instead. # In CMake 3.11+ you can promote a target to global after you create it, # which might be simpler than this check. -get_property( - is_config - TARGET pybind11::pybind11_headers - PROPERTY IMPORTED) -if(NOT is_config) +if(NOT _pybind11_is_config) set(optional_global GLOBAL) endif() diff --git a/tools/pybind11Config.cmake.in b/tools/pybind11Config.cmake.in index 304f1d9077..1f73dde34f 100644 --- a/tools/pybind11Config.cmake.in +++ b/tools/pybind11Config.cmake.in @@ -84,7 +84,7 @@ you can either use the basic targets, or use the FindPython tools: # Python method: Python_add_library(MyModule2 src2.cpp) - target_link_libraries(MyModule2 pybind11::headers) + target_link_libraries(MyModule2 PUBLIC pybind11::headers) set_target_properties(MyModule2 PROPERTIES INTERPROCEDURAL_OPTIMIZATION ON CXX_VISIBILITY_PRESET ON @@ -222,7 +222,7 @@ include("${CMAKE_CURRENT_LIST_DIR}/pybind11Targets.cmake") add_library(pybind11::headers IMPORTED INTERFACE) set_target_properties(pybind11::headers PROPERTIES INTERFACE_LINK_LIBRARIES pybind11::pybind11_headers) - +set(_pybind11_is_config ON) include("${CMAKE_CURRENT_LIST_DIR}/pybind11Common.cmake") if(NOT pybind11_FIND_QUIETLY)