-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
164 lines (143 loc) · 5.91 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
cmake_minimum_required(VERSION 3.12 FATAL_ERROR)
if(POLICY CMP0048)
cmake_policy(SET CMP0048 NEW) # project() command manages VERSION vars
endif()
if(POLICY CMP0074)
cmake_policy(SET CMP0074 NEW) # Use <PackageName>_ROOT variables
endif()
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake")
include(BuildType)
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
string(TIMESTAMP version_tweak ".%Y%m%d")
else()
set(version_tweak "")
endif()
project( Rubik
VERSION "0.0.1${version_tweak}"
DESCRIPTION "Simulate Rubik's cube"
HOMEPAGE_URL "https://www.github.com/mikkoi/rubik"
LANGUAGES C)
# Enable dashboard scripting
include(CTest)
set(CMAKE_C_STANDARD 11)
set(CMAKE_C_STANDARD_REQUIRED ON)
set(CMAKE_C_EXTENSIONS OFF)
# #############################################################################
# Configure project
set(private_include_directories "${CMAKE_BINARY_DIR}/private_include")
configure_file(cmake/config.h.in "${private_include_directories}/config.h" @ONLY)
add_library(config INTERFACE)
target_include_directories(config INTERFACE "${private_include_directories}")
# #############################################################################
# CMake enabled static analysis
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
# Different tests are only executed when the corresponding
# tools are available. Presence in the system is checked individually.
#
# Run analysis only when the build type is Debug,
# not any of the Release variants.
# In the future Cppcheck and other tools will improve
# and find new faults in our code.
# We do not want to create headache for the future admins and packagers,
# only for the future programmers.
if(CMAKE_VERSION VERSION_GREATER_EQUAL "3.10")
# CMAKE_<LANG>_CPPCHECK only supported in 3.10 and upwards.
# E.g. CMAKE_<LANG>_CPPLINT already since CMake 3.8.
find_package(Cppcheck)
if(Cppcheck_FOUND)
set(CMAKE_C_CPPCHECK
"${Cppcheck_EXECUTABLE};--quiet;--std=c89;--enable=warning,style,performance,portability")
set(CMAKE_CXX_CPPCHECK "${CMAKE_C_CPPCHECK}")
endif(Cppcheck_FOUND)
endif()
if(CMAKE_VERSION VERSION_GREATER_EQUAL "3.6.3")
# CMAKE_<LANG>_CLANG_TIDY only supported in 3.6.3 and upwards.
find_package(ClangTidy 5.0)
if(ClangTidy_FOUND)
set(CMAKE_C_CLANG_TIDY "${ClangTidy_EXECUTABLE};-checks='*';-format-style=none")
set(CMAKE_CXX_CLANG_TIDY "${CMAKE_C_CLANG_TIDY}")
endif(ClangTidy_FOUND)
endif()
if(CMAKE_VERSION VERSION_GREATER_EQUAL "3.3.2")
# CMAKE_<LANG>_INCLUDE_WHAT_YOU_USE only supported in 3.3.2 and upwards.
find_package(ArtisticStyle 3.1)
if(ArtisticStyle_FOUND)
set(CMAKE_C_INCLUDE_WHAT_YOU_USE "${CMAKE_SOURCE_DIR}/cmake/iwyu-astyle.pl;--real-exe=${ArtisticStyle_EXECUTABLE}")
set(CMAKE_CXX_INCLUDE_WHAT_YOU_USE "${CMAKE_C_INCLUDE_WHAT_YOU_USE}")
endif(ArtisticStyle_FOUND)
endif()
endif()
# #############################################################################
# Compiler based static analysis
# https://stackoverflow.com/questions/17206568/what-is-the-difference-between-c-c99-ansi-c-and-gnu-c
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
if(
CMAKE_C_COMPILER_ID STREQUAL "GNU"
OR CMAKE_C_COMPILER_ID STREQUAL "Clang"
OR CMAKE_C_COMPILER_ID STREQUAL "AppleClang")
string(APPEND WARNING_COMPILER_FLAGS
" -Wall"
" -Wextra"
" -pedantic"
" -Wconversion"
" -Wsign-conversion"
" -Wpedantic"
# " -Wlogical-op"
#" -fsanitize=address" # Disable sanitizers to activate libasan for valgrind.
# " -static-libasan"
" -fno-omit-frame-pointer"
" -Wpointer-arith -Wstrict-prototypes"
" -Wstrict-prototypes -Wpointer-arith"
" -Wmissing-prototypes -Wmissing-declarations"
" -Wwrite-strings -Wcast-qual -Wcast-align"
" -Wbad-function-cast"
" -Wformat-security -Wformat-nonliteral"
" -Wmissing-format-attribute"
" -Winline"
)
# https://dwheeler.com/secure-programs/Secure-Programs-HOWTO.html#C-CPP
string(APPEND CMAKE_C_FLAGS ${WARNING_COMPILER_FLAGS})
string(APPEND CMAKE_CXX_FLAGS ${WARNING_COMPILER_FLAGS})
endif()
if(CMAKE_C_COMPILER_ID STREQUAL "GNU"
AND (CMAKE_C_COMPILER_VERSION VERSION_EQUAL 4.3
OR CMAKE_C_COMPILER_VERSION VERSION_GREATER 4.3))
# Blasted Clang! Doesn't support everything GNU does!
# When using _FORTIFY_SOURCE, must set optimize level to at least 1.
add_compile_definitions("_FORTIFY_SOURCE=2")
string(APPEND CMAKE_C_FLAGS " -O1")
string(APPEND CMAKE_CXX_FLAGS " -O1")
endif()
endif()
# Doxygen
# find_package(Doxygen)
# option(BUILD_DOCUMENTATION
# "Create and install the HTML based API documentation (requires Doxygen)"
# ${DOXYGEN_FOUND}
# )
#
# if(BUILD_DOCUMENTATION)
# if(NOT DOXYGEN_FOUND)
# message(FATAL_ERROR "Doxygen is needed to build the documentation.")
# endif()
#
# set(doxyfile_in ${CMAKE_CURRENT_SOURCE_DIR}/Doxyfile.in)
# set(doxyfile ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile)
# configure_file(${doxyfile_in} ${doxyfile} @ONLY)
#
# message("Doxygen build started.")
# add_custom_target(doc
# COMMAND ${DOXYGEN_EXECUTABLE} ${doxyfile}
# WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
# COMMENT "Generating API documentation with Doxygen"
# VERBATIM)
#
# # install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/html DESTINATION share/doc)
# endif()
# add_subdirectory(external)
add_subdirectory(src)
# #############################################################################
# Packaging
include(InstallRequiredSystemLibraries)
set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_SOURCE_DIR}/LICENSE")
include(CPack)