fix: duplicate target names removed

This commit is contained in:
Henry Schreiner 2020-08-01 15:53:11 -04:00 committed by Henry Schreiner
parent df115977df
commit da803eb0a5
7 changed files with 44 additions and 39 deletions

View File

@ -1,7 +1,7 @@
add_custom_target(test_cmake_build)
function(pybind11_add_build_test name)
cmake_parse_arguments(ARG "INSTALL" "" "" ${ARGN})
cmake_parse_arguments(PARSE_ARGV 1 ARG "INSTALL" "" "")
set(build_options
"-DCMAKE_PREFIX_PATH=${pybind11_BINARY_DIR}/mock_install"
@ -14,10 +14,12 @@ function(pybind11_add_build_test name)
if(NOT ARG_INSTALL)
list(APPEND build_options "-DPYBIND11_PROJECT_DIR=${pybind11_SOURCE_DIR}")
else()
list(APPEND build_options "-DCMAKE_PREFIX_PATH=${pybind11_BINARY_DIR}/mock_install")
endif()
add_custom_target(
test_${name}
test_build_${name}
${CMAKE_CTEST_COMMAND}
--build-and-test
"${CMAKE_CURRENT_SOURCE_DIR}/${name}"
@ -32,13 +34,13 @@ function(pybind11_add_build_test name)
--build-makeprogram
${CMAKE_MAKE_PROGRAM}
--build-target
check
check_${name}
--build-options
${build_options})
if(ARG_INSTALL)
add_dependencies(test_${name} mock_install)
add_dependencies(test_build_${name} mock_install)
endif()
add_dependencies(test_cmake_build test_${name})
add_dependencies(test_cmake_build test_build_${name})
endfunction()
pybind11_add_build_test(subdirectory_function)

View File

@ -11,15 +11,16 @@ endif()
project(test_installed_embed CXX)
set(CMAKE_MODULE_PATH "")
find_package(pybind11 CONFIG REQUIRED)
message(STATUS "Found pybind11 v${pybind11_VERSION}: ${pybind11_INCLUDE_DIRS}")
add_executable(test_cmake_build ../embed.cpp)
target_link_libraries(test_cmake_build PRIVATE pybind11::embed)
add_executable(test_installed_embed ../embed.cpp)
target_link_libraries(test_installed_embed PRIVATE pybind11::embed)
set_target_properties(test_installed_embed PROPERTIES OUTPUT_NAME test_cmake_build)
# Do not treat includes from IMPORTED target as SYSTEM (Python headers in pybind11::embed).
# This may be needed to resolve header conflicts, e.g. between Python release and debug headers.
set_target_properties(test_cmake_build PROPERTIES NO_SYSTEM_FROM_IMPORTED ON)
set_target_properties(test_installed_embed PROPERTIES NO_SYSTEM_FROM_IMPORTED ON)
add_custom_target(check $<TARGET_FILE:test_cmake_build> ${PROJECT_SOURCE_DIR}/../test.py)
add_custom_target(check_installed_embed $<TARGET_FILE:test_installed_embed>
${PROJECT_SOURCE_DIR}/../test.py)

View File

@ -9,22 +9,21 @@ else()
cmake_policy(VERSION 3.18)
endif()
project(test_installed_module CXX)
set(CMAKE_MODULE_PATH "")
project(test_installed_function CXX)
find_package(pybind11 CONFIG REQUIRED)
message(
STATUS "Found pybind11 v${pybind11_VERSION} ${pybind11_VERSION_TYPE}: ${pybind11_INCLUDE_DIRS}")
pybind11_add_module(test_cmake_build SHARED NO_EXTRAS ../main.cpp)
pybind11_add_module(test_installed_function SHARED NO_EXTRAS ../main.cpp)
set_target_properties(test_installed_function PROPERTIES OUTPUT_NAME test_cmake_build)
add_custom_target(
check
check_installed_function
${CMAKE_COMMAND}
-E
env
PYTHONPATH=$<TARGET_FILE_DIR:test_cmake_build>
PYTHONPATH=$<TARGET_FILE_DIR:test_installed_function>
${PYTHON_EXECUTABLE}
${PROJECT_SOURCE_DIR}/../test.py
${PROJECT_NAME})

View File

@ -11,29 +11,28 @@ endif()
project(test_installed_target CXX)
set(CMAKE_MODULE_PATH "")
find_package(pybind11 CONFIG REQUIRED)
message(STATUS "Found pybind11 v${pybind11_VERSION}: ${pybind11_INCLUDE_DIRS}")
add_library(test_cmake_build MODULE ../main.cpp)
add_library(test_installed_target MODULE ../main.cpp)
target_link_libraries(test_cmake_build PRIVATE pybind11::module)
target_link_libraries(test_installed_target PRIVATE pybind11::module)
set_target_properties(test_installed_target PROPERTIES OUTPUT_NAME test_cmake_build)
# make sure result is, for example, test_installed_target.so, not libtest_installed_target.dylib
set_target_properties(test_cmake_build PROPERTIES PREFIX "${PYTHON_MODULE_PREFIX}"
set_target_properties(test_installed_target PROPERTIES PREFIX "${PYTHON_MODULE_PREFIX}"
SUFFIX "${PYTHON_MODULE_EXTENSION}")
# Do not treat includes from IMPORTED target as SYSTEM (Python headers in pybind11::module).
# This may be needed to resolve header conflicts, e.g. between Python release and debug headers.
set_target_properties(test_cmake_build PROPERTIES NO_SYSTEM_FROM_IMPORTED ON)
set_target_properties(test_installed_target PROPERTIES NO_SYSTEM_FROM_IMPORTED ON)
add_custom_target(
check
check_installed_target
${CMAKE_COMMAND}
-E
env
PYTHONPATH=$<TARGET_FILE_DIR:test_cmake_build>
PYTHONPATH=$<TARGET_FILE_DIR:test_installed_target>
${PYTHON_EXECUTABLE}
${PROJECT_SOURCE_DIR}/../test.py
${PROJECT_NAME})

View File

@ -19,10 +19,12 @@ set(PYBIND11_EXPORT_NAME test_export)
add_subdirectory(${PYBIND11_PROJECT_DIR} pybind11)
# Test basic target functionality
add_executable(test_cmake_build ../embed.cpp)
target_link_libraries(test_cmake_build PRIVATE pybind11::embed)
add_executable(test_subdirectory_embed ../embed.cpp)
target_link_libraries(test_subdirectory_embed PRIVATE pybind11::embed)
set_target_properties(test_subdirectory_embed PROPERTIES OUTPUT_NAME test_cmake_build)
add_custom_target(check $<TARGET_FILE:test_cmake_build> ${PROJECT_SOURCE_DIR}/../test.py)
add_custom_target(check_subdirectory_embed $<TARGET_FILE:test_subdirectory_embed>
${PROJECT_SOURCE_DIR}/../test.py)
# Test custom export group -- PYBIND11_EXPORT_NAME
add_library(test_embed_lib ../embed.cpp)

View File

@ -9,17 +9,18 @@ else()
cmake_policy(VERSION 3.18)
endif()
project(test_subdirectory_module CXX)
project(test_subdirectory_function CXX)
add_subdirectory(${PYBIND11_PROJECT_DIR} pybind11)
pybind11_add_module(test_cmake_build THIN_LTO ../main.cpp)
add_subdirectory("${PYBIND11_PROJECT_DIR}" pybind11)
pybind11_add_module(test_subdirectory_function THIN_LTO ../main.cpp)
set_target_properties(test_subdirectory_function PROPERTIES OUTPUT_NAME test_cmake_build)
add_custom_target(
check
check_subdirectory_function
${CMAKE_COMMAND}
-E
env
PYTHONPATH=$<TARGET_FILE_DIR:test_cmake_build>
PYTHONPATH=$<TARGET_FILE_DIR:test_subdirectory_function>
${PYTHON_EXECUTABLE}
${PROJECT_SOURCE_DIR}/../test.py
${PROJECT_NAME})

View File

@ -13,20 +13,21 @@ project(test_subdirectory_target CXX)
add_subdirectory(${PYBIND11_PROJECT_DIR} pybind11)
add_library(test_cmake_build MODULE ../main.cpp)
add_library(test_subdirectory_target MODULE ../main.cpp)
set_target_properties(test_subdirectory_target PROPERTIES OUTPUT_NAME test_cmake_build)
target_link_libraries(test_cmake_build PRIVATE pybind11::module)
target_link_libraries(test_subdirectory_target PRIVATE pybind11::module)
# make sure result is, for example, test_installed_target.so, not libtest_installed_target.dylib
set_target_properties(test_cmake_build PROPERTIES PREFIX "${PYTHON_MODULE_PREFIX}"
set_target_properties(test_subdirectory_target PROPERTIES PREFIX "${PYTHON_MODULE_PREFIX}"
SUFFIX "${PYTHON_MODULE_EXTENSION}")
add_custom_target(
check
check_subdirectory_target
${CMAKE_COMMAND}
-E
env
PYTHONPATH=$<TARGET_FILE_DIR:test_cmake_build>
PYTHONPATH=$<TARGET_FILE_DIR:test_subdirectory_target>
${PYTHON_EXECUTABLE}
${PROJECT_SOURCE_DIR}/../test.py
${PROJECT_NAME})