|
| 1 | +# Builds and installs libpython_template_cpp without Python, for conda, vcpkg, and system packages. |
| 2 | +cmake_minimum_required(VERSION 3.20) |
| 3 | +project(python_template_cpp VERSION 0.1.0 LANGUAGES CXX) |
| 4 | + |
| 5 | +include(CMakePackageConfigHelpers) |
| 6 | + |
| 7 | +add_library(python_template_cpp SHARED python-template-cpp/c_api.cpp python-template-cpp/example.cpp) |
| 8 | +add_library(python_template_cpp::python_template_cpp ALIAS python_template_cpp) |
| 9 | +target_compile_features(python_template_cpp PRIVATE cxx_std_17) |
| 10 | +target_compile_definitions(python_template_cpp PRIVATE PYTHON_TEMPLATE_CPP_BUILD) |
| 11 | +target_include_directories( |
| 12 | + python_template_cpp |
| 13 | + PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/../python_template_cpp/include> $<INSTALL_INTERFACE:include> |
| 14 | + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} |
| 15 | +) |
| 16 | +# SOVERSION is PYTHON_TEMPLATE_CPP_ABI_VERSION. |
| 17 | +set_target_properties( |
| 18 | + python_template_cpp |
| 19 | + PROPERTIES VERSION ${PROJECT_VERSION} |
| 20 | + SOVERSION 1 |
| 21 | + CXX_VISIBILITY_PRESET hidden |
| 22 | + VISIBILITY_INLINES_HIDDEN ON |
| 23 | + INSTALL_NAME_DIR "@rpath" |
| 24 | +) |
| 25 | + |
| 26 | +install( |
| 27 | + TARGETS python_template_cpp |
| 28 | + EXPORT python_template_cppTargets |
| 29 | + RUNTIME DESTINATION bin |
| 30 | + LIBRARY DESTINATION lib |
| 31 | + ARCHIVE DESTINATION lib |
| 32 | +) |
| 33 | +install(DIRECTORY ../python_template_cpp/include/ DESTINATION include) |
| 34 | +install(EXPORT python_template_cppTargets NAMESPACE python_template_cpp:: DESTINATION lib/cmake/python_template_cpp) |
| 35 | + |
| 36 | +configure_package_config_file( |
| 37 | + cmake/python_template_cppConfig.cmake.in ${CMAKE_CURRENT_BINARY_DIR}/python_template_cppConfig.cmake |
| 38 | + INSTALL_DESTINATION lib/cmake/python_template_cpp |
| 39 | +) |
| 40 | +write_basic_package_version_file(${CMAKE_CURRENT_BINARY_DIR}/python_template_cppConfigVersion.cmake COMPATIBILITY SameMinorVersion) |
| 41 | +install(FILES ${CMAKE_CURRENT_BINARY_DIR}/python_template_cppConfig.cmake ${CMAKE_CURRENT_BINARY_DIR}/python_template_cppConfigVersion.cmake |
| 42 | + DESTINATION lib/cmake/python_template_cpp |
| 43 | +) |
| 44 | + |
| 45 | +configure_file(cmake/python_template_cpp.pc.in ${CMAKE_CURRENT_BINARY_DIR}/python_template_cpp.pc @ONLY) |
| 46 | +install(FILES ${CMAKE_CURRENT_BINARY_DIR}/python_template_cpp.pc DESTINATION lib/pkgconfig) |
0 commit comments