-
Notifications
You must be signed in to change notification settings - Fork 6
/
CMakeLists.txt
95 lines (76 loc) · 3.4 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
cmake_minimum_required(VERSION 3.10)
project(example)
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake")
################################################################################
############################ OUTPUT DIRECTORIES ############################
################################################################################
if(NOT DEFINED CMAKE_ARCHIVE_OUTPUT_DIRECTORY)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
endif()
if(NOT DEFINED CMAKE_LIBRARY_OUTPUT_DIRECTORY)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
endif()
if(NOT DEFINED CMAKE_RUNTIME_OUTPUT_DIRECTORY)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
endif()
################################################################################
################################ GOOGLE TEST ###############################
################################################################################
# https://github.com/google/googletest/blob/master/googletest/README.md#incorporating-into-an-existing-cmake-project
# <copy>
# Download and unpack googletest at configure time
configure_file(${CMAKE_CURRENT_LIST_DIR}/cmake/GoogleTest-CMakeLists.txt.in
googletest/CMakeLists.txt)
execute_process(COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}" .
RESULT_VARIABLE result
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/googletest )
if(result)
message(FATAL_ERROR "CMake step for googletest failed: ${result}")
endif()
execute_process(COMMAND ${CMAKE_COMMAND} --build .
RESULT_VARIABLE result
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/googletest )
if(result)
message(FATAL_ERROR "Build step for googletest failed: ${result}")
endif()
# Prevent overriding the parent project's compiler/linker
# settings on Windows
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
# Add googletest directly to our build. This defines
# the gtest and gtest_main targets.
add_subdirectory(${CMAKE_BINARY_DIR}/googletest/googletest-src
${CMAKE_BINARY_DIR}/googletest/googletest-build
EXCLUDE_FROM_ALL)
# </copy>
include(GoogleTest)
enable_testing()
################################################################################
############################# COMPILER OPTIONS #############################
################################################################################
# Use C++ 17
set (CMAKE_CXX_STANDARD 17)
# Optimize during linking stage
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION TRUE) # LTO
# Allow linking the compiled code into a shared library (for Python modules)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
# Compiler flags for C++
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} \
-O3 -g3 \
-Wall -Wextra -Werror \
-Wsuggest-override \
-Wno-register \
-Wno-missing-braces \
-Wno-unknown-pragmas \
-fdiagnostics-show-option")
# Compiler flags for C
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} \
-O3 -g3 \
-Wall -Wextra -Werror")
################################################################################
################################# LIBRARIES ################################
################################################################################
add_subdirectory("greet")
################################################################################
############################### APPLICATIONS ###############################
################################################################################
add_subdirectory("applications")