-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
187 lines (147 loc) · 5.74 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
cmake_minimum_required(VERSION 3.9)
# Add common functions
include(cmake/commons.cmake)
# The options and cofiguration defined here must come
# before CMake configure toolchains and project
# Determine build type
ct_option(CMAKE_BUILD_TYPE "Debug" STRING "Choose the type of build (Debug or Release)")
if(NOT CMAKE_OSX_ARCHITECTURES)
set(CMAKE_OSX_ARCHITECTURES "x86_64" CACHE STRING "macOS architecture to build; 64-bit is expected" FORCE)
endif()
# Project
project (ctfk
VERSION 0.0.1
DESCRIPTION "Chronotrix Framework"
LANGUAGES C CXX)
include(CMakeDependentOption)
include(GNUInstallDirs)
#############################################
#### BASE CONFIG ####
#############################################
# C/C++ version
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_C_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED True)
# Project config
set_property(GLOBAL PROPERTY USE_FOLDERS ON) # enable folders
set_property(GLOBAL PROPERTY PREDEFINED_TARGETS_FOLDER "CMake")
# Include the CMake Configuration and helpers files
include(cmake/config.cmake)
include(cmake/helpers.cmake)
# Set paths for chronotrix packages files
set(CT_FRWK_DIR "${PROJECT_SOURCE_DIR}")
set(CT_SRC "${CT_FRWK_DIR}/src/ct")
set(CT_INC "${CT_FRWK_DIR}/include/ct")
set(CMAKE_MODULE_PATH "${CT_FRWK_DIR}/cmake/modules")
set(CT_THIRDPARTY_DIR "${CT_FRWK_DIR}/thirdparty")
set(CT_THIRDPARTY_CMAKE_CONFIG_DIR "${CT_FRWK_DIR}/cmake/thirdparty")
set(CT_THIRDPARTY_HEADERS ${CT_THIRDPARTY_DIR}/headers)
set(CT_HEADER_GROUP "Header Files")
set(CT_SOURCE_GROUP "Source Files")
set(CMAKE_INSTALL_PREFIX "${CT_FRWK_DIR}/install/${PROJECT_NAME}")
#############################################
#### OPTIONS ####
#############################################
# Define BUILD_SHARED_LIBS property
ct_option(BUILD_SHARED_LIBS TRUE BOOL "TRUE = build Chronotrix as shared libraries. FALSE = build as static libraries")
# Build examples
ct_option(CT_EXAMPLES TRUE BOOL "TRUE = Build the Chronotrix examples. FALSE = Don't build examples")
# Build docs
ct_option(CT_DOCS FALSE BOOL "TRUE = generate the API documentation. FALSE = ignore it")
# Build tests
ct_option(CT_TESTS FALSE BOOL "Build tests")
# Check for clang-tidy
ct_option(ENABLE_CLANG_TIDY TRUE BOOL "Add clang-tidy automatically to builds")
if (ENABLE_CLANG_TIDY)
find_program(CLANG_TIDY_EXE NAMES "clang-tidy" PATHS /usr/local/opt/llvm/bin /usr/local/bin)
if (CLANG_TIDY_EXE)
set(CMAKE_CXX_CLANG_TIDY "${CLANG_TIDY_EXE};-header-filter=include\/ct\/.*.hpp")
message(STATUS "clang-tidy found: ${CLANG_TIDY_EXE}")
configure_file(.clang-tidy .clang-tidy COPYONLY)
else()
set(CMAKE_CXX_CLANG_TIDY "") # delete it
message(WARNING "clang-tidy not found! Skipping")
endif()
else()
set(CMAKE_CXX_CLANG_TIDY "")
endif()
# [WINDOWS] Make a multi options for executables
if(CT_OS_WINDOWS AND BUILD_SHARED_LIBS AND CT_EXAMPLES)
ct_multi_options(
CT_EXAMPLES_POSTCOMMAND
"exe_to_bin"
"exe_to_bin;bin_to_exe"
"Defines post build command for executables.
This is necessary to link executables with dynamic libraries.
* exe_to_bin = Build executables in the same folder of libraries
* bin_to_exe = Make a copy of libraries to the executable folders.")
endif()
#############################################
#### OS CONFIG ####
#############################################
# [WINDOWS] Should generate static or dynamic libraries
if(CT_OS_WINDOWS)
option(CT_STATIC_STDLIBS "TRUE to statically link to the standard libraries, FALSE to use them as DLLs" FALSE)
# the following combination of flags is not valid
if (BUILD_SHARED_LIBS AND CT_STATIC_STDLIBS)
message(FATAL_ERROR "Can not use BUILD_SHARED_LIBS and CT_STATIC_STDLIBS together.")
endif()
# for VC++, set globally compiler flags
if(CT_COMPILER_MSVC AND CT_STATIC_STDLIBS)
foreach(flag
CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE
CMAKE_CXX_FLAGS_MINSIZEREL CMAKE_CXX_FLAGS_RELWITHDEBINFO)
if(${flag} MATCHES "/MD")
string(REGEX REPLACE "/MD" "/MT" ${flag} "${${flag}}")
endif()
endforeach()
# add_compile_options("$<$<C_COMPILER_ID:MSVC>:/utf-8>")
# add_compile_options("$<$<CXX_COMPILER_ID:MSVC>:/utf-8>")
endif()
# There is a bug in MSVC Community 2019 >= v16.8.4
# does not recognize whitespace in source_group.
# This seems to happens after the configuration from above lines.
# So, we repest the defintions os groups again:
if(CT_COMPILER_MSVC)
set(CT_HEADER_GROUP "Headers Files")
set(CT_SOURCE_GROUP "Sources Files")
endif()
endif()
# [MACOSX] Setup
if(CT_OS_MACOSX)
set(XCODE_TEMPLATES_ARCH "\$(NATIVE_ARCH_ACTUAL)")
endif()
#############################################
#### OUTPUT AND LIB DIRECTORIES ####
#############################################
# Set output folders for libraries
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib")
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib")
set(LIBRARY_OUTPUT_PATH "${CMAKE_BINARY_DIR}/lib")
if (CT_OS_WINDOWS AND CT_EXAMPLES_POSTCOMMAND STREQUAL "exe_to_bin")
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin")
endif()
#############################################
#### ADD PACAKGES ####
#############################################
add_subdirectory(${CT_SRC})
# Examples
if (CT_EXAMPLES)
add_subdirectory("${CT_FRWK_DIR}/examples")
endif()
# Tests
if(CT_TESTS)
add_subdirectory("${CT_FRWK_DIR}/tests")
endif()
if(CT_DOCS)
add_subdirectory("${CT_FRWK_DIR}/docs")
endif()
#############################################
#### INSTALL ####
#############################################
# Install all packages includes
install(DIRECTORY "${CT_INC}"
DESTINATION include
COMPONENT devel
FILES_MATCHING PATTERN "*.hpp" PATTERN "*.inl")
ct_export_targets()