forked from Rukakuka/otus-cxx-developer-professional
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
104 lines (77 loc) · 2.53 KB
/
Copy pathCMakeLists.txt
File metadata and controls
104 lines (77 loc) · 2.53 KB
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
98
99
100
101
102
103
104
cmake_minimum_required(VERSION 3.10)
set(PATCH_VERSION "1" CACHE INTERNAL "Patch version")
set(PROJECT_VESRION 0.0.${PATCH_VERSION})
project(helloworld VERSION ${PROJECT_VESRION})
find_package(Boost COMPONENTS unit_test_framework REQUIRED)
# We do not want gtest files to appear in target debian package
set(INSTALL_GTEST OFF)
include(FetchContent)
FetchContent_Declare(
googletest
GIT_REPOSITORY https://github.com/google/googletest.git
GIT_TAG release-1.12.1
)
FetchContent_MakeAvailable(googletest)
add_library(GTest::GTest INTERFACE IMPORTED)
target_link_libraries(GTest::GTest INTERFACE gtest_main)
configure_file(version.h.in version.h)
add_executable(helloworld_cli main.cpp)
add_library(helloworld lib.cpp)
add_executable(test_version test_version.cpp)
add_executable(gtest_version gtest_version.cpp)
set_target_properties(helloworld_cli helloworld test_version PROPERTIES
CXX_STANDARD 14
CXX_STANDARD_REQUIRED ON
)
target_include_directories(helloworld
PRIVATE "${CMAKE_BINARY_DIR}"
)
set_target_properties(test_version PROPERTIES
COMPILE_DEFINITIONS BOOST_TEST_DYN_LINK
INCLUDE_DIRECTORIES ${Boost_INCLUDE_DIR}
)
target_link_libraries(helloworld_cli PRIVATE
helloworld
)
# target_link_options(helloworld_cli PRIVATE -static-libgcc -static-libstdc++)
target_link_libraries(test_version
${Boost_LIBRARIES}
helloworld
)
target_link_libraries(gtest_version
PRIVATE
GTest::GTest
helloworld
)
if (MSVC)
target_compile_options(helloworld_cli PRIVATE
/W4
)
target_compile_options(helloworld PRIVATE
/W4
)
target_compile_options(test_version PRIVATE
/W4
)
else ()
target_compile_options(helloworld_cli PRIVATE
-Wall -Wextra -pedantic -Werror
)
target_compile_options(helloworld PRIVATE
-Wall -Wextra -pedantic -Werror
)
target_compile_options(test_version PRIVATE
-Wall -Wextra -pedantic -Werror
)
endif()
install(TARGETS helloworld_cli RUNTIME DESTINATION bin)
set(CPACK_GENERATOR DEB)
set(CPACK_PACKAGE_VERSION_MAJOR "${PROJECT_VERSION_MAJOR}")
set(CPACK_PACKAGE_VERSION_MINOR "${PROJECT_VERSION_MINOR}")
set(CPACK_PACKAGE_VERSION_PATCH "${PROJECT_VERSION_PATCH}")
set(CPACK_PACKAGE_CONTACT kovalevdenis@gmail.com)
# set(CPACK_DEBIAN_PACKAGE_DEPENDS "libc6 (>= 2.31)")
include(CPack)
enable_testing()
add_test(test_version test_version)
add_test(gtest_version gtest_version)