forked from njoy/tools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
164 lines (126 loc) · 4.66 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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
########################################################################
# Preamble
########################################################################
cmake_minimum_required( VERSION 3.24 )
set( subproject OFF )
if( DEFINED PROJECT_NAME )
set( subproject ON )
endif()
project( tools
VERSION 0.4.0
LANGUAGES CXX
)
include( CTest )
include( CMakeDependentOption )
include( GNUInstallDirs )
########################################################################
# Project-wide setup
########################################################################
set( CMAKE_CXX_STANDARD 17 )
set( CMAKE_CXX_STANDARD_REQUIRED YES )
cmake_dependent_option(
tools.tests
"Build the tools unit tests and integrate with ctest" ON
"BUILD_TESTING AND NOT ${subproject}" OFF
)
cmake_dependent_option(
tools.python
"Build tools python bindings" ON
"NOT ${subproject} OR DEFINED require.tools.python " OFF
)
option( tools.installation "Install njoy::tools" ON )
########################################################################
# Dependencies
########################################################################
list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/.cmake)
include( cmake/dependencies.cmake )
########################################################################
# Project targets
########################################################################
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# tools : library
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
add_library( tools INTERFACE )
add_library( njoy::tools ALIAS tools )
string( CONCAT prefix
"$<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/src>"
"$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>"
)
target_include_directories( tools INTERFACE ${prefix} )
target_link_libraries( tools
INTERFACE
spdlog::spdlog
FastFloat::fast_float
)
target_compile_definitions( tools INTERFACE -DNANORANGE_NO_STD_FORWARD_DECLARATIONS )
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# tools : python bindings
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
if( tools.python )
pybind11_add_module( tools.python
python/src/tools.python.cpp
)
add_library( njoy::tools.python ALIAS tools.python )
target_link_libraries( tools.python PRIVATE tools )
target_include_directories( tools.python PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/python/src )
target_compile_options( tools.python PRIVATE "-fvisibility=hidden" )
set_target_properties( tools.python PROPERTIES OUTPUT_NAME tools )
set_target_properties( tools.python PROPERTIES COMPILE_DEFINITIONS "PYBIND11" )
set_target_properties( tools.python PROPERTIES POSITION_INDEPENDENT_CODE ON )
message( STATUS "Building tools' python API" )
list( APPEND TOOLS_PYTHONPATH ${CMAKE_CURRENT_BINARY_DIR} )
if( tools.tests )
include( cmake/unit_testing_python.cmake )
endif()
endif()
if( CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR )
if( tools.tests )
include( cmake/unit_testing.cmake )
endif()
endif()
#######################################################################
# Installation
#######################################################################
if(tools.installation)
include(CMakePackageConfigHelpers)
install(TARGETS tools EXPORT tools-targets
ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}"
LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}"
RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}"
)
install(EXPORT tools-targets
FILE "tools-targets.cmake"
NAMESPACE njoy::
DESTINATION share/cmake/tools
)
install(DIRECTORY src/
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}"
FILES_MATCHING PATTERN "*.hpp"
PATTERN "*test*" EXCLUDE
)
write_basic_package_version_file("tools-config-version.cmake"
VERSION ${PROJECT_VERSION}
COMPATIBILITY AnyNewerVersion)
configure_package_config_file(
${CMAKE_CURRENT_SOURCE_DIR}/cmake/tools-config.cmake.in
${PROJECT_BINARY_DIR}/tools-config.cmake
INSTALL_DESTINATION share/cmake/tools
)
install(FILES
"${PROJECT_BINARY_DIR}/tools-config.cmake"
"${PROJECT_BINARY_DIR}/tools-config-version.cmake"
DESTINATION share/cmake/tools
)
if(NOT subproject)
set(CPACK_PACKAGE_VENDOR "Los Alamos National Laboratory")
set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/LICENSE")
include(CPack)
endif()
if(tools.python)
install(TARGETS tools.python EXPORT tools-targets
ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}"
LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}"
RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}"
)
endif()
endif()