|
| 1 | +cmake_minimum_required(VERSION 3.9.2) |
| 2 | + |
| 3 | +# set project name |
| 4 | +project(cwalk |
| 5 | + VERSION 1.2.5 |
| 6 | + DESCRIPTION "A simple path library" |
| 7 | + LANGUAGES C) |
| 8 | + |
| 9 | +# include utilities |
| 10 | +list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake") |
| 11 | +include(EnableWarnings) |
| 12 | +include(CTest) |
| 13 | +include(CreateTestList) |
| 14 | +include(CMakePackageConfigHelpers) |
| 15 | + |
| 16 | +# configure requirements |
| 17 | +set(CMAKE_C_STANDARD 11) |
| 18 | + |
| 19 | +# setup target and directory names |
| 20 | +set(INCLUDE_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/include") |
| 21 | +set(SOURCE_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/src") |
| 22 | +set(TEST_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/test") |
| 23 | + |
| 24 | +# enable coverage if requested |
| 25 | +if(ENABLE_COVERAGE) |
| 26 | + message("-- Coverage enabled") |
| 27 | + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fprofile-arcs -ftest-coverage") |
| 28 | + set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} --coverage") |
| 29 | +endif() |
| 30 | + |
| 31 | +# enable sanitizer |
| 32 | +if(ENABLE_SANITIZER) |
| 33 | + message("-- Sanitizer enabled") |
| 34 | + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fno-omit-frame-pointer -fsanitize=${ENABLE_SANITIZER}") |
| 35 | + set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fno-omit-frame-pointer -fsanitize=${ENABLE_SANITIZER}") |
| 36 | +endif() |
| 37 | + |
| 38 | +# add the main executable |
| 39 | +add_library(cwalk |
| 40 | + "${INCLUDE_DIRECTORY}/cwalk.h" |
| 41 | + "${SOURCE_DIRECTORY}/cwalk.c") |
| 42 | +enable_warnings(cwalk) |
| 43 | +target_include_directories(cwalk PUBLIC |
| 44 | + $<BUILD_INTERFACE:${INCLUDE_DIRECTORY}> |
| 45 | + $<INSTALL_INTERFACE:include> |
| 46 | +) |
| 47 | +set_target_properties(cwalk PROPERTIES PUBLIC_HEADER "${INCLUDE_DIRECTORY}/cwalk.h") |
| 48 | +set_target_properties(cwalk PROPERTIES DEFINE_SYMBOL CWK_EXPORTS) |
| 49 | + |
| 50 | +# add shared library macro |
| 51 | +if(BUILD_SHARED_LIBS) |
| 52 | + target_compile_definitions(cwalk PUBLIC CWK_SHARED) |
| 53 | +endif() |
| 54 | + |
| 55 | +# enable tests |
| 56 | +if(ENABLE_TESTS) |
| 57 | + message("-- Tests enabled") |
| 58 | + enable_testing() |
| 59 | + |
| 60 | + create_test_list(DEFAULT cwalktest) |
| 61 | + create_test(DEFAULT absolute simple) |
| 62 | + create_test(DEFAULT absolute absolute_path) |
| 63 | + create_test(DEFAULT absolute unix_relative_base) |
| 64 | + create_test(DEFAULT absolute windows_relative_base) |
| 65 | + create_test(DEFAULT absolute mixed) |
| 66 | + create_test(DEFAULT absolute normalization) |
| 67 | + create_test(DEFAULT absolute too_far) |
| 68 | + create_test(DEFAULT absolute check) |
| 69 | + create_test(DEFAULT absolute buffer_reuse) |
| 70 | + create_test(DEFAULT basename simple) |
| 71 | + create_test(DEFAULT basename empty) |
| 72 | + create_test(DEFAULT basename trailing_separator) |
| 73 | + create_test(DEFAULT basename trailing_separators) |
| 74 | + create_test(DEFAULT basename no_separators) |
| 75 | + create_test(DEFAULT basename special_directories) |
| 76 | + create_test(DEFAULT basename root) |
| 77 | + create_test(DEFAULT basename windows) |
| 78 | + create_test(DEFAULT basename change_simple) |
| 79 | + create_test(DEFAULT basename change_empty_path) |
| 80 | + create_test(DEFAULT basename change_only_root) |
| 81 | + create_test(DEFAULT basename change_empty_basename) |
| 82 | + create_test(DEFAULT basename change_relative) |
| 83 | + create_test(DEFAULT basename change_trim) |
| 84 | + create_test(DEFAULT basename change_trim_only_root) |
| 85 | + create_test(DEFAULT dirname simple) |
| 86 | + create_test(DEFAULT dirname empty) |
| 87 | + create_test(DEFAULT dirname trailing_separator) |
| 88 | + create_test(DEFAULT dirname trailing_separators) |
| 89 | + create_test(DEFAULT dirname no_separators) |
| 90 | + create_test(DEFAULT dirname special_directories) |
| 91 | + create_test(DEFAULT dirname root) |
| 92 | + create_test(DEFAULT dirname three_segments) |
| 93 | + create_test(DEFAULT dirname relative) |
| 94 | + create_test(DEFAULT extension get_simple) |
| 95 | + create_test(DEFAULT extension get_without) |
| 96 | + create_test(DEFAULT extension get_first) |
| 97 | + create_test(DEFAULT extension get_last) |
| 98 | + create_test(DEFAULT extension get_multiple) |
| 99 | + create_test(DEFAULT extension check_simple) |
| 100 | + create_test(DEFAULT extension check_empty) |
| 101 | + create_test(DEFAULT extension check_without) |
| 102 | + create_test(DEFAULT extension change_simple) |
| 103 | + create_test(DEFAULT extension change_no_basename) |
| 104 | + create_test(DEFAULT extension change_no_extension) |
| 105 | + create_test(DEFAULT extension change_with_dot) |
| 106 | + create_test(DEFAULT extension change_overlap) |
| 107 | + create_test(DEFAULT extension change_overlap_long) |
| 108 | + create_test(DEFAULT extension change_hidden_file) |
| 109 | + create_test(DEFAULT extension change_with_trailing_slash) |
| 110 | + create_test(DEFAULT guess empty_string) |
| 111 | + create_test(DEFAULT guess windows_root) |
| 112 | + create_test(DEFAULT guess unix_root) |
| 113 | + create_test(DEFAULT guess windows_separator) |
| 114 | + create_test(DEFAULT guess unix_separator) |
| 115 | + create_test(DEFAULT guess hidden_file) |
| 116 | + create_test(DEFAULT guess extension) |
| 117 | + create_test(DEFAULT guess unguessable) |
| 118 | + create_test(DEFAULT intersection simple) |
| 119 | + create_test(DEFAULT intersection trailing_separator) |
| 120 | + create_test(DEFAULT intersection double_separator) |
| 121 | + create_test(DEFAULT intersection empty) |
| 122 | + create_test(DEFAULT intersection unequal_roots) |
| 123 | + create_test(DEFAULT intersection relative_absolute_mix) |
| 124 | + create_test(DEFAULT intersection same_roots) |
| 125 | + create_test(DEFAULT intersection one_root_only) |
| 126 | + create_test(DEFAULT intersection relative_base) |
| 127 | + create_test(DEFAULT intersection relative_other) |
| 128 | + create_test(DEFAULT intersection skipped_end) |
| 129 | + create_test(DEFAULT is_absolute absolute) |
| 130 | + create_test(DEFAULT is_absolute unc) |
| 131 | + create_test(DEFAULT is_absolute device_unc) |
| 132 | + create_test(DEFAULT is_absolute device_dot) |
| 133 | + create_test(DEFAULT is_absolute device_question_mark) |
| 134 | + create_test(DEFAULT is_absolute relative) |
| 135 | + create_test(DEFAULT is_absolute windows_backslash) |
| 136 | + create_test(DEFAULT is_absolute windows_slash) |
| 137 | + create_test(DEFAULT is_absolute unix_backslash) |
| 138 | + create_test(DEFAULT is_absolute unix_drive) |
| 139 | + create_test(DEFAULT is_absolute absolute_drive) |
| 140 | + create_test(DEFAULT is_absolute relative_drive) |
| 141 | + create_test(DEFAULT is_absolute relative_windows) |
| 142 | + create_test(DEFAULT is_relative absolute) |
| 143 | + create_test(DEFAULT is_relative unc) |
| 144 | + create_test(DEFAULT is_relative device_unc) |
| 145 | + create_test(DEFAULT is_relative device_dot) |
| 146 | + create_test(DEFAULT is_relative device_question_mark) |
| 147 | + create_test(DEFAULT is_relative relative) |
| 148 | + create_test(DEFAULT is_relative windows_backslash) |
| 149 | + create_test(DEFAULT is_relative windows_slash) |
| 150 | + create_test(DEFAULT is_relative unix_backslash) |
| 151 | + create_test(DEFAULT is_relative unix_drive) |
| 152 | + create_test(DEFAULT is_relative absolute_drive) |
| 153 | + create_test(DEFAULT is_relative relative_drive) |
| 154 | + create_test(DEFAULT is_relative relative_windows) |
| 155 | + create_test(DEFAULT join simple) |
| 156 | + create_test(DEFAULT join navigate_back) |
| 157 | + create_test(DEFAULT join empty) |
| 158 | + create_test(DEFAULT join two_absolute) |
| 159 | + create_test(DEFAULT join two_unc) |
| 160 | + create_test(DEFAULT join with_two_roots) |
| 161 | + create_test(DEFAULT join back_after_root) |
| 162 | + create_test(DEFAULT join relative_back_after_root) |
| 163 | + create_test(DEFAULT join multiple) |
| 164 | + create_test(DEFAULT normalize do_nothing) |
| 165 | + create_test(DEFAULT normalize navigate_back) |
| 166 | + create_test(DEFAULT normalize relative_too_far) |
| 167 | + create_test(DEFAULT normalize absolute_too_far) |
| 168 | + create_test(DEFAULT normalize terminated) |
| 169 | + create_test(DEFAULT normalize double_separator) |
| 170 | + create_test(DEFAULT normalize remove_current) |
| 171 | + create_test(DEFAULT normalize mixed) |
| 172 | + create_test(DEFAULT normalize overlap) |
| 173 | + create_test(DEFAULT normalize empty) |
| 174 | + create_test(DEFAULT normalize only_separators) |
| 175 | + create_test(DEFAULT normalize back_after_root) |
| 176 | + create_test(DEFAULT relative simple) |
| 177 | + create_test(DEFAULT relative relative) |
| 178 | + create_test(DEFAULT relative long_base) |
| 179 | + create_test(DEFAULT relative long_target) |
| 180 | + create_test(DEFAULT relative equal) |
| 181 | + create_test(DEFAULT relative base_skipped_end) |
| 182 | + create_test(DEFAULT relative target_skipped_end) |
| 183 | + create_test(DEFAULT relative base_div_skipped_end) |
| 184 | + create_test(DEFAULT relative target_div_skipped_end) |
| 185 | + create_test(DEFAULT relative skip_all) |
| 186 | + create_test(DEFAULT relative different_roots) |
| 187 | + create_test(DEFAULT relative relative_and_absolute) |
| 188 | + create_test(DEFAULT relative check) |
| 189 | + create_test(DEFAULT relative root_path_unix) |
| 190 | + create_test(DEFAULT relative root_path_windows) |
| 191 | + create_test(DEFAULT root absolute) |
| 192 | + create_test(DEFAULT root unc) |
| 193 | + create_test(DEFAULT root device_unc) |
| 194 | + create_test(DEFAULT root device_dot) |
| 195 | + create_test(DEFAULT root device_question_mark) |
| 196 | + create_test(DEFAULT root relative) |
| 197 | + create_test(DEFAULT root windows_backslash) |
| 198 | + create_test(DEFAULT root windows_slash) |
| 199 | + create_test(DEFAULT root unix_backslash) |
| 200 | + create_test(DEFAULT root unix_drive) |
| 201 | + create_test(DEFAULT root absolute_drive) |
| 202 | + create_test(DEFAULT root relative_drive) |
| 203 | + create_test(DEFAULT root relative_windows) |
| 204 | + create_test(DEFAULT root change_simple) |
| 205 | + create_test(DEFAULT root change_empty) |
| 206 | + create_test(DEFAULT root change_separators) |
| 207 | + create_test(DEFAULT root change_overlapping) |
| 208 | + create_test(DEFAULT root change_without_root) |
| 209 | + create_test(DEFAULT segment first) |
| 210 | + create_test(DEFAULT segment last) |
| 211 | + create_test(DEFAULT segment next) |
| 212 | + create_test(DEFAULT segment next_too_far) |
| 213 | + create_test(DEFAULT segment previous_absolute) |
| 214 | + create_test(DEFAULT segment previous_relative) |
| 215 | + create_test(DEFAULT segment previous_absolute_one_char_first) |
| 216 | + create_test(DEFAULT segment previous_relative_one_char_first) |
| 217 | + create_test(DEFAULT segment previous_too_far) |
| 218 | + create_test(DEFAULT segment previous_too_far_root) |
| 219 | + create_test(DEFAULT segment type) |
| 220 | + create_test(DEFAULT segment back_with_root) |
| 221 | + create_test(DEFAULT segment change_simple) |
| 222 | + create_test(DEFAULT segment change_first) |
| 223 | + create_test(DEFAULT segment change_last) |
| 224 | + create_test(DEFAULT segment change_trim) |
| 225 | + create_test(DEFAULT segment change_empty) |
| 226 | + create_test(DEFAULT segment change_with_separator) |
| 227 | + create_test(DEFAULT segment change_overlap) |
| 228 | + create_test(DEFAULT windows change_style) |
| 229 | + create_test(DEFAULT windows get_root) |
| 230 | + create_test(DEFAULT windows get_unc_root) |
| 231 | + create_test(DEFAULT windows get_root_separator) |
| 232 | + create_test(DEFAULT windows get_root_relative) |
| 233 | + create_test(DEFAULT windows intersection_case) |
| 234 | + create_test(DEFAULT windows root_backslash) |
| 235 | + create_test(DEFAULT windows root_empty) |
| 236 | + write_test_file(DEFAULT "${TEST_DIRECTORY}/tests.h") |
| 237 | + |
| 238 | + add_executable(cwalktest |
| 239 | + "${TEST_DIRECTORY}/main.c" |
| 240 | + "${TEST_DIRECTORY}/absolute_test.c" |
| 241 | + "${TEST_DIRECTORY}/basename_test.c" |
| 242 | + "${TEST_DIRECTORY}/dirname_test.c" |
| 243 | + "${TEST_DIRECTORY}/extension_test.c" |
| 244 | + "${TEST_DIRECTORY}/guess_test.c" |
| 245 | + "${TEST_DIRECTORY}/intersection_test.c" |
| 246 | + "${TEST_DIRECTORY}/is_absolute_test.c" |
| 247 | + "${TEST_DIRECTORY}/is_relative_test.c" |
| 248 | + "${TEST_DIRECTORY}/join_test.c" |
| 249 | + "${TEST_DIRECTORY}/normalize_test.c" |
| 250 | + "${TEST_DIRECTORY}/relative_test.c" |
| 251 | + "${TEST_DIRECTORY}/root_test.c" |
| 252 | + "${TEST_DIRECTORY}/segment_test.c" |
| 253 | + "${TEST_DIRECTORY}/windows_test.c") |
| 254 | + enable_warnings(cwalktest) |
| 255 | + |
| 256 | + target_link_libraries(cwalktest PRIVATE cwalk) |
| 257 | +endif() |
| 258 | + |
| 259 | +write_basic_package_version_file("CwalkConfigVersion.cmake" |
| 260 | + VERSION ${cwalk_VERSION} |
| 261 | + COMPATIBILITY SameMajorVersion) |
| 262 | + |
| 263 | +install(TARGETS cwalk |
| 264 | + EXPORT CwalkTargets |
| 265 | + RUNTIME DESTINATION bin |
| 266 | + LIBRARY DESTINATION lib |
| 267 | + ARCHIVE DESTINATION lib |
| 268 | + PUBLIC_HEADER DESTINATION include) |
| 269 | + |
| 270 | +install(FILES |
| 271 | + "${CMAKE_CURRENT_SOURCE_DIR}/cmake/CwalkConfig.cmake" |
| 272 | + DESTINATION lib/cmake/cwalk) |
| 273 | + |
| 274 | +install(EXPORT CwalkTargets |
| 275 | + FILE CwalkTargets.cmake |
| 276 | + DESTINATION lib/cmake/cwalk) |
0 commit comments