-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeLists.txt
90 lines (76 loc) · 2.84 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
cmake_minimum_required (VERSION 3.5)
project (HelloCI_C C)
project (HelloCI_Cpp CXX)
set(CMAKE_CXX_STANDARD 17)
# cmake info
message("MSVC = ${MSVC}")
message("CMAKE_C_COMPILER = ${CMAKE_C_COMPILER}")
message("CMAKE_C_COMPILER_ID = ${CMAKE_C_COMPILER_ID}")
message("CMAKE_CXX_COMPILER = ${CMAKE_CXX_COMPILER}")
message("CMAKE_CXX_COMPILER_ID = ${CMAKE_CXX_COMPILER_ID}")
message("CMAKE_C_FLAGS = ${CMAKE_C_FLAGS}")
message("CMAKE_C_FLAGS_DEBUG = ${CMAKE_C_FLAGS_DEBUG}")
message("CMAKE_C_FLAGS_RELEASE = ${CMAKE_C_FLAGS_RELEASE}")
# Compiler and build specific options
# https://cmake.org/cmake/help/latest/variable/CMAKE_LANG_COMPILER_ID.html
if (CMAKE_C_COMPILER_ID STREQUAL "Clang")
# using Clang
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -O0")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -O0")
elseif (CMAKE_C_COMPILER_ID STREQUAL "GNU")
# using GCC
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -O1")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -O1")
elseif (CMAKE_C_COMPILER_ID STREQUAL "MSVC")
# using Visual Studio C++
endif()
# https://cmake.org/cmake/help/latest/manual/cmake-variables.7.html#variables-that-describe-the-system
if(MSVC)
# warning level 4
add_compile_options(/W4)
else()
# additional warnings
add_compile_options(-Wall -Wextra --coverage)
add_link_options(--coverage)
#message("CMAKE_BUILD_TYPE = ${CMAKE_BUILD_TYPE}")
if("${CMAKE_BUILD_TYPE}" STREQUAL "Debug")
message("Configuring for Debug build")
#add_compile_options(-O0)
else()
message("Configuring for Release build")
#add_compile_options(-O2)
endif()
if ( (CMAKE_CXX_COMPILER_ID STREQUAL "GNU") OR (CMAKE_HOST_LINUX) )
# clang doesn't support -pg on Windows, only add profiling if using GCC or Linux
add_compile_options(-pg)
add_link_options(-pg)
endif()
if ( (CMAKE_CXX_COMPILER_ID STREQUAL "GNU") AND (CMAKE_HOST_WIN32) )
# on Windows -pg doesn't output data without -no-pie, only GCC supports -no-pie
add_compile_options(-no-pie)
add_link_options(-no-pie)
endif()
endif()
add_executable(HelloCI_C source/hello_c.c)
#target_compile_options(HelloCI_C PRIVATE -Wall)
target_include_directories(HelloCI_C PUBLIC include)
# Test build workflows: detect build, runtime and test failures
#target_compile_definitions(HelloCI_C PUBLIC TEST_FAIL_TO_COMPILE)
#target_compile_definitions(HelloCI_C PUBLIC TEST_FAIL_TO_LINK)
#target_compile_definitions(HelloCI_C PUBLIC TEST_FAIL_TO_RUN)
#target_compile_definitions(HelloCI_C PUBLIC TEST_FAIL_TO_TEST)
target_compile_definitions(HelloCI_C PUBLIC TEST_FAIL_TO_COVER)
target_compile_definitions(HelloCI_C PUBLIC TEST_PROFILING)
add_executable(HelloCI_Cpp source/HelloCpp.cpp)
# enable testing functionality
include(CTest)
enable_testing()
# define tests
add_test(
NAME HelloCI_C
COMMAND $<TARGET_FILE:HelloCI_C>
)
add_test(
NAME HelloCI_Cpp
COMMAND $<TARGET_FILE:HelloCI_Cpp>
)