-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeLists.txt
257 lines (212 loc) · 9.61 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
CMAKE_MINIMUM_REQUIRED( VERSION 3.9)
PROJECT(EXCEPTCXX)
# Check if project is a standalone and not part of another project.
IF( CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR )
SET(EXCEPTCXX_PROJECT_ROOT TRUE)
ENDIF()
# Use GNUInstallDirs for Unix predefined directories
INCLUDE(GNUInstallDirs)
SET(EXECUTABLE_OUTPUT_PATH ${CMAKE_BINARY_DIR}/bin CACHE INTERNAL "" FORCE)
SET(LIBRARY_OUTPUT_PATH ${CMAKE_BINARY_DIR}/lib CACHE INTERNAL "" FORCE)
#-----------------------------------------------------------------------------
# Options
# Build shared/dynamic library option
OPTION(CXXEXCEPT_BUILD_SHARED_LIBS "Build package with shared libraries." ON)
OPTION(CXXEXCEPT_BUILD_WITH_EXTERNAL_PROJECT "Enable external project build." ON)
OPTION(CXXEXCEPT_BUILD_OPT_BUILD_PACKAGES "Set to ON to generate CPack configuration files and packaging targets" OFF)
IF(NOT CXXEXCEPT_BUILD_SHARED_LIBS)
SET(CMAKE_EXE_LINKER_FLAGS "-static")
MESSAGE(STATUS "Static libraries enabled.")
SET(LINK_SEARCH_START_STATIC TRUE)
ELSE()
MESSAGE(STATUS "Shared libraries enabled.")
ENDIF(NOT CXXEXCEPT_BUILD_SHARED_LIBS)
#
OPTION(CXXEXCEPT_BUILD_WITH_TEST "Enable Testing." OFF)
OPTION(CXXEXCEPT_BUILD_WITH_DOCS "Build documentation." OFF)
IF(EXCEPTCXX_PROJECT_ROOT)
SET(CXXEXCEPT_BUILD_WITH_DOCS ON)
ENDIF()
# Set version of the project.
SET(CXXEXCEPT_VERSION_MAJOR 0)
SET(CXXEXCEPT_VERSION_MINOR 1)
SET(CXXEXCEPT_VERSION_REVISION 0)
SET(CXXEXCEPT_VERSION_STATE a)
SET(CXXEXCEPT_VERSION ${VERSION_MAJOR}.${VERSION_MINOR}${VERSION_STATE}${VERSION_REVISION} )
SET(CXXEXCEPT_PACKAGE_VERSION 0)
SET(CXXEXCEPT_PROJECT_VERSION "${CXXEXCEPT_VERSION}")
FIND_PACKAGE(Git QUIET)
IF(GIT_FOUND)
MESSAGE(STATUS "git found: ${GIT_EXECUTABLE} -- ${GIT_VERSION_STRING}")
ENDIF()
IF(NOT CXXEXCEPT_IGNORE_GIT_HASH AND GIT_FOUND)
# Get the current working branch
EXECUTE_PROCESS(
COMMAND git rev-parse --abbrev-ref HEAD
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
OUTPUT_VARIABLE GIT_BRANCH
OUTPUT_STRIP_TRAILING_WHITESPACE
ERROR_QUIET
)
# Get the latest abbreviated commit hash of the working branch
EXECUTE_PROCESS(
COMMAND git rev-parse --short=8 HEAD
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
OUTPUT_VARIABLE GIT_COMMIT_HASH
OUTPUT_STRIP_TRAILING_WHITESPACE
ERROR_QUIET
)
EXECUTE_PROCESS(
COMMAND git describe --exact-match --tags 2> /dev/null || git rev-parse --short HEAD
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
OUTPUT_VARIABLE GIT_TAG
OUTPUT_STRIP_TRAILING_WHITESPACE
ERROR_QUIET
)
ENDIF()
LIST(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake-modules" )
SET(LIBCXXEXCEPT_COMPONENT "LIBCXXEXCEPT{VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_REVISION}")
SET(LIBCXXEXCEPT-DEV_COMPONENT "LIBCXXEXCEPT{VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_REVISION}-dev")
SET(CPACK_COMPONENTS_ALL ${LIBCXXEXCEPT_COMPONENT} ${LIBCXXEXCEPT-DEV_COMPONENT} )
#####################################
# Compiler toolchain
#####################################
IF(MSVC)
OPTION( CXXEXCEPT_BUILD_INSTALL_PDB
"Install MSVC debug files."
ON
)
IF(NOT (MSVC_VERSION LESS 1900))
# Multibyte character set is deprecated since at least MSVC2015 (possibly earlier)
ADD_DEFINITIONS( -DUNICODE -D_UNICODE )
ENDIF()
ENDIF()
# GCC compiler flag options.
IF((CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX) AND NOT CMAKE_COMPILER_IS_MINGW)
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wpedantic -Wextra -Wall -Wno-attributes")
IF (CMAKE_BUILD_TYPE STREQUAL "Release")
ELSE()
ADD_DEFINITIONS(-D_GLIBCXX_ASSERTIONS)
ENDIF()
ELSEIF(MSVC)
# Enable multi-core compilation with MSVC
IF( "${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang" ) # clang-cl
ADD_COMPILE_OPTIONS(/bigobj /W4)
ELSE() # msvc
ADD_COMPILE_OPTIONS(/MP /bigobj /W4)
ENDIF()
ENDIF()
# Inlucde external resources.
IF(CXXEXCEPT_BUILD_WITH_EXTERNAL_PROJECT)
ADD_SUBDIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/extern/backward-cpp)
ENDIF(CXXEXCEPT_BUILD_WITH_EXTERNAL_PROJECT)
############################################
# Exception Library Target.
############################################
SET(CXXEXCEPT_SOURCE_FILES
${CMAKE_CURRENT_SOURCE_DIR}/cxxexcept/Exception.hpp
)
ADD_LIBRARY(cxxexcept INTERFACE)
# Required c++ features - use to determine what C++ version is required
TARGET_COMPILE_FEATURES(cxxexcept INTERFACE cxx_constexpr cxx_noexcept cxx_override
cxx_sizeof_member cxx_static_assert cxx_decltype cxx_defaulted_functions cxx_relaxed_constexpr
cxx_default_function_template_args)
TARGET_INCLUDE_DIRECTORIES (cxxexcept
INTERFACE
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/cxxexcept>
$<INSTALL_INTERFACE:cxxexcept>
)
# Set predefined macro for version.
TARGET_COMPILE_DEFINITIONS(cxxexcept INTERFACE CXXE_VERSION="${CXXEXCEPT_PROJECT_VERSION}")
TARGET_LINK_LIBRARIES(cxxexcept INTERFACE backward dl fmt ${BACKWARD_LIBRARIES})
# # Install the header file and export the target
INSTALL(FILES ${PROJECT_SOURCE_DIR}/cxxexcept/Exception.hpp DESTINATION include)
IF (BUILD_SHARED_LIBS AND CMAKE_SIZEOF_VOID_P EQUAL 8)
SET_PROPERTY(TARGET cxxexcept PROPERTY POSITION_INDEPENDENT_CODE ON)
SET_PROPERTY(TARGET backward PROPERTY POSITION_INDEPENDENT_CODE ON)
ENDIF()
IF(CXXEXCEPT_BUILD_WITH_TEST)
ENABLE_TESTING()
ADD_SUBDIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/test)
ENDIF()
###############################
# Generate documentations.
###############################
IF(CXXEXCEPT_BUILD_WITH_DOCS)
ENDIF(CXXEXCEPT_BUILD_WITH_DOCS)
SET(CMAKE_INSTALL_FULL_INCLUDEDIR ${CMAKE_INSTALL_PREFIX}/${CXXEXCEPT_INCLUDE_INSTALL_DIR})
SET(CMAKE_INSTALL_FULL_LIBDIR ${CMAKE_INSTALL_PREFIX}/${CXXEXCEPT_LIB_INSTALL_DIR})
SET(CMAKE_INSTALL_FULL_BINDIR ${CMAKE_INSTALL_PREFIX}/${CXXEXCEPT_BIN_INSTALL_DIR})
#-----------------------------------------------------------------------------
# Create install packages for debian system.
IF(CMAKE_CPACK_COMMAND AND UNIX AND CXXEXCEPT_BUILD_OPT_BUILD_PACKAGES)
SET(CPACK_GENERATOR "DEB")
SET(CPACK_DEBIAN_PACKAGE_MAINTAINER "valdemar lindberg")
# Packing information
SET(CPACK_PACKAGE_NAME "cxxexcept${CXXEXCEPT_VERSION_MAJOR}.${CXXEXCEPT_VERSION_MINOR}")
SET(CPACK_PACKAGE_CONTACT "" CACHE STRING "Package maintainer and PGP signer.")
SET(CPACK_PACKAGE_VENDOR "https://github.com/voldien/cxxexcept")
SET(CPACK_PACKAGE_DISPLAY_NAME "CxxExcept ${VERSION}")
SET(CPACK_PACKAGE_DESCRIPTION_SUMMARY " - ${VERSION}")
SET(CPACK_PACKAGE_VERSION "${CXXEXCEPT_VERSION}.${CXXEXCEPT_PACKAGE_VERSION}" )
SET(CPACK_PACKAGE_VERSION_MAJOR "${CXXEXCEPT_VERSION_MAJOR}")
SET(CPACK_PACKAGE_VERSION_MINOR "${CXXEXCEPT_VERSION_MINOR}")
SET(CPACK_PACKAGE_VERSION_PATCH "${CXXEXCEPT_VERSION_PATCH}")
SET(CPACK_PACKAGE_INSTALL_DIRECTORY "cxxexcept")
SET(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/LICENSE")
#
STRING(TOUPPER ${LIBCXXEXCEPT_COMPONENT} "LIBCXXEXCEPT_COMPONENT_UPPER")
STRING(TOUPPER ${LIBCXXEXCEPT-DEV_COMPONENT} "LIBCXXEXCEPT-DEV_COMPONENT_UPPER")
#
SET(CPACK_COMPOENTT_${LIBFRACORE_COMPONENT_UPPER}_DISPLAY_NAME "")
SET(CPACK_COMPOENTT_${LIBFRACORE-DEV_COMPONENT_UPPER}_DISPLAY_NAME "")
SET(CPACK_COMPONENT_${LIBFRACORE-DEV_COMPONENT_UPPER}_DEPENDS $ "{LIBCXXEXCEPT_COMPONENT}" )
SET(CPACK_COMPOENTT_${LIBFRACORE-DEV_COMPONENT_UPPER}_DISPLAY_NAME "")
SET(CPACK_COMPONENT_${LIBCXXEXCEPT_COMPONENT_UPPER}_DISPLAY_NAME "libraries")
SET(CPACK_COMPONENT_${LIBCXXEXCEPT-DEV_COMPONENT_UPPER}_DISPLAY_NAME "common headers and installs")
SET(CPACK_COMPONENT_${LIBCXXEXCEPT-DEV_COMPONENT_UPPER}_DEPENDS $ "{LIBCXXEXCEPT_COMPONENT}" )
SET(CPACK_COMPONENT_LIBCXXEXCEPT-DEV_DISPLAY_NAME "${CPACK_COMPONENT_${LIBCXXEXCEPT-DEV_COMPONENT}_DISPLAY_NAME}" )
SET(CPACK_COMPONENT_LIBCXXEXCEPT-DEV_DEPENDS "${LIBCXXEXCEPT-DEV_COMPONENT}" )
SET(CPACK_DEBIAN_BUILD_DEPENDS debhelper cmake zlib1g-dev pkg-config)
# debian
SET(CPACK_DEBIAN_PACKAGE_PRIORITY "optional")
SET(CPACK_DEBIAN_CMAKE_OPTIONS "")
SET(CPACK_DEBIAN_PACKAGE_SECTION "libs" )
SET(CPACK_DEBIAN_PACKAGE_DEPENDS "${CPACK_COMPONENTS_ALL} libfmt-dev")
SET(CPACK_DEBIAN_PACKAGE_SUGGESTS)
SET(cPACK_DEBIAN_PACKAGE_NAME "cxxexcept")
SET(CPACK_DEBIAN_PACKAGE_REMOVE_SOURCE_FILES build doc obj samples packaging utils)
SET(CPACK_DEBIAN_PACKAGE_SOURCE_COPY svn export --force)
SET(CPACK_DEBIAN_CHANGELOG)
execute_process(COMMAND lsb_release -is
OUTPUT_VARIABLE _lsb_distribution OUTPUT_STRIP_TRAILING_WHITESPACE
RESULT_VARIABLE _lsb_release_failed)
SET(CPACK_DEBIAN_DISTRIBUTION_NAME ${_lsb_distribution} CACHE STRING "Name of the distrubiton")
STRING(TOLOWER ${CPACK_DEBIAN_DISTRIBUTION_NAME} CPACK_DEBIAN_DISTRIBUTION_NAME)
IF( ${CPACK_DEBIAN_DISTRIBUTION_NAME} STREQUAL "ubuntu" )
SET(CPACK_DEBIAN_DISTRIBUTION_RELEASES lucid maverick natty oneiric precise CACHE STRING "Release code-names of the distrubiton release")
ENDIF()
SET(DPUT_HOST "" CACHE STRING "PPA repository to upload the debian sources")
INCLUDE(DebSourcePPA)
INCLUDE(CPack)
ENDIF()
# Final verbose message status.
MESSAGE(STATUS "")
MESSAGE(STATUS "These are the configured paths:")
MESSAGE(STATUS " PREFIX: ${CMAKE_INSTALL_PREFIX}")
MESSAGE(STATUS " LIB_DIR: ${LIB_DIR}")
MESSAGE(STATUS " RENDERING_DIR: ${PLUGIN_DIR}")
MESSAGE(STATUS " BIN_DIR: ${BIN_DIR}")
MESSAGE(STATUS " DATA_DIR: ${DATA_DIR}")
MESSAGE(STATUS " MAN_DIR: ${MAN_DIR}")
MESSAGE(STATUS " DOC_DIR: ${DOC_DIR}")
MESSAGE(STATUS " ICON_DIR: ${ICON_DIR}")
MESSAGE(STATUS " SVG_DIR: ${SVG_DIR}")
MESSAGE(STATUS " MENU_DIR: ${MENU_DIR}")
MESSAGE(STATUS "")
MESSAGE(STATUS "Options:")
MESSAGE(STATUS " LAYOUT: ${LAYOUT}")
MESSAGE(STATUS "")
MESSAGE(STATUS "Build type: ${CMAKE_BUILD_TYPE}")
MESSAGE(STATUS "Target bitness: ${CMAKE_SIZEOF_VOID_P}*8")
MESSAGE(STATUS "")