forked from cieslarmichal/config-cxx
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
97 lines (73 loc) · 2.54 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
cmake_minimum_required(VERSION 3.22)
set(PROJECT_NAME config-cxx)
project(${PROJECT_NAME} CXX)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED YES)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
option(BUILD_CONFIG_CXX_TESTS DEFAULT ON)
if (MSVC)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /std:c++20 /permissive- /bigobj")
else ()
set(CMAKE_CXX_FLAGS
"${CMAKE_CXX_FLAGS} -Wall -Wextra -Wpedantic -Wconversion -Wformat"
)
endif ()
set(LIBRARY_NAME config-cxx)
set(SOURCES
src/Config.cpp
src/ConfigDirectoryPathResolver.cpp
src/environment/EnvironmentParser.cpp
src/environment/ConfigProvider.cpp
src/filesystem/FileSystemService.cpp
src/filesystem/ExecutableFinder.cpp
src/JsonConfigLoader.cpp
src/YamlConfigLoader.cpp
src/XmlConfigLoader.cpp
)
set(UT_SOURCES
src/ConfigTest.cpp
src/ConfigDirectoryPathResolverTest.cpp
src/environment/EnvironmentParserTest.cpp
src/filesystem/FileSystemServiceTest.cpp
src/filesystem/ExecutableFinderTest.cpp
src/tests/EnvironmentSetter.cpp
src/tests/EnvironmentSetterTest.cpp
src/JsonConfigLoaderTest.cpp
src/YamlConfigLoaderTest.cpp
src/XmlConfigLoaderTest.cpp
)
add_library(${LIBRARY_NAME} ${SOURCES})
add_subdirectory(externals/json)
target_link_libraries(${LIBRARY_NAME} PRIVATE nlohmann_json)
add_subdirectory(externals/yaml-cpp)
target_link_libraries(${LIBRARY_NAME} PUBLIC yaml-cpp)
add_subdirectory(externals/pugixml)
target_link_libraries(${LIBRARY_NAME} PUBLIC pugixml)
target_include_directories(
${LIBRARY_NAME}
INTERFACE "${CMAKE_CURRENT_LIST_DIR}/include"
PRIVATE "${CMAKE_CURRENT_LIST_DIR}/include")
if (BUILD_CONFIG_CXX_TESTS)
add_subdirectory(externals/googletest)
set(GTEST_INCLUDE_DIR
"${CMAKE_SOURCE_DIR}/externals/googletest/googletest/include")
set(GMOCK_INCLUDE_DIR
"${CMAKE_SOURCE_DIR}/externals/googletest/googlemock/include")
enable_testing()
set(target_code_coverage_ALL 1)
include("cmake/cmake-coverage.cmake")
add_code_coverage_all_targets()
add_executable(${LIBRARY_NAME}-UT ${UT_SOURCES})
target_link_libraries(${LIBRARY_NAME}-UT PRIVATE ${LIBRARY_NAME} gmock_main nlohmann_json yaml-cpp pugixml)
target_include_directories(
${LIBRARY_NAME}-UT
PRIVATE ${GTEST_INCLUDE_DIR}
${GMOCK_INCLUDE_DIR}
${CMAKE_CURRENT_LIST_DIR}
)
add_test(
NAME ${LIBRARY_NAME}-UT
COMMAND ${LIBRARY_NAME}-UT
WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR})
target_code_coverage(${LIBRARY_NAME}-UT ALL)
endif ()