-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
211 lines (178 loc) · 5.63 KB
/
CMakeLists.txt
File metadata and controls
211 lines (178 loc) · 5.63 KB
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
#
# File: CMakeLists.txt Part of commonpp.
#
# Distributed under the 2-clause BSD licence (See LICENCE.TXT file at the
# project root).
#
# Copyright (c) 2015 Thomas Sanchez. All rights reserved.
#
project(commonpp C CXX)
cmake_minimum_required(VERSION 3.9)
cmake_policy(SET CMP0005 NEW)
cmake_policy(SET CMP0069 NEW)
# Require at least Windows 7 See:
# https://msdn.microsoft.com/en-us/library/windows/desktop/aa383745(v=vs.85).aspx
if(WIN32)
add_definitions(-D_WIN32_WINNT=0x0601)
add_definitions(-DNTDDI_VERSION=0x06010000)
endif()
# Set a default build type if none was specified
if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
message(STATUS "Setting cmake build type to 'Debug' as none was specified.")
set(CMAKE_BUILD_TYPE
Debug
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"
"RelWithDebInfo")
endif()
if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
set(CMAKE_INSTALL_PREFIX
"/usr"
CACHE PATH "Default install prefix" FORCE)
endif()
set(CMAKE_CXX_STANDARD
20
CACHE STRING "C++ standard for all targets.")
set(INSTALL_LIB_DIR
lib
CACHE PATH "Installation directory for libraries")
set(INSTALL_BIN_DIR
bin
CACHE PATH "Installation directory for executables")
set(INSTALL_INCLUDE_DIR
include
CACHE PATH "Installation directory for header files")
set(INSTALL_CMAKE_DIR
"${INSTALL_LIB_DIR}/CMake/commonpp/"
CACHE PATH "Installation directory for cmake files")
option(BUILD_TESTS "Should the tests be built" ON)
set(commonpp_MAJOR "0")
set(commonpp_MINOR "1")
set(commonpp_MICRO "1")
set(CPACK_PACKAGE_VERSION_MAJOR ${commonpp_MAJOR})
set(CPACK_PACKAGE_VERSION_MINOR ${commonpp_MINOR})
set(CPACK_PACKAGE_VERSION_PATCH ${commonpp_MICRO})
set(commonpp_VERSION "${commonpp_MAJOR}.${commonpp_MINOR}.${commonpp_MICRO}")
message(
STATUS
"CMake Version : ${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}.${CMAKE_PATCH_VERSION}"
)
message(STATUS "commonpp Version : ${commonpp_VERSION}")
message(STATUS "Build Tests : ${BUILD_TESTS}")
message(STATUS "Build Type : ${CMAKE_BUILD_TYPE}")
message(
STATUS "System : ${CMAKE_SYSTEM_NAME} ${CMAKE_SYSTEM_VERSION}")
message(STATUS "Install Prefix : ${CMAKE_INSTALL_PREFIX}")
message(STATUS "Source Directory : ${commonpp_SOURCE_DIR}")
message(STATUS "C++ Compiler ID : ${CMAKE_CXX_COMPILER_ID}")
if(${CMAKE_CXX_COMPILER_ID} MATCHES GNU OR ${CMAKE_CXX_COMPILER_ID} MATCHES
Clang)
include(CheckCXXCompilerFlag)
check_cxx_compiler_flag(-Wno-unused-local-typedefs
HAVE_NOUNUSED_LOCAL_TYPEDEF)
# With clang + gcc we gave __attribute__ ((unused))
set(HAVE_UNUSED_ATTR 1)
if(UNIX)
include(CheckFunctionExists)
set(SAVE ${CMAKE_REQUIRED_LIBRARIES})
list(APPEND CMAKE_REQUIRED_LIBRARIES "rt")
check_function_exists("clock_getcpuclockid" HAVE_POSIX_CPU_CLOCK)
set(CMAKE_REQUIRED_LIBRARIES ${SAVE})
endif()
if(HAVE_NOUNUSED_LOCAL_TYPEDEF)
add_definitions("-Wno-unused-local-typedefs")
endif()
add_definitions("-Wextra -Wall -Wno-unused-parameter")
if(${CMAKE_BUILD_TYPE} MATCHES "Debug")
add_definitions("-fstack-protector-all")
if(${CMAKE_CXX_COMPILER_ID} MATCHES GNU)
add_definitions("-ggdb3")
endif()
endif()
endif()
# Actual Stuff ################################################################
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${commonpp_SOURCE_DIR}/cmake)
include(SubDirList)
include(MakeUnique)
include(CheckIncludeFiles)
include(ThreadLocal)
check_have_make_unique(HAVE_MAKE_UNIQUE)
check_include_files(sys/prctl.h HAVE_SYS_PRCTL_H)
check_have_thread_local_specifier(HAVE_THREAD_LOCAL_SPECIFIER)
# Thread
find_package(Threads REQUIRED)
find_package(HWLOC)
if(HWLOC_FOUND)
set(HAVE_HWLOC 1)
endif()
# Boost
if(NOT WIN32)
if(${BUILD_SHARED_LIBS})
set(Boost_USE_STATIC_LIBS OFF)
add_definitions("-DBOOST_ALL_DYN_LINK=1")
else()
set(Boost_USE_STATIC_LIBS ON)
endif()
set(Boost_USE_MULTITHREADED ON)
endif()
if("${CMAKE_SYSTEM_NAME}" MATCHES "Linux")
set(HAVE_SYSLOG 1)
endif()
find_package(
Boost 1.85.0
REQUIRED)
include_directories(SYSTEM ${Boost_INCLUDE_DIR})
link_directories(${Boost_LIBRARY_DIR})
# Only link required boost libraries, exclude test libraries
set(COMMONPP_DEPS
Boost::log
Boost::log_setup
Boost::thread
Boost::timer
Boost::chrono
${CMAKE_THREAD_LIBS_INIT})
if(UNIX AND NOT APPLE)
set(COMMONPP_DEPS ${COMMONPP_DEPS} rt)
endif()
if(${HAVE_HWLOC})
set(COMMONPP_DEPS ${COMMONPP_DEPS} ${HWLOC_LIBRARIES})
include_directories(SYSTEM ${HWLOC_INCLUDE_DIR})
endif()
add_subdirectory(src/)
add_subdirectory(include/)
if(${BUILD_TESTS})
enable_testing()
add_subdirectory(tests/)
endif()
if(${CMAKE_PROJECT_NAME} STREQUAL ${PROJECT_NAME})
find_program(
CLANG_FORMAT
NAMES clang-format
clang-format-9.0
clang-format-8.1
clang-format-8.0
clang-format-7.0
clang-format-6.2
clang-format-6.0
clang-format-5.2
clang-format-5.0
clang-format-4.0
clang-format-3.9
clang-format-3.8)
if(CLANG_FORMAT)
file(
GLOB_RECURSE
ALL_SOURCE_FILES
src/*.cpp
include/*.hpp
tests/*.cpp
tests/*.hpp
examples/*.cpp
examples/*.hpp
bench/*.cpp
bench/*.hpp)
add_custom_target(format COMMAND ${CLANG_FORMAT} -style=file -i
${ALL_SOURCE_FILES})
endif()
endif()