Commit faea921e4004af91763b8fde905de3baf24d3945
Committed by
GitHub
1 parent
c7aff0ee
chore: cmake reorganization (#768)
update conan and azure-pipelines to fix gcc 4.8 issue make the CLI11 target sources only for newer CMake Change the cmake to use subdirectory and move the library generation and warnings to separate files.
Showing
8 changed files
with
167 additions
and
132 deletions
.ci/azure-build.yml
CMakeLists.txt
| ... | ... | @@ -27,6 +27,8 @@ project( |
| 27 | 27 | LANGUAGES CXX |
| 28 | 28 | VERSION ${VERSION_STRING}) |
| 29 | 29 | |
| 30 | +list(APPEND CMAKE_MODULE_PATH "${CLI11_SOURCE_DIR}/cmake") | |
| 31 | + | |
| 30 | 32 | # Print the version number of CMake if this is the main project |
| 31 | 33 | if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME) |
| 32 | 34 | message(STATUS "CMake ${CMAKE_VERSION}") |
| ... | ... | @@ -128,89 +130,9 @@ if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME) |
| 128 | 130 | set_property(GLOBAL PROPERTY USE_FOLDERS ON) |
| 129 | 131 | endif() |
| 130 | 132 | |
| 131 | -# Special target that adds warnings. Is not exported. | |
| 132 | -add_library(CLI11_warnings INTERFACE) | |
| 133 | - | |
| 134 | -set(unix-warnings -Wall -Wextra -pedantic -Wshadow -Wsign-conversion -Wswitch-enum) | |
| 135 | - | |
| 136 | -# Clang warnings | |
| 137 | -# -Wfloat-equal could be added with Catch::literals and _a usage | |
| 138 | -if(CMAKE_CXX_COMPILER_ID MATCHES "Clang") | |
| 139 | - list( | |
| 140 | - APPEND | |
| 141 | - unix-warnings | |
| 142 | - -Wcast-align | |
| 143 | - -Wimplicit-atomic-properties | |
| 144 | - -Wmissing-declarations | |
| 145 | - -Woverlength-strings | |
| 146 | - -Wshadow | |
| 147 | - -Wstrict-selector-match | |
| 148 | - -Wundeclared-selector) | |
| 149 | - # -Wunreachable-code Doesn't work on Clang 3.4 | |
| 150 | -endif() | |
| 151 | - | |
| 152 | -# Buggy in GCC 4.8 | |
| 153 | -if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.9) | |
| 154 | - list(APPEND unix-warnings -Weffc++) | |
| 155 | -endif() | |
| 156 | - | |
| 157 | -target_compile_options( | |
| 158 | - CLI11_warnings | |
| 159 | - INTERFACE $<$<BOOL:${CLI11_FORCE_LIBCXX}>:-stdlib=libc++> | |
| 160 | - $<$<CXX_COMPILER_ID:MSVC>:/W4 | |
| 161 | - $<$<BOOL:${CLI11_WARNINGS_AS_ERRORS}>:/WX>> | |
| 162 | - $<$<NOT:$<CXX_COMPILER_ID:MSVC>>:${unix-warnings} | |
| 163 | - $<$<BOOL:${CLI11_WARNINGS_AS_ERRORS}>:-Werror>>) | |
| 164 | - | |
| 165 | -if(NOT CMAKE_VERSION VERSION_LESS 3.13) | |
| 166 | - target_link_options(CLI11_warnings INTERFACE $<$<BOOL:${CLI11_FORCE_LIBCXX}>:-stdlib=libc++>) | |
| 167 | -endif() | |
| 168 | - | |
| 169 | -# To see in IDE, headers must be listed for target | |
| 170 | -set(MAYBE_CONFIGURE_DEPENDS "") | |
| 171 | -if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME AND NOT CMAKE_VERSION VERSION_LESS 3.12) | |
| 172 | - list(INSERT MAYBE_CONFIGURE_DEPENDS 0 CONFIGURE_DEPENDS) | |
| 173 | -endif() | |
| 174 | - | |
| 175 | -file(GLOB CLI11_headers ${MAYBE_CONFIGURE_DEPENDS} "${PROJECT_SOURCE_DIR}/include/CLI/*.hpp") | |
| 176 | -file(GLOB CLI11_impl_headers ${MAYBE_CONFIGURE_DEPENDS} | |
| 177 | - "${PROJECT_SOURCE_DIR}/include/CLI/impl/*.hpp") | |
| 133 | +include(CLI11Warnings) | |
| 178 | 134 | |
| 179 | -if(CLI11_PRECOMPILED) | |
| 180 | - # Create static lib | |
| 181 | - file(GLOB CLI11_precompile_sources "${PROJECT_SOURCE_DIR}/src/*.cpp") | |
| 182 | - add_library(CLI11 STATIC ${CLI11_headers} ${CLI11_impl_headers} ${CLI11_precompile_sources}) | |
| 183 | - target_compile_definitions(CLI11 PUBLIC -DCLI11_COMPILE) | |
| 184 | - | |
| 185 | - set(PUBLIC_OR_INTERFACE PUBLIC) | |
| 186 | -else() | |
| 187 | - add_library(CLI11 INTERFACE) | |
| 188 | - set(PUBLIC_OR_INTERFACE INTERFACE) | |
| 189 | -endif() | |
| 190 | - | |
| 191 | -# Allow IDE's to group targets into folders | |
| 192 | -add_library(CLI11::CLI11 ALIAS CLI11) # for add_subdirectory calls | |
| 193 | - | |
| 194 | -# Duplicated because CMake adds the current source dir if you don't. | |
| 195 | -target_include_directories( | |
| 196 | - CLI11 ${PUBLIC_OR_INTERFACE} $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include> | |
| 197 | - $<INSTALL_INTERFACE:include>) | |
| 198 | - | |
| 199 | -if(CMAKE_VERSION VERSION_LESS 3.8) | |
| 200 | - # This might not be a complete list | |
| 201 | - target_compile_features( | |
| 202 | - CLI11 | |
| 203 | - INTERFACE cxx_lambdas | |
| 204 | - cxx_nullptr | |
| 205 | - cxx_override | |
| 206 | - cxx_range_for | |
| 207 | - cxx_right_angle_brackets | |
| 208 | - cxx_strong_enums | |
| 209 | - cxx_constexpr | |
| 210 | - cxx_auto_type) | |
| 211 | -else() | |
| 212 | - target_compile_features(CLI11 INTERFACE cxx_std_11) | |
| 213 | -endif() | |
| 135 | +add_subdirectory(src) | |
| 214 | 136 | |
| 215 | 137 | # Allow tests to be run on CUDA |
| 216 | 138 | if(CLI11_CUDA_TESTS) |
| ... | ... | @@ -222,13 +144,6 @@ endif() |
| 222 | 144 | |
| 223 | 145 | # This folder should be installed |
| 224 | 146 | if(CLI11_INSTALL) |
| 225 | - install(FILES ${CLI11_headers} DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/CLI") | |
| 226 | - if(NOT CLI11_COMPILE) | |
| 227 | - install(FILES ${CLI11_impl_headers} DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/CLI/impl") | |
| 228 | - endif() | |
| 229 | - | |
| 230 | - # Make an export target | |
| 231 | - install(TARGETS CLI11 EXPORT CLI11Targets) | |
| 232 | 147 | |
| 233 | 148 | # Use find_package on the installed package |
| 234 | 149 | # Since we have no custom code, we can directly write this |
| ... | ... | @@ -261,42 +176,6 @@ if(CLI11_INSTALL) |
| 261 | 176 | export(PACKAGE CLI11) |
| 262 | 177 | endif() |
| 263 | 178 | |
| 264 | -if(CLI11_SINGLE_FILE) | |
| 265 | - # Single file test | |
| 266 | - if(CMAKE_VERSION VERSION_LESS 3.12) | |
| 267 | - find_package(PythonInterp REQUIRED) | |
| 268 | - add_executable(Python::Interpreter IMPORTED) | |
| 269 | - set_target_properties(Python::Interpreter PROPERTIES IMPORTED_LOCATION "${PYTHON_EXECUTABLE}" | |
| 270 | - VERSION "${PYTHON_VERSION_STRING}") | |
| 271 | - else() | |
| 272 | - find_package( | |
| 273 | - Python | |
| 274 | - COMPONENTS Interpreter | |
| 275 | - REQUIRED) | |
| 276 | - endif() | |
| 277 | - | |
| 278 | - file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/include") | |
| 279 | - add_custom_command( | |
| 280 | - OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/include/CLI11.hpp" | |
| 281 | - COMMAND | |
| 282 | - Python::Interpreter "${CMAKE_CURRENT_SOURCE_DIR}/scripts/MakeSingleHeader.py" | |
| 283 | - ${CLI11_headers} ${CLI11_impl_headers} --main "${CMAKE_CURRENT_SOURCE_DIR}/CLI11.hpp.in" | |
| 284 | - --output "${CMAKE_CURRENT_BINARY_DIR}/include/CLI11.hpp" --version "${CLI11_VERSION}" | |
| 285 | - DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/include/CLI/CLI.hpp" ${CLI11_headers} | |
| 286 | - ${CLI11_impl_headers}) | |
| 287 | - add_custom_target(CLI11-generate-single-file ALL | |
| 288 | - DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/include/CLI11.hpp") | |
| 289 | - set_property(TARGET CLI11-generate-single-file PROPERTY FOLDER "Scripts") | |
| 290 | - install(FILES "${CMAKE_CURRENT_BINARY_DIR}/include/CLI11.hpp" DESTINATION include) | |
| 291 | - add_library(CLI11_SINGLE INTERFACE) | |
| 292 | - target_link_libraries(CLI11_SINGLE INTERFACE CLI11) | |
| 293 | - add_dependencies(CLI11_SINGLE CLI11-generate-single-file) | |
| 294 | - target_compile_definitions(CLI11_SINGLE INTERFACE -DCLI11_SINGLE_FILE) | |
| 295 | - target_include_directories( | |
| 296 | - CLI11_SINGLE INTERFACE $<BUILD_INTERFACE:${PROJECT_BINARY_DIR}/include/> | |
| 297 | - $<INSTALL_INTERFACE:include>) | |
| 298 | -endif() | |
| 299 | - | |
| 300 | 179 | if(CLI11_BUILD_TESTS) |
| 301 | 180 | include(CTest) |
| 302 | 181 | add_subdirectory(tests) | ... | ... |
azure-pipelines.yml
cmake/CLI11Warnings.cmake
0 โ 100644
| 1 | +# Special target that adds warnings. Is not exported. | |
| 2 | +add_library(CLI11_warnings INTERFACE) | |
| 3 | + | |
| 4 | +set(unix-warnings -Wall -Wextra -pedantic -Wshadow -Wsign-conversion -Wswitch-enum) | |
| 5 | + | |
| 6 | +# Clang warnings | |
| 7 | +# -Wfloat-equal could be added with Catch::literals and _a usage | |
| 8 | +if(CMAKE_CXX_COMPILER_ID MATCHES "Clang") | |
| 9 | + list( | |
| 10 | + APPEND | |
| 11 | + unix-warnings | |
| 12 | + -Wcast-align | |
| 13 | + -Wimplicit-atomic-properties | |
| 14 | + -Wmissing-declarations | |
| 15 | + -Woverlength-strings | |
| 16 | + -Wshadow | |
| 17 | + -Wstrict-selector-match | |
| 18 | + -Wundeclared-selector) | |
| 19 | + # -Wunreachable-code Doesn't work on Clang 3.4 | |
| 20 | +endif() | |
| 21 | + | |
| 22 | +# Buggy in GCC 4.8 | |
| 23 | +if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.9) | |
| 24 | + list(APPEND unix-warnings -Weffc++) | |
| 25 | +endif() | |
| 26 | + | |
| 27 | +target_compile_options( | |
| 28 | + CLI11_warnings | |
| 29 | + INTERFACE $<$<BOOL:${CLI11_FORCE_LIBCXX}>:-stdlib=libc++> | |
| 30 | + $<$<CXX_COMPILER_ID:MSVC>:/W4 | |
| 31 | + $<$<BOOL:${CLI11_WARNINGS_AS_ERRORS}>:/WX>> | |
| 32 | + $<$<NOT:$<CXX_COMPILER_ID:MSVC>>:${unix-warnings} | |
| 33 | + $<$<BOOL:${CLI11_WARNINGS_AS_ERRORS}>:-Werror>>) | |
| 34 | + | |
| 35 | +if(NOT CMAKE_VERSION VERSION_LESS 3.13) | |
| 36 | + target_link_options(CLI11_warnings INTERFACE $<$<BOOL:${CLI11_FORCE_LIBCXX}>:-stdlib=libc++>) | |
| 37 | +endif() | ... | ... |
conanfile.py
examples/CMakeLists.txt
src/CMakeLists.txt
0 โ 100644
| 1 | +set(CLI11_headerLoc "${PROJECT_SOURCE_DIR}/include/CLI") | |
| 2 | + | |
| 3 | +set(CLI11_headers | |
| 4 | + ${CLI11_headerLoc}/App.hpp | |
| 5 | + ${CLI11_headerLoc}/CLI.hpp | |
| 6 | + ${CLI11_headerLoc}/Config.hpp | |
| 7 | + ${CLI11_headerLoc}/ConfigFwd.hpp | |
| 8 | + ${CLI11_headerLoc}/Error.hpp | |
| 9 | + ${CLI11_headerLoc}/Formatter.hpp | |
| 10 | + ${CLI11_headerLoc}/FormatterFwd.hpp | |
| 11 | + ${CLI11_headerLoc}/Macros.hpp | |
| 12 | + ${CLI11_headerLoc}/Option.hpp | |
| 13 | + ${CLI11_headerLoc}/Split.hpp | |
| 14 | + ${CLI11_headerLoc}/StringTools.hpp | |
| 15 | + ${CLI11_headerLoc}/Timer.hpp | |
| 16 | + ${CLI11_headerLoc}/TypeTools.hpp | |
| 17 | + ${CLI11_headerLoc}/Validators.hpp | |
| 18 | + ${CLI11_headerLoc}/Version.hpp) | |
| 19 | + | |
| 20 | +set(CLI11_implLoc "${PROJECT_SOURCE_DIR}/include/CLI/impl") | |
| 21 | + | |
| 22 | +set(CLI11_impl_headers | |
| 23 | + ${CLI11_implLoc}/App_inl.hpp | |
| 24 | + ${CLI11_implLoc}/Config_inl.hpp | |
| 25 | + ${CLI11_implLoc}/Formatter_inl.hpp | |
| 26 | + ${CLI11_implLoc}/Option_inl.hpp | |
| 27 | + ${CLI11_implLoc}/Split_inl.hpp | |
| 28 | + ${CLI11_implLoc}/StringTools_inl.hpp | |
| 29 | + ${CLI11_implLoc}/Validators_inl.hpp) | |
| 30 | + | |
| 31 | +if(CLI11_PRECOMPILED) | |
| 32 | + # Create static lib | |
| 33 | + file(GLOB CLI11_precompile_sources "${PROJECT_SOURCE_DIR}/src/*.cpp") | |
| 34 | + add_library(CLI11 STATIC ${CLI11_headers} ${CLI11_impl_headers} ${CLI11_precompile_sources}) | |
| 35 | + target_compile_definitions(CLI11 PUBLIC -DCLI11_COMPILE) | |
| 36 | + | |
| 37 | + set(PUBLIC_OR_INTERFACE PUBLIC) | |
| 38 | +else() | |
| 39 | + add_library(CLI11 INTERFACE) | |
| 40 | + if(CMAKE_VERSION VERSION_GREATER 3.19) | |
| 41 | + # This is only useful for visual studio and other IDE builds | |
| 42 | + target_sources(CLI11 PRIVATE ${CLI11_headers} ${CLI11_impl_headers}) | |
| 43 | + endif() | |
| 44 | + | |
| 45 | + set(PUBLIC_OR_INTERFACE INTERFACE) | |
| 46 | +endif() | |
| 47 | + | |
| 48 | +# Allow IDE's to group targets into folders | |
| 49 | +add_library(CLI11::CLI11 ALIAS CLI11) # for add_subdirectory calls | |
| 50 | + | |
| 51 | +# Duplicated because CMake adds the current source dir if you don't. | |
| 52 | +target_include_directories( | |
| 53 | + CLI11 ${PUBLIC_OR_INTERFACE} $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include> | |
| 54 | + $<INSTALL_INTERFACE:include>) | |
| 55 | + | |
| 56 | +if(CMAKE_VERSION VERSION_LESS 3.8) | |
| 57 | + # This might not be a complete list | |
| 58 | + target_compile_features( | |
| 59 | + CLI11 | |
| 60 | + INTERFACE cxx_lambdas | |
| 61 | + cxx_nullptr | |
| 62 | + cxx_override | |
| 63 | + cxx_range_for | |
| 64 | + cxx_right_angle_brackets | |
| 65 | + cxx_strong_enums | |
| 66 | + cxx_constexpr | |
| 67 | + cxx_auto_type) | |
| 68 | +else() | |
| 69 | + target_compile_features(CLI11 INTERFACE cxx_std_11) | |
| 70 | +endif() | |
| 71 | + | |
| 72 | +if(CLI11_SINGLE_FILE) | |
| 73 | + # Single file test | |
| 74 | + if(CMAKE_VERSION VERSION_LESS 3.12) | |
| 75 | + find_package(PythonInterp REQUIRED) | |
| 76 | + add_executable(Python::Interpreter IMPORTED) | |
| 77 | + set_target_properties(Python::Interpreter PROPERTIES IMPORTED_LOCATION "${PYTHON_EXECUTABLE}" | |
| 78 | + VERSION "${PYTHON_VERSION_STRING}") | |
| 79 | + else() | |
| 80 | + find_package( | |
| 81 | + Python | |
| 82 | + COMPONENTS Interpreter | |
| 83 | + REQUIRED) | |
| 84 | + endif() | |
| 85 | + | |
| 86 | + file(MAKE_DIRECTORY "${PROJECT_BINARY_DIR}/include") | |
| 87 | + add_custom_command( | |
| 88 | + OUTPUT "${PROJECT_BINARY_DIR}/include/CLI11.hpp" | |
| 89 | + COMMAND | |
| 90 | + Python::Interpreter "${PROJECT_SOURCE_DIR}/scripts/MakeSingleHeader.py" ${CLI11_headers} | |
| 91 | + ${CLI11_impl_headers} --main "${PROJECT_SOURCE_DIR}/CLI11.hpp.in" --output | |
| 92 | + "${PROJECT_BINARY_DIR}/include/CLI11.hpp" --version "${CLI11_VERSION}" | |
| 93 | + DEPENDS "${PROJECT_SOURCE_DIR}/include/CLI/CLI.hpp" ${CLI11_headers} ${CLI11_impl_headers}) | |
| 94 | + add_custom_target(CLI11-generate-single-file ALL | |
| 95 | + DEPENDS "${PROJECT_BINARY_DIR}/include/CLI11.hpp") | |
| 96 | + set_property(TARGET CLI11-generate-single-file PROPERTY FOLDER "Scripts") | |
| 97 | + if(CLI11_INSTALL) | |
| 98 | + install(FILES "${PROJECT_BINARY_DIR}/include/CLI11.hpp" | |
| 99 | + DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}) | |
| 100 | + endif() | |
| 101 | + add_library(CLI11_SINGLE INTERFACE) | |
| 102 | + target_link_libraries(CLI11_SINGLE INTERFACE CLI11) | |
| 103 | + add_dependencies(CLI11_SINGLE CLI11-generate-single-file) | |
| 104 | + target_compile_definitions(CLI11_SINGLE INTERFACE -DCLI11_SINGLE_FILE) | |
| 105 | + target_include_directories( | |
| 106 | + CLI11_SINGLE INTERFACE $<BUILD_INTERFACE:${PROJECT_BINARY_DIR}/include/> | |
| 107 | + $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>) | |
| 108 | +endif() | |
| 109 | + | |
| 110 | +if(CLI11_INSTALL) | |
| 111 | + | |
| 112 | + # Make an export target | |
| 113 | + install(TARGETS CLI11 EXPORT CLI11Targets) | |
| 114 | + if(NOT CLI11_SINGLE_FILE) | |
| 115 | + install(FILES ${CLI11_headers} DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/CLI") | |
| 116 | + if(NOT CLI11_COMPILE) | |
| 117 | + install(FILES ${CLI11_impl_headers} DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/CLI/impl") | |
| 118 | + endif() | |
| 119 | + endif() | |
| 120 | +endif() | ... | ... |
tests/CMakeLists.txt
| 1 | -list(APPEND CMAKE_MODULE_PATH "${CLI11_SOURCE_DIR}/cmake") | |
| 2 | - | |
| 3 | 1 | if(CLI11_SANITIZERS) |
| 4 | 2 | message(STATUS "Using arsenm/sanitizers-cmake") |
| 5 | 3 | FetchContent_Declare( |
| ... | ... | @@ -109,7 +107,7 @@ foreach(T IN LISTS CLI11_TESTS) |
| 109 | 107 | if(CLI11_CUDA_TESTS) |
| 110 | 108 | set_property(SOURCE ${T}.cpp PROPERTY LANGUAGE CUDA) |
| 111 | 109 | endif() |
| 112 | - add_executable(${T} ${T}.cpp ${CLI11_headers}) | |
| 110 | + add_executable(${T} ${T}.cpp) | |
| 113 | 111 | add_sanitizers(${T}) |
| 114 | 112 | if(NOT CLI11_CUDA_TESTS) |
| 115 | 113 | target_link_libraries(${T} PRIVATE CLI11_warnings) |
| ... | ... | @@ -126,7 +124,7 @@ foreach(T IN LISTS CLI11_TESTS) |
| 126 | 124 | endforeach() |
| 127 | 125 | |
| 128 | 126 | foreach(T IN LISTS CLI11_MULTIONLY_TESTS) |
| 129 | - add_executable(${T} ${T}.cpp ${CLI11_headers}) | |
| 127 | + add_executable(${T} ${T}.cpp) | |
| 130 | 128 | add_sanitizers(${T}) |
| 131 | 129 | target_link_libraries(${T} PUBLIC CLI11) |
| 132 | 130 | add_catch_test(${T}) | ... | ... |