-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathCMakeLists.txt
260 lines (219 loc) · 10.3 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
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
cmake_minimum_required(VERSION 3.0)
project(SmallChange VERSION 1.0.0)
string(TOLOWER ${PROJECT_NAME} PROJECT_NAME_LOWER)
# ############################################################################
# these will be removed after upgrading CMake minimum version
set(PROJECT_DESCRIPTION "A collection of extensions to the Open Inventor API")
# ############################################################################
string(TIMESTAMP SMALLCHANGE_BUILD_YEAR "%Y")
math(EXPR SMALLCHANGE_SO_VERSION ${PROJECT_VERSION_MAJOR}*20)
if(POLICY CMP0072)
# get rid of OpenGL GLVND warning from CMake 3.11
cmake_policy(SET CMP0072 NEW)
endif()
# ############################################################################
# Prevent in-source builds, as they often cause severe build problems
# ############################################################################
if(CMAKE_SOURCE_DIR STREQUAL CMAKE_BINARY_DIR)
message(FATAL_ERROR "${CMAKE_PROJECT_NAME} requires an out of source build. Please create a separate build directory and run 'cmake <path_to_${CMAKE_PROJECT_NAME}> [options]' from there.")
endif()
# ############################################################################
# Include necessary submodules
# ############################################################################
include(CheckIncludeFiles)
include(CMakeDependentOption)
include(CMakePackageConfigHelpers)
include(GNUInstallDirs)
# ############################################################################
# Provide options to customise the build
# ############################################################################
function(report_prepare)
set(multiValueArgs IF_APPLE IF_WIN32)
cmake_parse_arguments(REPORT "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN} )
if (REPORT_IF_APPLE AND APPLE)
list(APPEND res ${REPORT_IF_APPLE})
endif()
if (REPORT_IF_WIN32 AND WIN32)
list(APPEND res ${REPORT_IF_WIN32})
endif()
list(APPEND res ${REPORT_UNPARSED_ARGUMENTS})
list(APPEND PACKAGE_OPTIONS ${res})
set(PACKAGE_OPTIONS "${PACKAGE_OPTIONS}" PARENT_SCOPE)
endfunction(report_prepare)
option(HAVE_DEBUG "Add debugging information during the configure process")
option(SMALLCHANGE_BUILD_SHARED_LIBS "Build shared libraries" ON)
option(SMALLCHANGE_USE_QT6 "Prefer Qt6 over Qt5 if available" ON)
option(SMALLCHANGE_USE_QT5 "Prefer Qt5 over Qt4 if available" ON)
option(SMALLCHANGE_USE_WX "Prefer wxWidgets over Qt if available" OFF)
option(SMALLCHANGE_BUILD_DOCUMENTATION "Build and install API documentation (requires Doxygen)." OFF)
option(SMALLCHANGE_BUILD_AWESOME_DOCUMENTATION "Build and install API documentation in new modern style (requires Doxygen)." OFF)
cmake_dependent_option(SMALLCHANGE_BUILD_INTERNAL_DOCUMENTATION "Document internal code not part of the API." OFF "SMALLCHANGE_BUILD_DOCUMENTATION" OFF)
cmake_dependent_option(SMALLCHANGE_BUILD_DOC_MAN "Build SmallChange man pages." OFF "SMALLCHANGE_BUILD_DOCUMENTATION" OFF)
cmake_dependent_option(SMALLCHANGE_BUILD_DOC_QTHELP "Build QtHelp documentation." OFF "SMALLCHANGE_BUILD_DOCUMENTATION" OFF)
cmake_dependent_option(SMALLCHANGE_BUILD_DOC_CHM "Build compressed HTML help manual (requires HTML help compiler)" OFF "SMALLCHANGE_BUILD_DOCUMENTATION" OFF)
option(SMALLCHANGE_USE_CPACK "If enabled the cpack subrepo is mandatory" OFF)
report_prepare(
SMALLCHANGE_BUILD_SHARED_LIBS
SMALLCHANGE_USE_QT6
SMALLCHANGE_USE_QT5
SMALLCHANGE_USE_WX
SMALLCHANGE_BUILD_DOCUMENTATION
SMALLCHANGE_BUILD_AWESOME_DOCUMENTATION
SMALLCHANGE_BUILD_INTERNAL_DOCUMENTATION
SMALLCHANGE_BUILD_DOC_MAN
SMALLCHANGE_BUILD_DOC_QTHELP
SMALLCHANGE_BUILD_DOC_CHM
)
# ############################################################################
# Find all necessary and optional SmallChange dependencies
# ############################################################################
# Fail early if one of the required packages cannot be found
find_package(OpenGL REQUIRED)
find_package(Coin REQUIRED)
set(SMALLCHANGE_PKG_DEPS "Coin")
if(NOT SMALLCHANGE_USE_WX)
if(SMALLCHANGE_USE_QT6)
find_package(Qt6 COMPONENTS Core Widgets QUIET)
endif()
if(NOT Qt6_FOUND AND SMALLCHANGE_USE_QT5)
find_package(Qt5 COMPONENTS Core Widgets QUIET)
endif()
if(NOT Qt6_FOUND AND NOT Qt5_FOUND)
set(QT_USE_IMPORTED_TARGETS ON)
find_package(Qt4 COMPONENTS QtCore QtGui REQUIRED)
endif()
if(Qt6_FOUND)
set(SMALLCHANGE_QT_TARGETS Qt6::Core Qt6::Gui Qt6::Widgets)
string(REGEX REPLACE "^([0-9]+)\\.[0-9]+\\.[0-9]+.*" "\\1" QT_VERSION_MAJOR "${Qt6Core_VERSION_STRING}")
string(REGEX REPLACE "^[0-9]+\\.([0-9]+)\\.[0-9]+.*" "\\1" QT_VERSION_MINOR "${Qt6Core_VERSION_STRING}")
string(REGEX REPLACE "^[0-9]+\\.[0-9]+\\.([0-9]+).*" "\\1" QT_VERSION_PATCH "${Qt6Core_VERSION_STRING}")
set(SMALLCHANGE_PKG_DEPS "${SMALLCHANGE_PKG_DEPS} Qt6Core Qt6Gui Qt6Widgets")
elseif(Qt5_FOUND)
set(SMALLCHANGE_QT_TARGETS Qt5::Core Qt5::Gui Qt5::Widgets)
string(REGEX REPLACE "^([0-9]+)\\.[0-9]+\\.[0-9]+.*" "\\1" QT_VERSION_MAJOR "${Qt5Core_VERSION_STRING}")
string(REGEX REPLACE "^[0-9]+\\.([0-9]+)\\.[0-9]+.*" "\\1" QT_VERSION_MINOR "${Qt5Core_VERSION_STRING}")
string(REGEX REPLACE "^[0-9]+\\.[0-9]+\\.([0-9]+).*" "\\1" QT_VERSION_PATCH "${Qt5Core_VERSION_STRING}")
set(SMALLCHANGE_PKG_DEPS "${SMALLCHANGE_PKG_DEPS} Qt5Core Qt5Gui Qt5Widgets")
else()
set(QT_USE_IMPORTED_TARGETS ON)
find_package(Qt4 COMPONENTS QtCore QtGui REQUIRED)
set(SMALLCHANGE_QT_TARGETS Qt4::QtCore Qt4::QtGui)
include(${QT_USE_FILE})
set(SMALLCHANGE_PKG_DEPS "${SMALLCHANGE_PKG_DEPS} QtCore QtGui")
endif()
set(SMALLCHANGE_PKG_LIBS "" CACHE INTERNAL "Link libraries for package config")
set(SMALLCHANGE_PKG_FLAGS "" CACHE INTERNAL "Compilation flags for package config")
find_package(SoQt REQUIRED)
else()
set(SMALLCHANGE_PKG_LIBS "" CACHE INTERNAL "Link libraries for package config")
set(SMALLCHANGE_PKG_FLAGS "" CACHE INTERNAL "Compilation flags for package config")
find_package(SoWx REQUIRED)
endif()
# ##########################################################################
# Setup build environment
# ##########################################################################
if(NOT CMAKE_BUILD_TYPE)
# Has no effect for multi configuration generators (VisualStudio, Xcode).
set(CMAKE_BUILD_TYPE Release CACHE STRING "Choose type of build, options are Debug, Release, RelWithDebInfo, MinSizeRel." FORCE)
endif()
# Set common output directories for all targets built.
# First for the generic no-config case (e.g. with mingw)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib")
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib")
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin")
# Second, for multi-config builds (e.g. msvc)
foreach (_config ${CMAKE_CONFIGURATION_TYPES})
string(TOUPPER ${_config} _config)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY_${_config} "${CMAKE_BINARY_DIR}/lib")
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY_${_config} "${CMAKE_BINARY_DIR}/lib")
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_${_config} "${CMAKE_BINARY_DIR}/bin")
endforeach()
function(versionize)
foreach(dir ${ARGN})
set(name "CMAKE_INSTALL_${dir}")
set(full-name "CMAKE_INSTALL_FULL_${dir}")
set(value "${${name}}/${PROJECT_NAME}")
set(full-value "${CMAKE_INSTALL_PREFIX}/${value}")
set(${name} ${value} PARENT_SCOPE)
set(${full-name} ${full-value} PARENT_SCOPE)
endforeach()
endfunction()
function(dump_variable)
if (HAVE_DEBUG)
foreach(f ${ARGN})
if (DEFINED ${f})
message("${f} = ${${f}}")
else()
message("${f} = ***UNDEF***")
endif()
endforeach()
endif()
endfunction()
# Only the following defines are actually used inside the project sources:
# HAVE_SYS_STAT_H
# HAVE_UNISTD_H
# HAVE_WINDOWS_H
# consequently the new config.h.cmake.in will be set based on the results of
# the following checks
check_include_files(unistd.h HAVE_UNISTD_H)
check_include_files(sys/stat.h HAVE_SYS_STAT_H)
check_include_files(windows.h HAVE_WINDOWS_H)
configure_file(config.h.cmake.in config.h)
###############################################################################
# Build setup
dump_variable(
CMAKE_INSTALL_FULL_INCLUDEDIR
CMAKE_INSTALL_FULL_DOCDIR
)
versionize(INCLUDEDIR)
dump_variable(
CMAKE_INSTALL_FULL_INCLUDEDIR
CMAKE_INSTALL_FULL_DOCDIR
)
include_directories(BEFORE
${CMAKE_BINARY_DIR}
${CMAKE_SOURCE_DIR}/lib
${CMAKE_BINARY_DIR}/lib
${Coin_INCLUDE_DIR}
)
# ############################################################################
# Setup targets in subdirectories
# ############################################################################
add_subdirectory(lib)
add_subdirectory(test-code)
add_subdirectory(docs)
# ############################################################################
# Install pkgconfig file and CMake config package
# ############################################################################
if(UNIX OR MINGW)
configure_file("${CMAKE_SOURCE_DIR}/SmallChange.pc.cmake.in" SmallChange.pc @ONLY)
install(FILES "${CMAKE_BINARY_DIR}/SmallChange.pc" DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)
endif()
configure_package_config_file("${CMAKE_SOURCE_DIR}/${PROJECT_NAME_LOWER}-config.cmake.in" ${PROJECT_NAME_LOWER}-config.cmake
INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}-${PROJECT_VERSION}
PATH_VARS CMAKE_INSTALL_DOCDIR CMAKE_INSTALL_INCLUDEDIR CMAKE_INSTALL_LIBDIR
)
write_basic_package_version_file("${CMAKE_BINARY_DIR}/${PROJECT_NAME_LOWER}-config-version.cmake"
VERSION ${PROJECT_VERSION}
COMPATIBILITY ExactVersion
)
# To make the component usable not only from the install directory but also from the build directory
export(
TARGETS ${PROJECT_NAME}
FILE ${PROJECT_NAME_LOWER}-export.cmake
)
install(FILES "${CMAKE_BINARY_DIR}/${PROJECT_NAME_LOWER}-config.cmake" "${CMAKE_BINARY_DIR}/${PROJECT_NAME_LOWER}-config-version.cmake"
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}-${PROJECT_VERSION}
COMPONENT development
)
install(EXPORT ${PROJECT_NAME}
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}-${PROJECT_VERSION}
NAMESPACE ${PROJECT_NAME}::
FILE ${PROJECT_NAME_LOWER}-export.cmake
COMPONENT development
)
# CPACK section moved in the package-config directory.
# Please see the README file inside.
if (SMALLCHANGE_USE_CPACK)
add_subdirectory(cpack.d)
endif()