forked from maxitg/SetReplace
-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathCMakeLists.txt
210 lines (184 loc) · 7.67 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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
cmake_minimum_required(VERSION 3.13)
project(SetReplace
VERSION 0.3.0
LANGUAGES CXX)
message(STATUS "${PROJECT_NAME} version: ${PROJECT_VERSION}")
option(SET_REPLACE_WITH_MATHEMATICA "Add the library definition for Wolfram LibraryLink" OFF)
option(SET_REPLACE_BUILD_TESTING "Enable cpp testing." OFF)
option(SET_REPLACE_WRAP_PYTHON "Wrap python using pybind11" OFF)
include(GNUInstallDirs) # Define CMAKE_INSTALL_xxx: LIBDIR, INCLUDEDIR
set(SetReplace_export_file "${PROJECT_BINARY_DIR}/SetReplaceTargets.cmake")
set(default_build_type "Release")
if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
message(STATUS "Setting build type to '${default_build_type}' as none was specified.")
set(CMAKE_BUILD_TYPE "${default_build_type}" CACHE
STRING "Choose the type of build." FORCE)
# Set the possible values of build type for cmake-gui
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY
STRINGS "Debug" "Release" "MinSizeRel" "RelWithDebInfo")
endif()
if(NOT CMAKE_CXX_STANDARD)
set(CMAKE_CXX_STANDARD 17)
message(STATUS "${PROJECT_NAME} using CMAKE_CXX_STANDARD: ${CMAKE_CXX_STANDARD}")
endif()
# Set extra compile options
set(_set_replace_extra_compile_options_docstring "Add extra compile options to the CXX targets")
if(MSVC)
set(SET_REPLACE_EXTRA_COMPILE_OPTIONS /EHsc CACHE STRING ${_set_replace_extra_compile_options_docstring})
else()
option(SET_REPLACE_ENABLE_ALLWARNINGS "Add compile options to the cpp targets. The warnings are set in SET_REPLACE_EXTRA_COMPILE_OPTIONS" OFF)
if(SET_REPLACE_ENABLE_ALLWARNINGS)
set(SET_REPLACE_EXTRA_COMPILE_OPTIONS
-Wall -Wextra -Werror -pedantic -Wcast-align -Wcast-qual
-Wctor-dtor-privacy -Wdisabled-optimization -Wformat=2
-Winit-self -Wmissing-include-dirs -Wold-style-cast
-Woverloaded-virtual -Wredundant-decls -Wshadow
-Wsign-promo -Wswitch-default -Wundef -Wno-unused
CACHE STRING ${_set_replace_extra_compile_options_docstring})
endif()
endif()
message(STATUS "SET_REPLACE_BUILD_TESTING: ${SET_REPLACE_BUILD_TESTING}")
message(STATUS "SET_REPLACE_WITH_MATHEMATICA: ${SET_REPLACE_WITH_MATHEMATICA}")
message(STATUS "SET_REPLACE_EXTRA_COMPILE_OPTIONS: ${SET_REPLACE_EXTRA_COMPILE_OPTIONS}")
# The python package is named wolfram_model
set(CMAKE_INSTALL_PYTHONLIBDIR wolfram_model) # Install folder for python libs
set(CMAKE_BUILD_PYTHONLIBDIR ${PROJECT_BINARY_DIR}/wolfram_model) # copy python libs at build time
if(SET_REPLACE_WRAP_PYTHON)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
endif()
message(STATUS "SET_REPLACE_WRAP_PYTHON: ${SET_REPLACE_WRAP_PYTHON}")
set(libSetReplace_headers
Rule.hpp
IDTypes.hpp
Expression.hpp
Match.hpp
Set.hpp
SetReplaceIO.hpp
)
set(libSetReplace_sources
Expression.cpp
Match.cpp
Set.cpp
)
if(SET_REPLACE_WITH_MATHEMATICA)
list(APPEND libSetReplace_headers SetReplace.hpp)
endif()
list(TRANSFORM libSetReplace_headers PREPEND "libSetReplace/")
list(TRANSFORM libSetReplace_sources PREPEND "libSetReplace/")
add_library(SetReplace ${libSetReplace_sources})
target_include_directories(SetReplace PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/libSetReplace>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
)
target_compile_options(SetReplace PRIVATE ${SET_REPLACE_EXTRA_COMPILE_OPTIONS})
set(SET_REPLACE_LIBRARIES SetReplace)
if(SET_REPLACE_WITH_MATHEMATICA)
set(libSetReplaceMathematica_sources
SetReplace.cpp)
list(TRANSFORM libSetReplaceMathematica_sources PREPEND "libSetReplace/")
add_library(SetReplaceMathematica ${libSetReplaceMathematica_sources})
target_link_libraries(SetReplaceMathematica SetReplace)
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}/cmake)
find_package(Mathematica REQUIRED)
target_include_directories(SetReplaceMathematica PUBLIC ${Mathematica_INCLUDE_DIR})
target_link_libraries(SetReplaceMathematica ${Mathematica_LIBRARIES})
target_compile_options(SetReplaceMathematica PRIVATE ${SET_REPLACE_EXTRA_COMPILE_OPTIONS})
list(APPEND SET_REPLACE_LIBRARIES SetReplaceMathematica)
endif()
install(TARGETS ${SET_REPLACE_LIBRARIES}
EXPORT SetReplaceTargets
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT runtime
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT runtime
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT development
)
install(FILES ${libSetReplace_headers}
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/SetReplace
COMPONENT development
)
# export to the build tree
export( TARGETS ${SET_REPLACE_LIBRARIES}
NAMESPACE SetReplace::
APPEND FILE ${SetReplace_export_file})
if(SET_REPLACE_BUILD_TESTING)
enable_testing()
set(INSTALL_GTEST OFF)
set(CMAKE_POLICY_DEFAULT_CMP0077 NEW) # Propagate INSTALL_GTEST=OFF to subproject
set(GTEST_LIBRARIES gtest gtest_main)
include(GoogleTest)
#############################################################################
# Fetch GTest
include(FetchContent)
FetchContent_Declare(
googletest
GIT_REPOSITORY https://github.com/google/googletest.git
GIT_TAG v1.8.x
)
set(CMAKE_POLICY_DEFAULT_CMP0048 NEW) # google test raises warning about it
FetchContent_GetProperties(googletest)
if(NOT googletest_POPULATED)
FetchContent_Populate(googletest)
add_subdirectory(${googletest_SOURCE_DIR} ${googletest_BINARY_DIR})
endif()
#############################################################################
add_subdirectory(libSetReplace/test)
endif()
if(SET_REPLACE_WRAP_PYTHON)
# Fetch pybind11
include(FetchContent)
FetchContent_Declare(
pybind11
GIT_REPOSITORY https://github.com/pybind/pybind11
GIT_TAG v2.5
)
FetchContent_GetProperties(pybind11)
if(NOT pybind11_POPULATED)
FetchContent_Populate(pybind11)
add_subdirectory(${pybind11_SOURCE_DIR} ${pybind11_BINARY_DIR})
endif()
add_subdirectory(python)
endif()
# INSTALL
set(install_cmake_dir "${CMAKE_INSTALL_LIBDIR}/cmake/SetReplace")
install (EXPORT SetReplaceTargets
NAMESPACE SetReplace::
DESTINATION ${install_cmake_dir} )
install(FILES
${CMAKE_CURRENT_SOURCE_DIR}/cmake/FindMathematica.cmake
${CMAKE_CURRENT_BINARY_DIR}/cmake/SetReplaceConfig.cmake
${CMAKE_CURRENT_BINARY_DIR}/SetReplaceConfigVersion.cmake
DESTINATION ${install_cmake_dir} )
include(CMakePackageConfigHelpers)
write_basic_package_version_file(SetReplaceConfigVersion.cmake
VERSION ${PROJECT_VERSION}
COMPATIBILITY SameMajorVersion)
# Build tree
set(SetReplace_TARGETS_FILE ${SetReplace_export_file})
configure_package_config_file(
${CMAKE_CURRENT_SOURCE_DIR}/cmake/SetReplaceConfig.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/SetReplaceConfig.cmake
INSTALL_DESTINATION ${install_cmake_dir}
PATH_VARS SetReplace_TARGETS_FILE
NO_CHECK_REQUIRED_COMPONENTS_MACRO # SetReplace does not provide components
INSTALL_PREFIX ${CMAKE_CURRENT_BINARY_DIR}
)
# Install tree
set(SetReplace_TARGETS_FILE ${CMAKE_INSTALL_PREFIX}/${install_cmake_dir}/SetReplaceTargets.cmake)
configure_package_config_file(
${CMAKE_CURRENT_SOURCE_DIR}/cmake/SetReplaceConfig.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/cmake/SetReplaceConfig.cmake
INSTALL_DESTINATION ${install_cmake_dir}
PATH_VARS SetReplace_TARGETS_FILE
NO_CHECK_REQUIRED_COMPONENTS_MACRO # SetReplace does not provide components
)
# Add custom target to only install component: runtime (libraries)
add_custom_target(set-replace-install-runtime
${CMAKE_COMMAND}
-DCMAKE_INSTALL_COMPONENT=runtime
-P "${PROJECT_BINARY_DIR}/cmake_install.cmake"
DEPENDS ${SET_REPLACE_LIBRARIES}
)
message(STATUS "SET_REPLACE_LIBRARIES: ${SET_REPLACE_LIBRARIES}")
add_dependencies(set-replace-install-runtime ${SET_REPLACE_LIBRARIES})
if(SET_REPLACE_WRAP_PYTHON)
add_dependencies(set-replace-install-runtime _wolfram_model)
endif()