-
Notifications
You must be signed in to change notification settings - Fork 0
/
ccf_init.cmake
80 lines (53 loc) · 2.23 KB
/
ccf_init.cmake
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
cmake_minimum_required(VERSION 3.28)
#### Early exit for common unsupported setups
if(${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_BINARY_DIR})
message(FATAL_ERROR "In-source builds not allowed. Please make a new directory (called a build directory) and run CMake from there. You may need to remove CMakeCache.txt.")
endif()
if(NOT CMAKE_GENERATOR STREQUAL "Ninja")
message(FATAL_ERROR "CCF only supports the Ninja generator. Please re-run CMake with -G Ninja. You may need to remove CMakeCache.txt.")
endif()
if(NOT CMAKE_CXX_COMPILER_ID STREQUAL "Clang"
OR NOT CMAKE_C_COMPILER_ID STREQUAL "Clang"
OR NOT "x${CMAKE_CXX_COMPILER_FRONTEND_VARIANT}" STREQUAL "xGNU")
#message(FATAL_ERROR "CCF only supports the Clang compiler, using the GNU-style command line (not clang-cl). Please re-run CMake with the C and C++ compiler set to clang/clang++. You may need to remove CMakeCache.txt.")
endif()
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
include(CheckIPOSupported)
check_ipo_supported()
#### Define options & config variables
option(WITH_TIDY "Run clang-tidy during the build, if clang is the compiler" ON)
set(CCF_DIR "${CMAKE_CURRENT_LIST_DIR}")
set(CCF_TEMPLATE_DIR "${CCF_DIR}/templates")
if(NOT DEFINED CCF_BUILD_SOURCE_DIR)
set(CCF_BUILD_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}")
endif()
if(NOT DEFINED CCF_BUILD_BINARY_DIR)
set(CCF_BUILD_BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}")
endif()
if(NOT DEFINED CCF_BUILD_THIRD_PARTY_DIR)
set( CCF_BUILD_THIRD_PARTY_DIR "${CCF_BUILD_SOURCE_DIR}/3rd-party/")
endif()
if(NOT DEFINED PREFERRED_CXX_EXTENSION)
set(PREFERRED_CXX_EXTENSION "cxx")
endif()
#### Ensure an empty cpp source file exists
set(CCF_EMPTY "${CCF_BUILD_BINARY_DIR}/__ccf_empty.${PREFERRED_CXX_EXTENSION}")
file(WRITE "${CCF_EMPTY}" "")
#### Configure PIC/PIE flags
# TODO: push/pop stack
cmake_policy(SET CMP0083 NEW)
include(CheckPIESupported)
check_pie_supported()
#### Include main code
include(build_helpers)
include(ccf_config)
include(CompilerConfig)
### testing
enable_testing()
set(CCF_IGNORE "^cmake;^build;^_3p$;^[.]git$;^[.]vscode$")
### Dependencies!
if(NOT DEFINED CCF_DEPENDENCY_SUBDIR)
set(CCF_DEPENDENCY_SUBDIR "_3p/")
endif()
set(CCF_DEPENDENCY_DIR "${CCF_BUILD_SOURCE_DIR}/${CCF_DEPENDENCY_SUBDIR}/")
include(ccf_3p)