1
1
cmake_minimum_required (VERSION 3.14 FATAL_ERROR )
2
2
3
3
# ---- Project ----
4
-
5
4
# Note: update this to your new project's name and version
6
5
project (
7
- Glob
8
- VERSION 1.0
9
- LANGUAGES CXX
6
+ Glob
7
+ VERSION 1.0
8
+ LANGUAGES CXX
10
9
)
11
10
12
11
# ---- Options ----
13
12
option (GLOB_USE_GHC_FILESYSTEM "Use ghc::filesystem instead of std::filesystem" OFF )
14
13
15
14
# ---- Include guards ----
16
15
17
- if (PROJECT_SOURCE_DIR STREQUAL PROJECT_BINARY_DIR )
18
- message (
19
- FATAL_ERROR
20
- "In-source builds not allowed. Please make a new directory (called a build directory) and run CMake from there."
21
- )
22
- endif ()
16
+ if (PROJECT_SOURCE_DIR STREQUAL PROJECT_BINARY_DIR )
17
+ message (
18
+ FATAL_ERROR
19
+ "In-source builds not allowed. Please make a new directory (called a build directory) and run CMake from there."
20
+ )
21
+ endif ()
23
22
24
23
# ---- Add dependencies via CPM ----
25
24
# see https://github.com/TheLartians/CPM.cmake for more info
@@ -28,10 +27,20 @@ include(cmake/CPM.cmake)
28
27
29
28
# PackageProject.cmake will be used to make our target installable
30
29
CPMAddPackage (
31
- NAME PackageProject.cmake
32
- GITHUB_REPOSITORY TheLartians/PackageProject.cmake
33
- VERSION 1.3
30
+ NAME PackageProject.cmake
31
+ GITHUB_REPOSITORY TheLartians/PackageProject.cmake
32
+ VERSION 1.3
33
+ )
34
+
35
+ CPMAddPackage (
36
+ NAME googletest
37
+ GITHUB_REPOSITORY google/googletest
38
+ GIT_TAG v1.16.0
39
+ VERSION 1.16.0
40
+ OPTIONS "INSTALL_GTEST OFF" "gtest_force_shared_crt"
34
41
)
42
+ # For Windows: Prevent overriding the parent project's compiler/linker settings
43
+ set (gtest_force_shared_crt ON CACHE BOOL "" FORCE )
35
44
36
45
# ---- Add source files ----
37
46
@@ -47,23 +56,23 @@ file(GLOB_RECURSE sources CONFIGURE_DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/source/
47
56
# INTERFACE_COMPILE_FEATURES cxx_std_17)
48
57
49
58
add_library (Glob ${headers} ${sources} )
50
- SET_TARGET_PROPERTIES (Glob PROPERTIES OUTPUT_NAME glob )
59
+ set_target_properties (Glob PROPERTIES OUTPUT_NAME glob )
51
60
set_target_properties (Glob PROPERTIES CXX_STANDARD 17 )
52
61
53
- if ( GLOB_USE_GHC_FILESYSTEM )
54
- # Switch to ghc::filesystem.
55
- target_link_libraries (Glob PRIVATE ghcFilesystem::ghc_filesystem )
56
- target_compile_definitions (Glob PUBLIC GLOB_USE_GHC_FILESYSTEM )
57
- endif ()
62
+ if (GLOB_USE_GHC_FILESYSTEM )
63
+ # Switch to ghc::filesystem.
64
+ target_link_libraries (Glob PRIVATE ghcFilesystem::ghc_filesystem )
65
+ target_compile_definitions (Glob PUBLIC GLOB_USE_GHC_FILESYSTEM )
66
+ endif ()
58
67
59
68
# being a cross-platform target, we enforce standards conformance on MSVC
60
69
target_compile_options (Glob PUBLIC "$<$<BOOL:${MSVC} >:/permissive->" )
61
70
62
71
# Link dependencies (if required) target_link_libraries(Glob PUBLIC cxxopts)
63
72
64
73
target_include_directories (
65
- Glob PUBLIC $< BUILD_INTERFACE:${PROJECT_SOURCE_DIR} /include>
66
- $< INSTALL_INTERFACE:include/${PROJECT_NAME} -${PROJECT_VERSION} >
74
+ Glob PUBLIC $< BUILD_INTERFACE:${PROJECT_SOURCE_DIR} /include>
75
+ $< INSTALL_INTERFACE:include/${PROJECT_NAME} -${PROJECT_VERSION} >
67
76
)
68
77
69
78
# ---- Create an installable target ----
@@ -74,11 +83,26 @@ target_include_directories(
74
83
string (TOLOWER ${PROJECT_NAME} /version.h VERSION_HEADER_LOCATION )
75
84
76
85
packageProject (
77
- NAME ${PROJECT_NAME}
78
- VERSION ${PROJECT_VERSION}
79
- BINARY_DIR ${PROJECT_BINARY_DIR}
80
- INCLUDE_DIR ${PROJECT_SOURCE_DIR} /include
81
- INCLUDE_DESTINATION include /${PROJECT_NAME}-${PROJECT_VERSION}
82
- VERSION_HEADER "${VERSION_HEADER_LOCATION} "
83
- DEPENDENCIES ""
86
+ NAME ${PROJECT_NAME}
87
+ VERSION ${PROJECT_VERSION}
88
+ BINARY_DIR ${PROJECT_BINARY_DIR}
89
+ INCLUDE_DIR ${PROJECT_SOURCE_DIR} /include
90
+ INCLUDE_DESTINATION include /${PROJECT_NAME}-${PROJECT_VERSION}
91
+ VERSION_HEADER "${VERSION_HEADER_LOCATION} "
92
+ DEPENDENCIES ""
84
93
)
94
+
95
+ # --- setup tests ---
96
+ enable_testing ()
97
+
98
+ add_executable (glob_tests test /rglob_test.cpp )
99
+ set_property (TARGET glob_tests PROPERTY CXX_STANDARD 17 )
100
+ target_link_libraries (glob_tests PRIVATE gtest_main ${PROJECT_NAME} )
101
+ add_test (NAME glob_tests COMMAND glob_tests )
102
+
103
+ add_executable (glob_tests_single test /rglob_test.cpp )
104
+ set_property (TARGET glob_tests_single PROPERTY CXX_STANDARD 17 )
105
+ target_compile_definitions (glob_tests_single PRIVATE USE_SINGLE_HEADER=1 )
106
+ target_link_libraries (glob_tests_single PRIVATE gtest_main )
107
+ target_include_directories (glob_tests_single PRIVATE single_include )
108
+ add_test (NAME glob_tests_single COMMAND glob_tests_single )
0 commit comments