-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
179 lines (148 loc) · 4.91 KB
/
Copy pathCMakeLists.txt
File metadata and controls
179 lines (148 loc) · 4.91 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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
# ====================================================================
# Rix - FS Module
# ====================================================================
# Purpose:
# Build configuration for the fs module.
#
# This module provides filesystem utilities for Rix:
# - path helpers
# - file exists/size helpers
# - directory helpers
# - small file ops helpers
#
# Design:
# - Header-only by default (INTERFACE library)
# - If any .cpp files exist under src/, we switch to a STATIC lib
#
# Targets:
# - rix_fs : The actual library target (STATIC or INTERFACE)
# - rix::fs : Namespaced alias for consumers
#
# Installation:
# - Installs headers under <prefix>/include/rix/...
# - Contributes to the umbrella export-set `RixTargets`
# ====================================================================
cmake_minimum_required(VERSION 3.20)
project(rix_fs VERSION 0.1.0 LANGUAGES CXX)
include(GNUInstallDirs)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
file(GLOB_RECURSE RIX_FS_SOURCES CONFIGURE_DEPENDS
"${CMAKE_CURRENT_SOURCE_DIR}/src/*.cpp"
)
option(RIX_FS_ENABLE_SANITIZERS "Enable address/UB sanitizers for fs" OFF)
option(RIX_FS_BUILD_TESTS "Build fs tests" ON)
option(RIX_FS_BUILD_EXAMPLES "Build fs examples" ON)
function(rix_fs_apply_warnings tgt scope)
if (NOT TARGET ${tgt})
return()
endif()
if (MSVC)
target_compile_options(${tgt} ${scope} /W4 /permissive-)
else()
target_compile_options(${tgt} ${scope} -Wall -Wextra -Wshadow -Wpedantic)
endif()
endfunction()
function(rix_fs_apply_sanitizers tgt scope)
if (NOT RIX_FS_ENABLE_SANITIZERS OR NOT TARGET ${tgt})
return()
endif()
if (MSVC)
message(WARNING "[fs] Sanitizers are not enabled on MSVC in this module.")
return()
endif()
target_compile_options(${tgt} ${scope}
-O1 -g -fno-omit-frame-pointer -fsanitize=address,undefined
)
target_link_options(${tgt} ${scope}
-fsanitize=address,undefined
)
endfunction()
if (RIX_FS_SOURCES)
message(STATUS "[fs] Building STATIC library (sources found).")
add_library(rix_fs STATIC ${RIX_FS_SOURCES})
add_library(rix::fs ALIAS rix_fs)
target_compile_features(rix_fs PUBLIC cxx_std_20)
target_include_directories(rix_fs
PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
)
rix_fs_apply_warnings(rix_fs PUBLIC)
rix_fs_apply_sanitizers(rix_fs PRIVATE)
set_target_properties(rix_fs PROPERTIES
OUTPUT_NAME rix_fs
VERSION ${PROJECT_VERSION}
SOVERSION 0
EXPORT_NAME fs
)
install(TARGETS rix_fs
EXPORT RixTargets
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
)
else()
message(STATUS "[fs] Building HEADER-ONLY library (no sources).")
add_library(rix_fs INTERFACE)
add_library(rix::fs ALIAS rix_fs)
target_compile_features(rix_fs INTERFACE cxx_std_20)
target_include_directories(rix_fs INTERFACE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
)
rix_fs_apply_warnings(rix_fs INTERFACE)
rix_fs_apply_sanitizers(rix_fs INTERFACE)
install(TARGETS rix_fs
EXPORT RixTargets
INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
)
endif()
install(
DIRECTORY include/
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
FILES_MATCHING PATTERN "*.hpp" PATTERN "*.h"
)
if (RIX_FS_BUILD_TESTS)
enable_testing()
add_executable(rix_fs_tests
${CMAKE_CURRENT_SOURCE_DIR}/tests/test_basic.cpp
)
target_link_libraries(rix_fs_tests PRIVATE rix_fs)
rix_fs_apply_warnings(rix_fs_tests PRIVATE)
rix_fs_apply_sanitizers(rix_fs_tests PRIVATE)
add_test(NAME rix_fs_tests COMMAND rix_fs_tests)
endif()
if (RIX_FS_BUILD_EXAMPLES)
function(rix_fs_add_example exe_name src_file)
add_executable(${exe_name} ${src_file})
target_link_libraries(${exe_name} PRIVATE rix_fs)
rix_fs_apply_warnings(${exe_name} PRIVATE)
rix_fs_apply_sanitizers(${exe_name} PRIVATE)
endfunction()
# Keep this list small at first; add more as the module grows.
set(RIX_FS_EXAMPLES
exists_and_size
read_text
write_text
list_dir
)
foreach(ex ${RIX_FS_EXAMPLES})
rix_fs_add_example(rix_fs_${ex}
${CMAKE_CURRENT_SOURCE_DIR}/examples/${ex}.cpp
)
endforeach()
endif()
message(STATUS "------------------------------------------------------")
message(STATUS "rix::fs configured (${PROJECT_VERSION})")
if (RIX_FS_SOURCES)
message(STATUS "Mode: STATIC / sources found")
else()
message(STATUS "Mode: HEADER-ONLY / no sources")
endif()
message(STATUS "Sanitizers enabled: ${RIX_FS_ENABLE_SANITIZERS}")
message(STATUS "Build type: ${CMAKE_BUILD_TYPE}")
message(STATUS "Binary dir: ${CMAKE_BINARY_DIR}")
message(STATUS "------------------------------------------------------")