mirror of
https://github.com/RYDE-WORK/pybind11.git
synced 2026-01-29 02:23:27 +08:00
39 lines
1.5 KiB
CMake
39 lines
1.5 KiB
CMake
cmake_minimum_required(VERSION 3.7)
|
|
|
|
# The `cmake_minimum_required(VERSION 3.7...3.18)` syntax does not work with
|
|
# some versions of VS that have a patched CMake 3.11. This forces us to emulate
|
|
# the behavior using the following workaround:
|
|
if(${CMAKE_VERSION} VERSION_LESS 3.18)
|
|
cmake_policy(VERSION ${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION})
|
|
else()
|
|
cmake_policy(VERSION 3.18)
|
|
endif()
|
|
|
|
project(test_installed_target CXX)
|
|
|
|
find_package(pybind11 CONFIG REQUIRED)
|
|
message(STATUS "Found pybind11 v${pybind11_VERSION}: ${pybind11_INCLUDE_DIRS}")
|
|
|
|
add_library(test_installed_target MODULE ../main.cpp)
|
|
|
|
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_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_installed_target PROPERTIES NO_SYSTEM_FROM_IMPORTED ON)
|
|
|
|
add_custom_target(
|
|
check_installed_target
|
|
${CMAKE_COMMAND}
|
|
-E
|
|
env
|
|
PYTHONPATH=$<TARGET_FILE_DIR:test_installed_target>
|
|
${PYTHON_EXECUTABLE}
|
|
${PROJECT_SOURCE_DIR}/../test.py
|
|
${PROJECT_NAME})
|