-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeLists.txt
71 lines (51 loc) · 1.86 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
cmake_minimum_required(VERSION 3.6 FATAL_ERROR)
project(hello LANGUAGES C)
# Enable IPO on release builds:
if(CMAKE_BUILD_TYPE MATCHES "^(Release|MinSizeRel)$" AND CMAKE_VERSION VERSION_GREATER_EQUAL 3.9)
cmake_policy(SET CMP0069 NEW) # CMP0069: INTERPROCEDURAL_OPTIMIZATION is enforced when enabled
include(CheckIPOSupported)
check_ipo_supported(RESULT IPO_SUPPORTED LANGUAGES C)
if(IPO_SUPPORTED)
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION TRUE)
endif()
endif()
# Enable PIE:
if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.14)
cmake_policy(SET CMP0083 NEW) # CMP0083: Add PIE options when linking executable
include(CheckPIESupported)
check_pie_supported(OUTPUT_VARIABLE PIE_SUPPORTED LANGUAGES C)
if(PIE_SUPPORTED)
set(CMAKE_POSITION_INDEPENDENT_CODE TRUE)
endif()
endif()
# Set the default C standard:
set(CMAKE_C_STANDARD 11)
set(CMAKE_C_STANDARD_REQUIRED ON)
set(CMAKE_C_EXTENSIONS OFF)
# Enable compiler warnings:
if(NOT "${CMAKE_C_COMPILER_FRONTEND_VARIANT}" STREQUAL "")
set(c_compiler "${CMAKE_C_COMPILER_FRONTEND_VARIANT}")
elseif(NOT "${CMAKE_C_SIMULATE_ID}" STREQUAL "")
set(c_compiler "${CMAKE_C_SIMULATE_ID}")
else()
set(c_compiler "${CMAKE_C_COMPILER_ID}")
endif()
if(c_compiler MATCHES "^(GNU|(ARM|Apple)?Clang|Intel(LLVM)?)$")
set(c_flags "-pedantic-errors -Wall -Wextra")
elseif(c_compiler STREQUAL MSVC)
set(c_flags "/W4")
endif()
if(NOT "${c_flags}" STREQUAL "")
if("${CMAKE_C_FLAGS}" STREQUAL "")
set(CMAKE_C_FLAGS "${c_flags}")
else()
string(APPEND CMAKE_C_FLAGS " ${c_flags}")
endif()
endif()
# Enable clang-tidy:
set(CMAKE_C_CLANG_TIDY clang-tidy -p "${CMAKE_CURRENT_BINARY_DIR}")
# Add the executable and the libraries it depends upon:
find_package(PkgConfig MODULE REQUIRED)
pkg_check_modules(GLIB REQUIRED IMPORTED_TARGET glib-2.0)
add_executable(hello main.c)
target_link_libraries(hello PRIVATE PkgConfig::GLIB)