forked from ViennaTools/ViennaPS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeLists.txt
213 lines (175 loc) · 8.48 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
211
212
213
cmake_minimum_required(VERSION 3.14 FATAL_ERROR)
project(ViennaPS VERSION 1.3.1)
# Store version in cache
set(VIENNAPS_VERSION
${PROJECT_VERSION}
CACHE STRING "The version of ViennaPS" FORCE)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
set(CMAKE_CXX_STANDARD "17")
add_definitions(-DVIENNAPS_VERSION=${PROJECT_VERSION})
include(GNUInstallDirs)
# Setup of default build type
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()
# Tell VS to export all symbols to its dll files
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS
TRUE
CACHE BOOL "Export all symbols" FORCE)
add_compile_definitions(_USE_MATH_DEFINES)
endif()
# ##################################################################################################
# CONFIGURATION OPTIONS
# ##################################################################################################
# Build the included examples
option(VIENNAPS_BUILD_EXAMPLES "Build examples." OFF)
# Build the application binary
option(VIENNAPS_BUILD_APPLICATION "Build ViennaPS application." OFF)
# Build the included tests
option(VIENNAPS_BUILD_TESTS "Build tests." OFF)
# ##################################################################################################
# AUTOMATIC DEPENDENCY PREPARATION
# ##################################################################################################
# With the stampfile mechanism, cmake automatically retriggers the configure step after the
# buildDependencies targed has been executed. Thus all dependencies that were built with
# buildDependencies should then be made available by the find_package calls.
set(STAMPFILE ${CMAKE_BINARY_DIR}/target.stamp)
# When the buildDependencies target is executed, the stamp file is touched
add_custom_target(buildDependencies COMMAND ${CMAKE_COMMAND} -E touch ${STAMPFILE})
# Include the external dependencies
include(ExternalProject)
if(NOT DEFINED VIENNAPS_DEPENDENCIES_DIR)
set(DEPENDENCIES_DIR ${CMAKE_SOURCE_DIR}/dependencies)
else()
set(DEPENDENCIES_DIR
${VIENNAPS_DEPENDENCIES_DIR}
CACHE PATH "Directory for downloading, building and installing external dependencies")
endif()
add_subdirectory(external/upstream)
# Create the initial stamp file
file(TOUCH ${STAMPFILE})
# Include the stamp file, so that cmake is forced to re-run once the file has been touched
include(${STAMPFILE})
# Binary store the binary directory for use in subprojects
set(ViennaPS_BINARY_DIR
${PROJECT_BINARY_DIR}
CACHE PATH "Path to local ViennaPS installation" FORCE)
# ##################################################################################################
# DEPENDENCY CHECKS
# ##################################################################################################
set(DEPENDENCIES_FOUND TRUE)
list(APPEND VIENNAPS_DEPENDENCIES "viennals_external")
find_package(ViennaLS QUIET CONFIG PATHS ${ViennaLS_DIR} NO_DEFAULT_PATH)
if(NOT ViennaLS_FOUND)
set(DEPENDENCIES_FOUND FALSE)
endif()
list(APPEND VIENNAPS_DEPENDENCIES "viennaray_external")
find_package(ViennaRay QUIET CONFIG PATHS ${ViennaRay_DIR} NO_DEFAULT_PATH)
if(NOT ViennaRay_FOUND)
set(DEPENDENCIES_FOUND FALSE)
endif()
if(VIENNAPS_BUILD_PYTHON)
list(APPEND VIENNAPS_DEPENDENCIES "pybind11_external")
find_package(pybind11 QUIET PATHS ${pybind11_DIR} NO_DEFAULT_PATH)
if(NOT pybind11_FOUND)
set(DEPENDENCIES_FOUND FALSE)
endif()
endif()
if(DEPENDENCIES_FOUND)
# Remove the buildDependencies target from the ALL target to prevent unnecessary re-builds
set_target_properties(buildDependencies PROPERTIES EXCLUDE_FROM_ALL true)
else()
message(WARNING "Not all dependencies were found. Execute buildDependencies target first.")
# Add the buildDependencies target to the ALL target
set_target_properties(buildDependencies PROPERTIES EXCLUDE_FROM_ALL false)
endif()
# ##################################################################################################
# DIRECTORY CONFIGURATIONS
# ##################################################################################################
# install config files locations are provided by GNUInstallDirs
add_library(${PROJECT_NAME} INTERFACE)
if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
set(CMAKE_INSTALL_PREFIX "${CMAKE_INSTALL_PREFIX}/${PROJECT_NAME}/")
endif()
set(LOCAL_CONFIG_DIR "lib/cmake/${PROJECT_NAME}")
# This variable is used by the example, test, python and precompiled library target, since those are
# compiled before the project is installed in its proper install location.
set(VIENNAPS_BUILD_INCLUDE_DIRS "${${PROJECT_NAME}_SOURCE_DIR}/include")
# Adding the install interface generator expression makes sure that the include files are installed
# to the proper location (provided by GNUInstallDirs)
target_include_directories(
${PROJECT_NAME} INTERFACE $<BUILD_INTERFACE:${VIENNAPS_BUILD_INCLUDE_DIRS}>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>)
target_compile_features(${PROJECT_NAME} INTERFACE cxx_std_11)
# ##################################################################################################
# CMAKE CONFIG FILE SETUP
# ##################################################################################################
include(CMakePackageConfigHelpers)
write_basic_package_version_file(
"${PROJECT_NAME}ConfigVersion.cmake"
VERSION ${PROJECT_VERSION}
COMPATIBILITY AnyNewerVersion)
configure_package_config_file(
"${PROJECT_SOURCE_DIR}/cmake/${PROJECT_NAME}Config.cmake.in"
"${PROJECT_BINARY_DIR}/${PROJECT_NAME}Config.cmake" INSTALL_DESTINATION ${LOCAL_CONFIG_DIR})
# ##################################################################################################
# BUILD EXAMPLES
# ##################################################################################################
if(VIENNAPS_BUILD_EXAMPLES AND DEPENDENCIES_FOUND)
add_subdirectory(examples)
endif()
# ##################################################################################################
# BUILD VIENNAPS APPLICATION
# ##################################################################################################
if(VIENNAPS_BUILD_APPLICATION AND DEPENDENCIES_FOUND)
add_subdirectory(app)
endif()
# ##################################################################################################
# BUILD TESTS (Smaller examples for testing)
# ##################################################################################################
if(VIENNAPS_BUILD_TESTS AND DEPENDENCIES_FOUND)
enable_testing()
add_subdirectory(tests)
endif()
# ##################################################################################################
# BUILD VIENNAPS PYTHON BINDINGS
# ##################################################################################################
# Build Python bindings
option(VIENNAPS_BUILD_PYTHON "Build for python3.x." OFF)
if(VIENNAPS_BUILD_PYTHON AND DEPENDENCIES_FOUND)
add_subdirectory(python)
endif()
# ##################################################################################################
# INSTALL
# ##################################################################################################
install(
TARGETS ${PROJECT_NAME}
EXPORT ${PROJECT_NAME}_Targets
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
install(
EXPORT ${PROJECT_NAME}_Targets
FILE ${PROJECT_NAME}Targets.cmake
DESTINATION ${LOCAL_CONFIG_DIR})
install(FILES "${PROJECT_BINARY_DIR}/${PROJECT_NAME}Config.cmake"
"${PROJECT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake"
DESTINATION ${LOCAL_CONFIG_DIR})
# Install include files
file(GLOB_RECURSE HEADER_FILES "${PROJECT_SOURCE_DIR}/include/*.hpp")
install(FILES ${HEADER_FILES} DESTINATION include)
# uninstall target
if(NOT TARGET uninstall)
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/cmake/cmake_uninstall.cmake.in"
"${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake" IMMEDIATE @ONLY)
add_custom_target(uninstall COMMAND ${CMAKE_COMMAND} -P
${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake)
endif()