-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
76 lines (64 loc) · 2.5 KB
/
CMakeLists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
cmake_minimum_required(VERSION 3.17)
project(
funi
VERSION 0.1.0
LANGUAGES CXX)
if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
endif()
# options - default is to build python module together
option(FUNI_BUILD_PYTHON "build python module" ON)
# config
set(exe_dest "bin")
set(incl_dest "include")
set(lib_dest "lib")
set(cfg_dest "${lib_dest}/cmake/${PROJECT_NAME}")
set(gen_dir "${CMAKE_CURRENT_BINARY_DIR}/generated")
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
set(version_config "${gen_dir}/${PROJECT_NAME}ConfigVersion.cmake")
set(project_config "${gen_dir}/${PROJECT_NAME}Config.cmake")
set(TARGETS_EXPORT_NAME "${PROJECT_NAME}Targets")
set(namespace "${PROJECT_NAME}::")
# sources
set(CXX_HEADERS src/axis.hpp src/lexi.hpp src/pyfuni.hpp)
# add library - header only
add_library(headers INTERFACE)
target_include_directories(
headers INTERFACE $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/src>
$<INSTALL_INTERFACE:${incl_dest}>)
add_library(funi::headers ALIAS headers)
set_target_properties(headers PROPERTIES CXX_STANDARD 17)
if(FUNI_BUILD_PYTHON)
find_package(Python REQUIRED COMPONENTS Interpreter Development.Module)
find_package(pybind11 CONFIG REQUIRED)
python_add_library(funi MODULE src/pyfuni.cpp WITH_SOABI)
target_link_libraries(funi PRIVATE pybind11::headers funi::headers)
target_compile_definitions(funi PRIVATE $<$<NOT:$<CONFIG:Debug>>:NDEBUG>)
if(CMAKE_CXX_COMPILER_ID MATCHES "GNU" OR CMAKE_CXX_COMPILER_ID MATCHES
"Clang")
target_compile_options(funi PRIVATE $<$<NOT:$<CONFIG:Debug>>:-O3>)
elseif(CMAKE_CXX_COMPILER_ID MATCHES "MSCV")
target_compile_options(funi PRIVATE $<$<NOT:$<CONFIG:Debug>>:/O2>)
endif()
endif()
# configure config files
include(CMakePackageConfigHelpers)
write_basic_package_version_file("${version_config}"
COMPATIBILITY SameMajorVersion)
configure_package_config_file("cmake/config.cmake.in" "${project_config}"
INSTALL_DESTINATION "${cfg_dest}")
install(
TARGETS headers
EXPORT "${TARGETS_EXPORT_NAME}"
LIBRARY DESTINATION ${lib_dest}
ARCHIVE DESTINATION ${lib_dest}
INCLUDES
DESTINATION "${incl_dest}")
install(FILES "${project_config}" "${version_config}" DESTINATION "${cfg_dest}")
install(
EXPORT "${TARGETS_EXPORT_NAME}"
NAMESPACE "${namespace}"
DESTINATION "${cfg_dest}")
install(FILES ${CXX_HEADERS} DESTINATION ${incl_dest})
if(FUNI_BUILD_PYTHON)
install(TARGETS funi DESTINATION .)
endif()