-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
106 lines (90 loc) · 3.23 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
cmake_minimum_required(VERSION 3.13)
project(DPLL LANGUAGES C)
# For multi-config generatores possible builds types are "Debug" and "Release"
if(DEFINED CMAKE_CONFIGURATION_TYPES)
set(CMAKE_CONFIGURATION_TYPES Debug Release)
endif()
# Default build is a debug build
set(default_build_type "Debug")
if(NOT DEFINED CMAKE_CONFIGURATION_TYPES)
# Set default build for single config generators
if(CMAKE_BUILD_TYPE STREQUAL "")
set(CMAKE_BUILD_TYPE "${default_build_type}"
CACHE
STRING "Choose type of build (Debug/Release)"
FORCE)
endif()
elseif(DEFINED CMAKE_CONFIGURATION_TYPES)
# Set default build for ninja multi-config generator
if (${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.17")
set(CMAKE_DEFAULT_BUILD_TYPE "${default_build_type}")
endif()
endif()
unset(default_build_type)
# Correct CMAKE_BUILD_TYPE string to start with capital letter
if(DEFINED CMAKE_BUILD_TYPE)
string(SUBSTRING ${CMAKE_BUILD_TYPE} 0 1 CMAKE_BUILD_TYPE_HEAD)
string(SUBSTRING ${CMAKE_BUILD_TYPE} 1 -1 CMAKE_BUILD_TYPE_BODY)
string(TOUPPER ${CMAKE_BUILD_TYPE_HEAD} CMAKE_BUILD_TYPE_HEAD)
string(TOLOWER ${CMAKE_BUILD_TYPE_BODY} CMAKE_BUILD_TYPE_BODY)
string(CONCAT CMAKE_BUILD_TYPE ${CMAKE_BUILD_TYPE_HEAD} ${CMAKE_BUILD_TYPE_BODY})
unset(CMAKE_BUILD_TYPE_HEAD)
unset(CMAKE_BUILD_TYPE_BODY)
endif()
# Set default compiler options
set(CMAKE_C_STANDARD 99)
add_compile_options(-Wall)
add_compile_options(-Wextra)
add_compile_options(-pedantic)
option(
BUILD_HELPER_AS_SHARED_LIB
"Whether to build internal helper libraries as shared libraries.
Default is to build them as static libraries.
(Only useful for quicker compile times while developing)"
OFF
)
option(
USE_LTO
"Whether to use link-time optimization (LTO) / interprocedural
optimization (IPO)."
OFF
)
# Define main executable
add_executable(dpll "")
# Enable LTO / IPO if supported and requested:
if(USE_LTO)
# Check if LTO / IPO is supported
include(CheckIPOSupported)
check_ipo_supported(RESULT lto_supported OUTPUT lto_error LANGUAGES C)
if(lto_supported)
set_target_properties(dpll PROPERTIES INTERPROCEDURAL_OPTIMIZATION TRUE)
else()
message(WARNING "LTO not supported by compiler. Error: '${lto_error}'")
endif()
unset(lto_supported)
unset(lto_error)
endif()
add_subdirectory(libs)
add_subdirectory(src)
include(CTest)
if(BUILD_TESTING)
add_subdirectory(tests)
endif()
# Print build summary
if(CMAKE_BUILD_TYPE)
message(STATUS "Summary - Build Type: ${CMAKE_BUILD_TYPE}")
endif()
if(CMAKE_CONFIGURATION_TYPES)
message(STATUS "Summary - Build Type: <multi-configuration> (Default: ${CMAKE_DEFAULT_BUILD_TYPE})")
endif()
if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
message(STATUS "Summary - Build Type: NOT DEFINED! (not encouraged!)")
endif()
message(STATUS "Summary - Internal libs as shared libs: ${BUILD_HELPER_AS_SHARED_LIB} (BUILD_HELPER_AS_SHARED_LIB)")
get_property(using_lto TARGET dpll PROPERTY INTERPROCEDURAL_OPTIMIZATION)
if(NOT using_lto)
set(using_lto FALSE)
endif()
message(STATUS "Summary - Using LTO / IPO: ${using_lto} (USE_LTO)")
unset(using_lto)
message(STATUS "Summary - Test: ${BUILD_TESTING} (BUILD_TESTING)")