-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
149 lines (130 loc) · 5.51 KB
/
Copy pathCMakeLists.txt
File metadata and controls
149 lines (130 loc) · 5.51 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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
cmake_minimum_required(VERSION 3.20)
project(DSALibraries VERSION 1.0.0 LANGUAGES CXX)
include(FetchContent)
enable_testing()
include(CTest)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
if (NOT CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME)
message(STATUS "This project has a top-level one called [${CMAKE_PROJECT_NAME}]")
else ()
message(STATUS "This project is a top-level one")
endif ()
FetchContent_Declare(
googletest
URL https://github.com/google/googletest/archive/03597a01ee50ed33e9dfd640b249b4be3799d395.zip
DOWNLOAD_EXTRACT_TIMESTAMP TRUE
)
# For Windows: Prevent overriding the parent project's compiler/linker settings
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
FetchContent_MakeAvailable(googletest)
include(GoogleTest)
option(BUILD_TESTS "Build unit tests" OFF)
add_library(${PROJECT_NAME} STATIC
include/Containers/Stack/Stack.hpp
include/Utilities/Exception.hpp
include/Utilities/Allocator.hpp
include/Utilities/Memory.hpp
include/Utilities/Algorithm.hpp
include/Containers/List/List.hpp
include/Containers/List/ListIterator.hpp
include/Containers/List/ListNode.hpp
include/Containers/List/ListExceptions.hpp
include/Containers/SList/SList.hpp
include/Containers/SList/SListIterator.hpp
include/Containers/SList/SListNode.hpp
include/Containers/SList/SListExceptions.hpp
include/Containers/DList/DList.hpp
include/Containers/DList/DListIterator.hpp
include/Containers/DList/DListNode.hpp
include/Containers/DList/DListExceptions.hpp
include/Containers/CList/CList.hpp
include/Containers/CList/CListIterator.hpp
include/Containers/CList/CListNode.hpp
include/Containers/CList/CListExceptions.hpp
include/Containers/Vector/VectorBase.hpp
include/Containers/Vector/VectorExceptions.hpp
include/Containers/Vector/Vector.hpp
include/Containers/Vector/VectorIterator.hpp
include/Utilities/AlignedBuffer.hpp)
target_sources(${PROJECT_NAME}
PRIVATE
)
target_include_directories(${PROJECT_NAME}
PRIVATE
# where the library itself will look for its internal headers
${CMAKE_CURRENT_SOURCE_DIR}/src
PUBLIC
# where top-level project will look for the library's public headers
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include/Containers>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include/Containers/Stack>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include/Containers/List>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include/Containers/SList>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include/Containers/DList>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include/Containers/CList>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include/Vector>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include/Utilities>
# where external projects will look for the library's public headers
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
)
set_target_properties(${PROJECT_NAME} PROPERTIES LINKER_LANGUAGE CXX)
if (BUILD_TESTS)
add_executable(tests tests/test_defaults.cpp)
target_include_directories(tests PRIVATE ${CMAKE_SOURCE_DIR})
target_link_libraries(tests gtest_main ${PROJECT_NAME})
gtest_discover_tests(tests)
endif ()
# totally optional listing of include directories
get_property(inclds
TARGET ${PROJECT_NAME}
PROPERTY INCLUDE_DIRECTORIES
)
message(STATUS "Listing include directories for ${PROJECT_NAME}...")
# "dumb" listing with "raw" generator expressions on configuration
foreach (pth ${inclds})
message(STATUS " ${pth}")
endforeach ()
# actually evaluated generator expressions printed to file on generation
string(JOIN "\n" includeDirectories ${inclds})
file(GENERATE
OUTPUT "${CMAKE_BINARY_DIR}/include-directories.txt"
CONTENT ${includeDirectories}
)
# without it public headers won't get installed
set(public_headers
include/Containers/Stack/Stack.hpp
include/Utilities/Exception.hpp
include/Utilities/Allocator.hpp
include/Utilities/Memory.hpp
include/Utilities/Algorithm.hpp
include/Containers/List/List.hpp
include/Containers/List/ListIterator.hpp
include/Containers/List/ListNode.hpp
include/Containers/SList/ListExceptions.hpp
include/Containers/SList/SList.hpp
include/Containers/SList/SListIterator.hpp
include/Containers/SList/SListNode.hpp
include/Containers/SList/SListExceptions.hpp
include/Containers/DList/DList.hpp
include/Containers/DList/DListIterator.hpp
include/Containers/DList/DListNode.hpp
include/Containers/DList/DListExceptions.hpp
include/Containers/CList/CList.hpp
include/Containers/CList/CListIterator.hpp
include/Containers/CList/CListNode.hpp
include/Containers/CList/CListExceptions.hpp
include/Containers/Vector/VectorBase.hpp
include/Containers/Vector/VectorExceptions.hpp
include/Containers/Vector/Vector.hpp
include/Containers/Vector/VectorIterator.hpp
)
# not for MSVC
if (CMAKE_COMPILER_IS_GNUCXX)
# compile options for this target only
# treat warnings as errors
target_compile_options(${PROJECT_NAME} PRIVATE -Werror)
endif ()
# where to find our CMake modules
set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
#message(STATUS "CMake module path: ${CMAKE_MODULE_PATH}")
include(Installing)