-
Notifications
You must be signed in to change notification settings - Fork 1
/
CMakeLists.txt
71 lines (55 loc) · 1.85 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.11...3.27)
project(ytc
LANGUAGES CXX
VERSION 1.0.0
DESCRIPTION "YAML Template Class example")
# See: https://github.com/conan-io/cmake-conan/issues/159
cmake_policy(SET CMP0025 NEW)
# Determine if ytc is built as a subproject (using add_subdirectory) or if it
# is the master project.
set(MASTER_PROJECT OFF)
if(CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR)
set(MASTER_PROJECT ON)
message(STATUS "CMake version: ${CMAKE_VERSION}")
endif()
# Provide path for cmake scripts
list(APPEND CMAKE_MODULE_PATH ${ytc_SOURCE_DIR}/cmake)
include(language-standard)
include(conan-bootstrap)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin")
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib")
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib")
# Set the compiler standard to C++17
cxx_17()
# Conan bootstrap
conan_bootstrap()
conan_cmake_run(
CONANFILE conanfile.txt
BASIC_SETUP CMAKE_TARGETS
BUILD missing)
# Adjusts the standard library flags (libc++`, libstdc++, libstdc++11)
conan_set_libcxx()
# Code Coverage Configuration
add_library(coverage_config INTERFACE)
option(CODE_COVERAGE "Builds targets with code coverage instrumentation." OFF)
if(CODE_COVERAGE AND CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")
# Add required flags (GCC & LLVM/Clang)
target_compile_options(coverage_config INTERFACE
-O0 # no optimization
-g # generate debug info
--coverage # sets all required flags
)
if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.13)
target_link_options(coverage_config INTERFACE --coverage)
else()
target_link_libraries(coverage_config INTERFACE --coverage)
endif()
endif()
add_subdirectory(src)
if(MASTER_PROJECT)
include(CTest)
endif()
if(MASTER_PROJECT AND BUILD_TESTING)
message(STATUS "Include test sources")
add_subdirectory(tests)
endif()