Commit 60e2932356f049ba0313559c3d512bb1bc8e2b72
Committed by
Henry Schreiner
1 parent
c356ec87
CMake updates from @slurps-mad-rips
Showing
10 changed files
with
267 additions
and
209 deletions
.ci/azure-build.yml
| @@ -2,7 +2,7 @@ steps: | @@ -2,7 +2,7 @@ steps: | ||
| 2 | 2 | ||
| 3 | - task: CMake@1 | 3 | - task: CMake@1 |
| 4 | inputs: | 4 | inputs: |
| 5 | - cmakeArgs: .. -DCLI11_WARNINGS_AS_ERRORS=ON -DCLI11_SINGLE_FILE=$(cli11.single) -DCLI11_CXX_STD=$(cli11.std) -DCLI11_SINGLE_FILE_TESTS=$(cli11.single) -DCMAKE_BUILD_TYPE=$(cli11.build_type) $(cli11.options) | 5 | + cmakeArgs: .. -DCLI11_WARNINGS_AS_ERRORS=ON -DCLI11_SINGLE_FILE=$(cli11.single) -DCMAKE_CXX_STANDARD=$(cli11.std) -DCLI11_SINGLE_FILE_TESTS=$(cli11.single) -DCMAKE_BUILD_TYPE=$(cli11.build_type) $(cli11.options) |
| 6 | displayName: 'Configure' | 6 | displayName: 'Configure' |
| 7 | 7 | ||
| 8 | - script: cmake --build . | 8 | - script: cmake --build . |
.ci/make_and_test.sh
| @@ -8,7 +8,7 @@ set -evx | @@ -8,7 +8,7 @@ set -evx | ||
| 8 | 8 | ||
| 9 | mkdir -p build | 9 | mkdir -p build |
| 10 | cd build | 10 | cd build |
| 11 | -cmake .. -DCLI11_WARNINGS_AS_ERRORS=ON -DCLI11_SINGLE_FILE=ON -DCLI11_CXX_STD=$STD -DCLI11_SINGLE_FILE_TESTS=ON -DCMAKE_BUILD_TYPE=Debug -DCMAKE_CXX_COMPILER_LAUNCHER=ccache $@ | 11 | +cmake .. -DCLI11_WARNINGS_AS_ERRORS=ON -DCLI11_SINGLE_FILE=ON -DCMAKE_CXX_STANDARD=$STD -DCLI11_SINGLE_FILE_TESTS=ON -DCMAKE_BUILD_TYPE=Debug -DCMAKE_CXX_COMPILER_LAUNCHER=ccache $@ |
| 12 | cmake --build . -- -j2 | 12 | cmake --build . -- -j2 |
| 13 | 13 | ||
| 14 | set +evx | 14 | set +evx |
.gitmodules
| 1 | [submodule "extern/googletest"] | 1 | [submodule "extern/googletest"] |
| 2 | path = extern/googletest | 2 | path = extern/googletest |
| 3 | url = ../../google/googletest.git | 3 | url = ../../google/googletest.git |
| 4 | -[submodule "extern/sanitizers"] | ||
| 5 | - path = extern/sanitizers | ||
| 6 | - url = ../../arsenm/sanitizers-cmake | ||
| 7 | -[submodule "extern/json"] | ||
| 8 | - path = extern/json | ||
| 9 | - url = ../../nlohmann/json.git |
CMakeLists.txt
| @@ -24,120 +24,168 @@ string(REGEX REPLACE ${VERSION_REGEX} "\\1" VERSION_STRING "${VERSION_STRING}") | @@ -24,120 +24,168 @@ string(REGEX REPLACE ${VERSION_REGEX} "\\1" VERSION_STRING "${VERSION_STRING}") | ||
| 24 | # Add the project | 24 | # Add the project |
| 25 | project(CLI11 LANGUAGES CXX VERSION ${VERSION_STRING}) | 25 | project(CLI11 LANGUAGES CXX VERSION ${VERSION_STRING}) |
| 26 | 26 | ||
| 27 | -# Special target that adds warnings. Is not exported. | ||
| 28 | -add_library(CLI11_warnings INTERFACE) | ||
| 29 | - | ||
| 30 | -# Only if built as the main project | 27 | +# Print the version number of CMake if this is the main project |
| 31 | if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME) | 28 | if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME) |
| 32 | - # User settable | ||
| 33 | - set(CLI11_CXX_STD "11" CACHE STRING "The CMake standard to require") | ||
| 34 | - | ||
| 35 | - # Special override for Clang on Linux (useful with an old stdlibc++ and a newer clang) | ||
| 36 | - if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang") | ||
| 37 | - option(CLI11_FORCE_LIBCXX "Force Clang to use libc++ instead of libstdc++ (Linux only)" OFF) | ||
| 38 | - if(CLI11_FORCE_LIBCXX) | ||
| 39 | - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++") | ||
| 40 | - set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -stdlib=libc++") | ||
| 41 | - endif() | ||
| 42 | - endif() | 29 | + message(STATUS "CMake ${CMAKE_VERSION}") |
| 30 | +endif() | ||
| 43 | 31 | ||
| 44 | - set(CUR_PROJ ON) | ||
| 45 | - set(CMAKE_CXX_STANDARD ${CLI11_CXX_STD}) | ||
| 46 | - set(CMAKE_CXX_EXTENSIONS OFF) | ||
| 47 | - set(CMAKE_CXX_STANDARD_REQUIRED ON) | 32 | +include(CMakeDependentOption) |
| 33 | +include(GNUInstallDirs) | ||
| 34 | +include(CTest) | ||
| 48 | 35 | ||
| 49 | - option(CLI11_CUDA_TESTS "Build the tests with NVCC to check for warnings there - requires CMake 3.9+") | ||
| 50 | - if(CLI11_CUDA_TESTS) | ||
| 51 | - enable_language(CUDA) | 36 | +if(NOT CMAKE_VERSION VERSION_LESS 3.11) |
| 37 | + include(FetchContent) | ||
| 38 | +endif() | ||
| 52 | 39 | ||
| 53 | - # Print out warning and error numbers | ||
| 54 | - set(CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} -Xcudafe --display_error_number") | ||
| 55 | - endif() | 40 | +find_package(Doxygen) |
| 56 | 41 | ||
| 57 | - option(CLI11_WARNINGS_AS_ERRORS "Turn all warnings into errors (for CI)") | 42 | +list(APPEND force-libcxx "CMAKE_CXX_COMPILER_ID STREQUAL \"Clang\"") |
| 43 | +list(APPEND force-libcxx "CMAKE_SYSTEM_NAME STREQUAL \"Linux\"") | ||
| 44 | +list(APPEND force-libcxx "CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME") | ||
| 58 | 45 | ||
| 59 | - # Be moderately paranoid with flags | ||
| 60 | - if(MSVC) | ||
| 61 | - target_compile_options(CLI11_warnings INTERFACE "/W4") | ||
| 62 | - if(CLI11_WARNINGS_AS_ERRORS) | ||
| 63 | - target_compile_options(CLI11_warnings INTERFACE "/WX") | ||
| 64 | - endif() | ||
| 65 | - else() | ||
| 66 | - target_compile_options(CLI11_warnings INTERFACE -Wall -Wextra -pedantic -Wshadow -Wsign-conversion -Wswitch-enum) | ||
| 67 | - if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU") | ||
| 68 | - if(NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.9) | ||
| 69 | - # GCC 4.8 has a false positive | ||
| 70 | - # Other compilers ignore this flag | ||
| 71 | - target_compile_options(CLI11_warnings INTERFACE -Weffc++) | ||
| 72 | - endif() | ||
| 73 | - endif() | ||
| 74 | - if(CLI11_WARNINGS_AS_ERRORS) | ||
| 75 | - target_compile_options(CLI11_warnings INTERFACE -Werror) | ||
| 76 | - endif() | ||
| 77 | - endif() | 46 | +list(APPEND build-docs "CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME") |
| 47 | +list(APPEND build-docs "NOT CMAKE_VERSION VERSION_LESS 3.11") | ||
| 48 | +list(APPEND build-docs "Doxygen_FOUND") | ||
| 49 | +list(APPEND build-docs "EXISTS docs") | ||
| 78 | 50 | ||
| 79 | - if(NOT CMAKE_VERSION VERSION_LESS 3.6) | ||
| 80 | - option(CLI11_CLANG_TIDY "Look for and use Clang-Tidy") | ||
| 81 | - set(CLI11_CLANG_TIDY_OPTIONS "" CACHE STRING "Clang tidy option, such as -fix") | ||
| 82 | - if(CLI11_CLANG_TIDY) | 51 | +option(CLI11_WARNINGS_AS_ERRORS "Turn all warnings into errors (for CI)") |
| 52 | +option(CLI11_SINGLE_FILE "Generate a single header file") | ||
| 53 | +cmake_dependent_option(CLI11_SANITIZERS | ||
| 54 | + "Download the sanatizers CMake config" OFF | ||
| 55 | + "NOT CMAKE_VERSION VERSION_LESS 3.11" OFF) | ||
| 83 | 56 | ||
| 84 | - find_program( | ||
| 85 | - CLANG_TIDY_EXE | ||
| 86 | - NAMES "clang-tidy" | ||
| 87 | - DOC "Path to clang-tidy executable" | ||
| 88 | - REQUIRED | ||
| 89 | - ) | 57 | +cmake_dependent_option(CLI11_BUILD_DOCS |
| 58 | + "Build CLI11 documentation" ON | ||
| 59 | + "${build-docs}" OFF) | ||
| 90 | 60 | ||
| 91 | - set(DO_CLANG_TIDY "${CLANG_TIDY_EXE}" ${CLI11_CLANG_TIDY_OPTIONS}) | ||
| 92 | - endif() | ||
| 93 | - endif() | 61 | +cmake_dependent_option(CLI11_BUILD_TESTS |
| 62 | + "Build CLI11 tests" ON | ||
| 63 | + "BUILD_TESTING;CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME" OFF) | ||
| 94 | 64 | ||
| 95 | - if (EXISTS book) | ||
| 96 | - add_subdirectory(book) | ||
| 97 | - endif() | 65 | +cmake_dependent_option(CLI11_BUILD_EXAMPLES |
| 66 | + "Build CLI11 examples" ON | ||
| 67 | + "CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME;EXISTS examples" OFF) | ||
| 98 | 68 | ||
| 99 | - if(NOT CMAKE_VERSION VERSION_LESS 3.9) | ||
| 100 | - find_package(Doxygen) | ||
| 101 | - if(Doxygen_FOUND) | ||
| 102 | - add_subdirectory(docs) | ||
| 103 | - else() | ||
| 104 | - message(STATUS "Doxygen not found, not building docs") | ||
| 105 | - endif() | ||
| 106 | - else() | ||
| 107 | - message(STATUS "Newer CMake adds Doxygen support, update CMake for docs") | ||
| 108 | - endif() | ||
| 109 | -else() | ||
| 110 | - set(CUR_PROJ OFF) | 69 | +cmake_dependent_option(CLI11_BUILD_EXAMPLES_JSON |
| 70 | + "Build CLI11 json example" OFF | ||
| 71 | + "CLI11_BUILD_EXAMPLES;NOT CMAKE_VERSION VERSION_LESS 3.11" OFF) | ||
| 72 | + | ||
| 73 | +cmake_dependent_option(CLI11_SINGLE_FILE_TESTS | ||
| 74 | + "Duplicate all the tests for a single file build" OFF | ||
| 75 | + "BUILD_TESTING;CLI11_SINGLE_FILE" OFF) | ||
| 76 | + | ||
| 77 | +cmake_dependent_option(CLI11_INSTALL | ||
| 78 | + "Install the CLI11 folder to include during install process" ON | ||
| 79 | + "CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME" OFF) | ||
| 80 | + | ||
| 81 | +cmake_dependent_option(CLI11_FORCE_LIBCXX | ||
| 82 | + "Force clang to use libc++ instead of libstdc++ (Linux only)" OFF | ||
| 83 | + "${force-libcxx}" OFF) | ||
| 84 | + | ||
| 85 | +cmake_dependent_option(CLI11_CUDA_TESTS | ||
| 86 | + "Build the tests with NVCC to check for warnings there - requires CMake 3.9+" OFF | ||
| 87 | + "CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME" OFF) | ||
| 88 | + | ||
| 89 | +cmake_dependent_option(CLI11_CLANG_TIDY | ||
| 90 | + "Look for and use Clang-Tidy" OFF | ||
| 91 | + "CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME;NOT CMAKE_VERSION VERSION_LESS 3.6" OFF) | ||
| 92 | +set(CLI11_CLANG_TIDY_OPTIONS "" CACHE STRING "Clang tidy options, such as -fix, simicolon separated") | ||
| 93 | + | ||
| 94 | +if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME AND NOT DEFINED CMAKE_CXX_STANDARD) | ||
| 95 | + set(CMAKE_CXX_STANDARD 11) | ||
| 96 | +endif() | ||
| 97 | + | ||
| 98 | +if(NOT DEFINED CMAKE_CXX_EXTENSIONS) | ||
| 99 | + set(CMAKE_CXX_EXTENSIONS OFF) | ||
| 100 | +endif() | ||
| 101 | + | ||
| 102 | +if(NOT DEFINED CMAKE_CXX_STANDARD_REQUIRED) | ||
| 103 | + set(CMAKE_CXX_STANDARD_REQUIRED ON) | ||
| 111 | endif() | 104 | endif() |
| 112 | 105 | ||
| 113 | -# Allow dependent options | ||
| 114 | -include(CMakeDependentOption) | ||
| 115 | 106 | ||
| 116 | # Allow IDE's to group targets into folders | 107 | # Allow IDE's to group targets into folders |
| 117 | -set_property(GLOBAL PROPERTY USE_FOLDERS ON) | 108 | +if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME) |
| 109 | + set_property(GLOBAL PROPERTY USE_FOLDERS ON) | ||
| 110 | +endif() | ||
| 111 | + | ||
| 112 | +if(CMAKE_VERSION VERSION_LESS 3.10) | ||
| 113 | + message(STATUS "CMake 3.10+ adds Doxygen support. Update CMake to build documentation") | ||
| 114 | +elseif(NOT Doxygen_FOUND) | ||
| 115 | + message(STATUS "Doxygen not found, building docs has been disabled") | ||
| 116 | +endif() | ||
| 117 | + | ||
| 118 | +# Special target that adds warnings. Is not exported. | ||
| 119 | +add_library(CLI11_warnings INTERFACE) | ||
| 120 | + | ||
| 121 | +set(unix-warnings -Wall -Wextra -pedantic -Wshadow -Wsign-conversion -Wswitch-enum) | ||
| 118 | 122 | ||
| 119 | -file(GLOB CLI11_headers "${CMAKE_CURRENT_SOURCE_DIR}/include/CLI/*") | ||
| 120 | -# To see in IDE, must be listed for target | 123 | +# Buggy in GCC 4.8 |
| 124 | +if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.9) | ||
| 125 | + list(APPEND unix-warnings -Weffc++) | ||
| 126 | +endif() | ||
| 127 | + | ||
| 128 | +target_compile_options(CLI11_warnings | ||
| 129 | + INTERFACE | ||
| 130 | + $<$<BOOL:${CLI11_FORCE_LIBCXX}>:-stdlib=libc++> | ||
| 131 | + $<$<CXX_COMPILER_ID:MSVC>:/W4 $<$<BOOL:${CLI11_WARNINGS_AS_ERRORS}>:/WX>> | ||
| 132 | + $<$<NOT:$<CXX_COMPILER_ID:MSVC>>:${unix-warnings} $<$<BOOL:${CLI11_WARNINGS_AS_ERRORS}>:-Werror>>) | ||
| 133 | + | ||
| 134 | + | ||
| 135 | + if(NOT CMAKE_VERSION VERSION_LESS 3.13) | ||
| 136 | + target_link_options(CLI11_warnings | ||
| 137 | + INTERFACE | ||
| 138 | + $<$<BOOL:${CLI11_FORCE_LIBCXX}>:-stdlib=libc++>) | ||
| 139 | + endif() | ||
| 121 | 140 | ||
| 141 | + | ||
| 142 | +# Allow IDE's to group targets into folders | ||
| 122 | add_library(CLI11 INTERFACE) | 143 | add_library(CLI11 INTERFACE) |
| 144 | +add_library(CLI11::CLI11 ALIAS CLI11) # for add_subdirectory calls | ||
| 123 | 145 | ||
| 124 | # Duplicated because CMake adds the current source dir if you don't. | 146 | # Duplicated because CMake adds the current source dir if you don't. |
| 125 | target_include_directories(CLI11 INTERFACE | 147 | target_include_directories(CLI11 INTERFACE |
| 126 | $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include> | 148 | $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include> |
| 127 | $<INSTALL_INTERFACE:include>) | 149 | $<INSTALL_INTERFACE:include>) |
| 128 | 150 | ||
| 129 | -# Make add_subdirectory work like find_package | ||
| 130 | -add_library(CLI11::CLI11 ALIAS CLI11) | ||
| 131 | 151 | ||
| 132 | -option(CLI11_INSTALL "Install the CLI11 folder to include during install process" ${CUR_PROJ}) | 152 | +# To see in IDE, headers must be listed for target |
| 153 | +set(header-patterns "${PROJECT_SOURCE_DIR}/include/CLI/*") | ||
| 154 | +if(NOT CMAKE_VERSION VERSION_LESS 3.12) | ||
| 155 | + list(INSERT header-patterns 0 CONFIGURE_DEPENDS) | ||
| 156 | +endif() | ||
| 157 | + | ||
| 158 | +file(GLOB CLI11_headers ${header-patterns}) | ||
| 159 | + | ||
| 160 | +# Allow tests to be run on CUDA | ||
| 161 | + if(CLI11_CUDA_TESTS) | ||
| 162 | + enable_language(CUDA) | ||
| 163 | + | ||
| 164 | + # Print out warning and error numbers | ||
| 165 | + set(CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} -Xcudafe --display_error_number") | ||
| 166 | + endif() | ||
| 167 | + | ||
| 168 | + | ||
| 169 | +# Prepare Clang-Tidy | ||
| 170 | +if(CLI11_CLANG_TIDY) | ||
| 171 | + find_program( | ||
| 172 | + CLANG_TIDY_EXE | ||
| 173 | + NAMES "clang-tidy" | ||
| 174 | + DOC "Path to clang-tidy executable" | ||
| 175 | + REQUIRED | ||
| 176 | + ) | ||
| 177 | + | ||
| 178 | + set(DO_CLANG_TIDY "${CLANG_TIDY_EXE}" ${CLI11_CLANG_TIDY_OPTIONS}) | ||
| 179 | +endif() | ||
| 180 | + | ||
| 133 | 181 | ||
| 134 | # This folder should be installed | 182 | # This folder should be installed |
| 135 | if(CLI11_INSTALL) | 183 | if(CLI11_INSTALL) |
| 136 | - install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/include/CLI DESTINATION include) | 184 | + install(DIRECTORY ${PROJECT_SOURCE_DIR}/include/ |
| 185 | + DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}) | ||
| 137 | 186 | ||
| 138 | - # Make an export target | ||
| 139 | - install(TARGETS CLI11 | ||
| 140 | - EXPORT CLI11Targets) | 187 | + # Make an export target |
| 188 | + install(TARGETS CLI11 EXPORT CLI11Targets) | ||
| 141 | endif() | 189 | endif() |
| 142 | 190 | ||
| 143 | # Use find_package on the installed package | 191 | # Use find_package on the installed package |
| @@ -146,14 +194,13 @@ endif() | @@ -146,14 +194,13 @@ endif() | ||
| 146 | # import Targets.cmake | 194 | # import Targets.cmake |
| 147 | 195 | ||
| 148 | # Add the version in a CMake readable way | 196 | # Add the version in a CMake readable way |
| 149 | -configure_file("${CMAKE_CURRENT_SOURCE_DIR}/cmake/CLI11ConfigVersion.cmake.in" | ||
| 150 | - "${CMAKE_CURRENT_BINARY_DIR}/CLI11ConfigVersion.cmake" @ONLY) | 197 | +configure_file("cmake/CLI11ConfigVersion.cmake.in" |
| 198 | + "CLI11ConfigVersion.cmake" @ONLY) | ||
| 151 | 199 | ||
| 152 | -include(GNUInstallDirs) | ||
| 153 | # These installs only make sense for a local project | 200 | # These installs only make sense for a local project |
| 154 | -if(CUR_PROJ) | 201 | +if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME) |
| 155 | # Make version available in the install | 202 | # Make version available in the install |
| 156 | - install(FILES "${CMAKE_CURRENT_BINARY_DIR}/CLI11ConfigVersion.cmake" | 203 | + install(FILES "${PROJECT_BINARY_DIR}/CLI11ConfigVersion.cmake" |
| 157 | DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/CLI11) | 204 | DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/CLI11) |
| 158 | 205 | ||
| 159 | # Install the export target as a file | 206 | # Install the export target as a file |
| @@ -171,67 +218,64 @@ if(CUR_PROJ) | @@ -171,67 +218,64 @@ if(CUR_PROJ) | ||
| 171 | export(PACKAGE CLI11) | 218 | export(PACKAGE CLI11) |
| 172 | endif() | 219 | endif() |
| 173 | 220 | ||
| 174 | -option(CLI11_SINGLE_FILE "Generate a single header file" OFF) | ||
| 175 | - | ||
| 176 | if(CLI11_SINGLE_FILE) | 221 | if(CLI11_SINGLE_FILE) |
| 177 | -# Single file test | 222 | + # Single file test |
| 178 | if(CMAKE_VERSION VERSION_LESS 3.12) | 223 | if(CMAKE_VERSION VERSION_LESS 3.12) |
| 179 | find_package(PythonInterp REQUIRED) | 224 | find_package(PythonInterp REQUIRED) |
| 180 | - set(Python_VERSION ${PYTHON_VERSION_STRING}) | ||
| 181 | - set(Python_EXECUTABLE "${PYTHON_EXECUTABLE}") | 225 | + add_executable(Python::Interpreter IMPORTED) |
| 226 | + set_target_properties(Python::Interpreter | ||
| 227 | + PROPERTIES | ||
| 228 | + IMPORTED_LOCATION "${PYTHON_EXECUTABLE}" | ||
| 229 | + VERSION "${PYTHON_VERSION_STRING}") | ||
| 182 | else() | 230 | else() |
| 183 | - find_package(Python REQUIRED) | 231 | + find_package(Python COMPONENTS Interpreter REQUIRED) |
| 184 | endif() | 232 | endif() |
| 185 | 233 | ||
| 186 | file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/include") | 234 | file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/include") |
| 187 | add_custom_command(OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/include/CLI11.hpp" | 235 | add_custom_command(OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/include/CLI11.hpp" |
| 188 | - COMMAND "${Python_EXECUTABLE}" "${CMAKE_CURRENT_SOURCE_DIR}/scripts/MakeSingleHeader.py" "${CMAKE_CURRENT_BINARY_DIR}/include/CLI11.hpp" | ||
| 189 | - DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/include/CLI/CLI.hpp" ${CLI11_headers} | ||
| 190 | - ) | ||
| 191 | - add_custom_target(generate_cli_single_file ALL | 236 | + COMMAND Python::Interpreter |
| 237 | + "${CMAKE_CURRENT_SOURCE_DIR}/scripts/MakeSingleHeader.py" | ||
| 238 | + "${CMAKE_CURRENT_BINARY_DIR}/include/CLI11.hpp" | ||
| 239 | + DEPENDS | ||
| 240 | + "${CMAKE_CURRENT_SOURCE_DIR}/include/CLI/CLI.hpp" | ||
| 241 | + ${CLI11_headers}) | ||
| 242 | + add_custom_target(CLI11-generate-single-file ALL | ||
| 192 | DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/include/CLI11.hpp") | 243 | DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/include/CLI11.hpp") |
| 193 | - set_target_properties(generate_cli_single_file | ||
| 194 | - PROPERTIES FOLDER "Scripts") | ||
| 195 | - install(FILES ${CMAKE_CURRENT_BINARY_DIR}/include/CLI11.hpp DESTINATION include) | 244 | + set_property(TARGET CLI11-generate-single-file PROPERTY FOLDER "Scripts") |
| 245 | + install(FILES ${CMAKE_CURRENT_BINARY_DIR}/include/CLI11.hpp | ||
| 246 | + DESTINATION include) | ||
| 196 | add_library(CLI11_SINGLE INTERFACE) | 247 | add_library(CLI11_SINGLE INTERFACE) |
| 197 | target_link_libraries(CLI11_SINGLE INTERFACE CLI11) | 248 | target_link_libraries(CLI11_SINGLE INTERFACE CLI11) |
| 198 | - add_dependencies(CLI11_SINGLE generate_cli_single_file) | 249 | + add_dependencies(CLI11_SINGLE CLI11-generate-single-file) |
| 199 | target_compile_definitions(CLI11_SINGLE INTERFACE -DCLI11_SINGLE_FILE) | 250 | target_compile_definitions(CLI11_SINGLE INTERFACE -DCLI11_SINGLE_FILE) |
| 200 | - target_include_directories(CLI11_SINGLE INTERFACE "${CMAKE_CURRENT_BINARY_DIR}/include/") | 251 | + target_include_directories(CLI11_SINGLE INTERFACE |
| 252 | + $<BUILD_INTERFACE:${PROJECT_BINARY_DIR}/include/> | ||
| 253 | + $<INSTALL_INTERFACE:include>) | ||
| 201 | endif() | 254 | endif() |
| 202 | 255 | ||
| 203 | -cmake_dependent_option(CLI11_SINGLE_FILE_TESTS | ||
| 204 | - "Duplicate all the tests for a single file build" | ||
| 205 | - OFF | ||
| 206 | - "CLI11_SINGLE_FILE" | ||
| 207 | - OFF) | ||
| 208 | 256 | ||
| 257 | +if(CLI11_BUILD_TESTS) | ||
| 258 | + add_subdirectory(tests) | ||
| 259 | +endif() | ||
| 209 | 260 | ||
| 210 | -if(DEFINED CLI11_TESTING) | ||
| 211 | - set(CLI11_TESTING_INTERNAL "${CLI11_TESTING}") | ||
| 212 | -elseif(CUR_PROJ) | ||
| 213 | - option(BUILD_TESTING "Build the tests" ON) | ||
| 214 | - set(CLI11_TESTING_INTERNAL "${BUILD_TESTING}") | ||
| 215 | -else() | ||
| 216 | - set(CLI11_TESTING_INTERNAL OFF) | 261 | +if(CLI11_BUILD_EXAMPLES) |
| 262 | + add_subdirectory(examples) | ||
| 217 | endif() | 263 | endif() |
| 218 | 264 | ||
| 219 | -if(CLI11_TESTING_INTERNAL) | ||
| 220 | - enable_testing() | ||
| 221 | - add_subdirectory(tests) | 265 | +if(CLI11_BUILD_DOCS) |
| 266 | + add_subdirectory(docs) | ||
| 222 | endif() | 267 | endif() |
| 223 | 268 | ||
| 224 | -cmake_dependent_option(CLI11_EXAMPLES "Build the examples" ON "CUR_PROJ" OFF) | ||
| 225 | -if(CLI11_EXAMPLES) | ||
| 226 | - add_subdirectory(examples) | 269 | +# From a build system, this might not be included. |
| 270 | +if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME AND EXISTS book) | ||
| 271 | + add_subdirectory(book) | ||
| 227 | endif() | 272 | endif() |
| 228 | 273 | ||
| 229 | # Packaging support | 274 | # Packaging support |
| 275 | +# Packaging support | ||
| 230 | set(CPACK_PACKAGE_VENDOR "github.com/CLIUtils/CLI11") | 276 | set(CPACK_PACKAGE_VENDOR "github.com/CLIUtils/CLI11") |
| 231 | -set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "Command line interface") | ||
| 232 | -set(CPACK_PACKAGE_VERSION_MAJOR ${CLI11_VERSION_MAJOR}) | ||
| 233 | -set(CPACK_PACKAGE_VERSION_MINOR ${CLI11_VERSION_MINOR}) | ||
| 234 | -set(CPACK_PACKAGE_VERSION_PATCH ${CLI11_VERSION_PATCH}) | 277 | +set(CPACK_PACKAGE_VERSION ${PROJECT_VERSION}) |
| 278 | +set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "Command line parser with simple and intuitive interface") | ||
| 235 | set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/LICENSE") | 279 | set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/LICENSE") |
| 236 | set(CPACK_RESOURCE_FILE_README "${CMAKE_CURRENT_SOURCE_DIR}/README.md") | 280 | set(CPACK_RESOURCE_FILE_README "${CMAKE_CURRENT_SOURCE_DIR}/README.md") |
| 237 | set(CPACK_SOURCE_GENERATOR "TGZ;ZIP") | 281 | set(CPACK_SOURCE_GENERATOR "TGZ;ZIP") |
azure-pipelines.yml
| @@ -10,7 +10,7 @@ variables: | @@ -10,7 +10,7 @@ variables: | ||
| 10 | cli11.single: ON | 10 | cli11.single: ON |
| 11 | cli11.std: 14 | 11 | cli11.std: 14 |
| 12 | cli11.build_type: Debug | 12 | cli11.build_type: Debug |
| 13 | - cli11.options: | 13 | + cli11.options: -DCLI11_EXAMPLES_JSON=ON |
| 14 | CMAKE_BUILD_PARALLEL_LEVEL: 4 | 14 | CMAKE_BUILD_PARALLEL_LEVEL: 4 |
| 15 | 15 | ||
| 16 | jobs: | 16 | jobs: |
| @@ -84,6 +84,7 @@ jobs: | @@ -84,6 +84,7 @@ jobs: | ||
| 84 | gcc4.8: | 84 | gcc4.8: |
| 85 | containerImage: gcc:4.8 | 85 | containerImage: gcc:4.8 |
| 86 | cli11.std: 11 | 86 | cli11.std: 11 |
| 87 | + cli11.options: | ||
| 87 | clang3.4: | 88 | clang3.4: |
| 88 | containerImage: silkeh/clang:3.4 | 89 | containerImage: silkeh/clang:3.4 |
| 89 | cli11.std: 11 | 90 | cli11.std: 11 |
cmake/AddGoogletest.cmake
| @@ -37,6 +37,10 @@ macro(add_gtest TESTNAME) | @@ -37,6 +37,10 @@ macro(add_gtest TESTNAME) | ||
| 37 | else() | 37 | else() |
| 38 | add_test(${TESTNAME} ${TESTNAME}) | 38 | add_test(${TESTNAME} ${TESTNAME}) |
| 39 | set_target_properties(${TESTNAME} PROPERTIES FOLDER "Tests") | 39 | set_target_properties(${TESTNAME} PROPERTIES FOLDER "Tests") |
| 40 | + if (CLI11_FORCE_LIBCXX) | ||
| 41 | + set_property(TARGET ${T} APPEND_STRING | ||
| 42 | + PROPERTY LINK_FLAGS -stdlib=libc++) | ||
| 43 | + endif() | ||
| 40 | endif() | 44 | endif() |
| 41 | 45 | ||
| 42 | endmacro() | 46 | endmacro() |
examples/CMakeLists.txt
| 1 | + | ||
| 1 | function(add_cli_exe T) | 2 | function(add_cli_exe T) |
| 2 | add_executable(${T} ${ARGN} ${CLI11_headers}) | 3 | add_executable(${T} ${ARGN} ${CLI11_headers}) |
| 3 | target_link_libraries(${T} PUBLIC CLI11) | 4 | target_link_libraries(${T} PUBLIC CLI11) |
| 4 | - set_target_properties( | ||
| 5 | - ${T} PROPERTIES | ||
| 6 | - FOLDER "Examples" | ||
| 7 | - ) | ||
| 8 | - | ||
| 9 | - if(CLANG_TIDY_EXE) | ||
| 10 | - set_target_properties( | ||
| 11 | - ${T} PROPERTIES | ||
| 12 | - CXX_CLANG_TIDY "${DO_CLANG_TIDY}" | ||
| 13 | - ) | 5 | + set_property(TARGET ${T} PROPERTY FOLDER "Examples") |
| 6 | + if(CLI11_FORCE_LIBCXX) | ||
| 7 | + set_property(TARGET ${T} APPEND_STRING PROPERTY LINK_FLAGS -stdlib=libc++) | ||
| 8 | + endif() | ||
| 9 | + if(CLI11_CLANG_TIDY) | ||
| 10 | + set_property(TARGET ${T} PROPERTY CXX_CLANG_TIDY "${DO_CLANG_TIDY}") | ||
| 14 | endif() | 11 | endif() |
| 15 | endfunction() | 12 | endfunction() |
| 16 | 13 | ||
| 17 | -option(CLI11_EXAMPLE_JSON OFF) | ||
| 18 | -if(CLI11_EXAMPLE_JSON) | ||
| 19 | - if(NOT EXISTS "${CLI11_SOURCE_DIR}/extern/json/single_include/nlohmann/json.hpp") | ||
| 20 | - message(ERROR "You are missing the json package for CLI11_EXAMPLE_JSON. Please update your submodules (git submodule update --init)") | ||
| 21 | - endif() | ||
| 22 | - if(CMAKE_COMPILER_ID STREQUAL "GNU" AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.8) | ||
| 23 | - message(WARNING "The json example requires GCC 4.8+ (requirement on json library)") | 14 | +if(CLI11_BUILD_EXAMPLES_JSON) |
| 15 | + FetchContent_Declare(json | ||
| 16 | + GIT_REPOSITORY https://github.com/nlohmann/json.git | ||
| 17 | + GIT_SHALLOW 1 | ||
| 18 | + GIT_TAG v3.7.3) | ||
| 19 | + FetchContent_GetProperties(json) | ||
| 20 | + if (NOT json_POPULATED) | ||
| 21 | + FetchContent_Populate(json) | ||
| 24 | endif() | 22 | endif() |
| 23 | + | ||
| 25 | add_cli_exe(json json.cpp) | 24 | add_cli_exe(json json.cpp) |
| 26 | - target_include_directories(json PUBLIC SYSTEM "${CLI11_SOURCE_DIR}/extern/json/single_include") | 25 | + target_include_directories(json PUBLIC SYSTEM "${json_SOURCE_DIR}/single_include") |
| 27 | 26 | ||
| 28 | add_test(NAME json_config_out COMMAND json --item 2) | 27 | add_test(NAME json_config_out COMMAND json --item 2) |
| 29 | set_property(TEST json_config_out PROPERTY PASS_REGULAR_EXPRESSION | 28 | set_property(TEST json_config_out PROPERTY PASS_REGULAR_EXPRESSION |
| 30 | - "{" | ||
| 31 | - "\"item\": \"2\"" | ||
| 32 | - "\"simple\": false" | ||
| 33 | - "}") | 29 | + [[{]] |
| 30 | + [["item": "2"]] | ||
| 31 | + [["simple": false]] | ||
| 32 | + [[}]] | ||
| 33 | + ) | ||
| 34 | 34 | ||
| 35 | file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/input.json" [=[{"item":3,"simple":false}]=]) | 35 | file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/input.json" [=[{"item":3,"simple":false}]=]) |
| 36 | add_test(NAME json_config_in COMMAND json --config "${CMAKE_CURRENT_BINARY_DIR}/input.json") | 36 | add_test(NAME json_config_in COMMAND json --config "${CMAKE_CURRENT_BINARY_DIR}/input.json") |
| 37 | set_property(TEST json_config_in PROPERTY PASS_REGULAR_EXPRESSION | 37 | set_property(TEST json_config_in PROPERTY PASS_REGULAR_EXPRESSION |
| 38 | - "{" | ||
| 39 | - "\"item\": \"3\"" | ||
| 40 | - "\"simple\": false" | ||
| 41 | - "}") | 38 | + [[{]] |
| 39 | + [["item": "3"]] | ||
| 40 | + [["simple": false]] | ||
| 41 | + [[}]] | ||
| 42 | +) | ||
| 42 | endif() | 43 | endif() |
| 43 | 44 | ||
| 45 | + | ||
| 44 | add_cli_exe(simple simple.cpp) | 46 | add_cli_exe(simple simple.cpp) |
| 45 | add_test(NAME simple_basic COMMAND simple) | 47 | add_test(NAME simple_basic COMMAND simple) |
| 46 | add_test(NAME simple_all COMMAND simple -f filename.txt -c 12 --flag --flag -d 1.2) | 48 | add_test(NAME simple_all COMMAND simple -f filename.txt -c 12 --flag --flag -d 1.2) |
extern/json deleted
| 1 | -Subproject commit 1126c9ca74fdea22d2ce3a065ac0fcb5792cbdaf |
extern/sanitizers deleted
| 1 | -Subproject commit 99e159ec9bc8dd362b08d18436bd40ff0648417b |
tests/CMakeLists.txt
| @@ -5,10 +5,20 @@ endif() | @@ -5,10 +5,20 @@ endif() | ||
| 5 | 5 | ||
| 6 | list(APPEND CMAKE_MODULE_PATH "${CLI11_SOURCE_DIR}/cmake") | 6 | list(APPEND CMAKE_MODULE_PATH "${CLI11_SOURCE_DIR}/cmake") |
| 7 | 7 | ||
| 8 | -# If submodule is available, add sanitizers | ||
| 9 | -# Set SANITIZE_ADDRESS, SANITIZE_MEMORY, SANITIZE_THREAD or SANITIZE_UNDEFINED | ||
| 10 | -if(EXISTS "${CLI11_SOURCE_DIR}/extern/sanitizers/cmake/FindSanitizers.cmake") | ||
| 11 | - list(APPEND CMAKE_MODULE_PATH "${CLI11_SOURCE_DIR}/extern/sanitizers/cmake") | 8 | +if(CLI11_SANITIZERS) |
| 9 | + FetchContent_Declare(sanitizers | ||
| 10 | + GIT_REPOSITORY https://github.com/arsenm/sanitizers-cmake.git | ||
| 11 | + GIT_SHALLOW 1 | ||
| 12 | + GIT_TAG 99e159e) | ||
| 13 | + | ||
| 14 | + FetchContent_GetProperties(sanitizers) | ||
| 15 | + | ||
| 16 | + if (NOT sanitizers_POPULATED) | ||
| 17 | + FetchContent_Populate(sanitizers) | ||
| 18 | + endif() | ||
| 19 | + | ||
| 20 | + list(APPEND CMAKE_MODULE_PATH "${sanitizers_SOURCE_DIR}/cmake") | ||
| 21 | + | ||
| 12 | find_package(Sanitizers) | 22 | find_package(Sanitizers) |
| 13 | if(SANITIZE_ADDRESS) | 23 | if(SANITIZE_ADDRESS) |
| 14 | message(STATUS "You might want to use \"${ASan_WRAPPER}\" to run your program") | 24 | message(STATUS "You might want to use \"${ASan_WRAPPER}\" to run your program") |
| @@ -44,61 +54,53 @@ if(WIN32) | @@ -44,61 +54,53 @@ if(WIN32) | ||
| 44 | list(APPEND CLI11_TESTS WindowsTest) | 54 | list(APPEND CLI11_TESTS WindowsTest) |
| 45 | endif() | 55 | endif() |
| 46 | 56 | ||
| 47 | -set(CLI11_MULTIONLY_TESTS | ||
| 48 | - TimerTest | ||
| 49 | - ) | 57 | +set(CLI11_MULTIONLY_TESTS TimerTest) |
| 50 | 58 | ||
| 51 | # Only affects current directory, so safe | 59 | # Only affects current directory, so safe |
| 52 | include_directories(${CMAKE_CURRENT_SOURCE_DIR}) | 60 | include_directories(${CMAKE_CURRENT_SOURCE_DIR}) |
| 53 | 61 | ||
| 54 | -foreach(T ${CLI11_TESTS}) | 62 | +foreach(T IN LISTS CLI11_TESTS) |
| 55 | if(CLI11_CUDA_TESTS) | 63 | if(CLI11_CUDA_TESTS) |
| 56 | set_property( | 64 | set_property( |
| 57 | SOURCE ${T}.cpp | 65 | SOURCE ${T}.cpp |
| 58 | - PROPERTY | ||
| 59 | - LANGUAGE CUDA | ||
| 60 | - ) | 66 | + PROPERTY LANGUAGE CUDA |
| 67 | + ) | ||
| 61 | endif() | 68 | endif() |
| 62 | - | ||
| 63 | add_executable(${T} ${T}.cpp ${CLI11_headers}) | 69 | add_executable(${T} ${T}.cpp ${CLI11_headers}) |
| 64 | add_sanitizers(${T}) | 70 | add_sanitizers(${T}) |
| 65 | - target_link_libraries(${T} PUBLIC CLI11) | ||
| 66 | if(NOT CLI11_CUDA_TESTS) | 71 | if(NOT CLI11_CUDA_TESTS) |
| 67 | - target_link_libraries(${T} PUBLIC CLI11_warnings) | 72 | + target_link_libraries(${T} PRIVATE CLI11_warnings) |
| 68 | endif() | 73 | endif() |
| 74 | + target_link_libraries(${T} PRIVATE CLI11) | ||
| 69 | add_gtest(${T}) | 75 | add_gtest(${T}) |
| 70 | 76 | ||
| 71 | if(CLI11_SINGLE_FILE AND CLI11_SINGLE_FILE_TESTS) | 77 | if(CLI11_SINGLE_FILE AND CLI11_SINGLE_FILE_TESTS) |
| 72 | add_executable(${T}_Single ${T}.cpp) | 78 | add_executable(${T}_Single ${T}.cpp) |
| 73 | - target_link_libraries(${T}_Single PUBLIC CLI11_SINGLE) | 79 | + target_link_libraries(${T}_Single PRIVATE CLI11_SINGLE) |
| 74 | add_gtest(${T}_Single) | 80 | add_gtest(${T}_Single) |
| 75 | - set_target_properties(${T}_Single | ||
| 76 | - PROPERTIES | ||
| 77 | - FOLDER "Tests Single File") | 81 | + set_property(TARGET ${T}_Single PROPERTY FOLDER "Tests Single File") |
| 78 | endif() | 82 | endif() |
| 79 | - | ||
| 80 | endforeach() | 83 | endforeach() |
| 81 | 84 | ||
| 82 | -foreach(T ${CLI11_MULTIONLY_TESTS}) | ||
| 83 | - | 85 | +foreach(T IN LISTS CLI11_MULTIONLY_TESTS) |
| 84 | add_executable(${T} ${T}.cpp ${CLI11_headers}) | 86 | add_executable(${T} ${T}.cpp ${CLI11_headers}) |
| 85 | add_sanitizers(${T}) | 87 | add_sanitizers(${T}) |
| 86 | target_link_libraries(${T} PUBLIC CLI11) | 88 | target_link_libraries(${T} PUBLIC CLI11) |
| 87 | add_gtest(${T}) | 89 | add_gtest(${T}) |
| 88 | - | ||
| 89 | endforeach() | 90 | endforeach() |
| 90 | 91 | ||
| 91 | # Add -Wno-deprecated-declarations to DeprecatedTest | 92 | # Add -Wno-deprecated-declarations to DeprecatedTest |
| 92 | -if(NOT MSVC) | ||
| 93 | - target_compile_options(DeprecatedTest PRIVATE -Wno-deprecated-declarations) | ||
| 94 | - if(TARGET DeprecatedTest_Single) | ||
| 95 | - target_compile_options(DeprecatedTest_Single PRIVATE -Wno-deprecated-declarations) | ||
| 96 | - endif() | ||
| 97 | -else() | ||
| 98 | - target_compile_options(DeprecatedTest PRIVATE "/wd4996") | ||
| 99 | - if(TARGET DeprecatedTest_Single) | ||
| 100 | - target_compile_options(DeprecatedTest_Single PRIVATE "/wd4996") | ||
| 101 | - endif() | 93 | +set(no-deprecated-declarations |
| 94 | + $<$<CXX_COMPILER_ID:MSVC>:/wd4996> | ||
| 95 | + $<$<NOT:$<CXX_COMPILER_ID:MSVC>>:-Wno-deprecated-declarations> | ||
| 96 | + ) | ||
| 97 | +target_compile_options(DeprecatedTest | ||
| 98 | + PRIVATE | ||
| 99 | + ${no-deprecated-declarations}) | ||
| 100 | +if (TARGET DeprecatedTest_Single) | ||
| 101 | + target_compile_options(DeprecatedTest_Single | ||
| 102 | + PRIVATE | ||
| 103 | + ${no-deprecated-declarations}) | ||
| 102 | endif() | 104 | endif() |
| 103 | 105 | ||
| 104 | # Link test (build error if inlines missing) | 106 | # Link test (build error if inlines missing) |
| @@ -108,11 +110,22 @@ set_target_properties(link_test_1 PROPERTIES FOLDER "Tests") | @@ -108,11 +110,22 @@ set_target_properties(link_test_1 PROPERTIES FOLDER "Tests") | ||
| 108 | add_executable(link_test_2 link_test_2.cpp) | 110 | add_executable(link_test_2 link_test_2.cpp) |
| 109 | target_link_libraries(link_test_2 PUBLIC CLI11 link_test_1) | 111 | target_link_libraries(link_test_2 PUBLIC CLI11 link_test_1) |
| 110 | add_gtest(link_test_2) | 112 | add_gtest(link_test_2) |
| 113 | +if(CLI11_FORCE_LIBCXX) | ||
| 114 | + set_property(TARGET link_test_1 APPEND_STRING | ||
| 115 | + PROPERTY LINK_FLAGS -stdlib=libc++) | ||
| 116 | + set_property(TARGET link_test_2 APPEND_STRING | ||
| 117 | + PROPERTY LINK_FLAGS -stdlib=libc++) | ||
| 118 | +endif() | ||
| 111 | 119 | ||
| 112 | # Add informational printout | 120 | # Add informational printout |
| 113 | -# Force this to be in a standard location so CTest can find it | ||
| 114 | add_executable(informational informational.cpp) | 121 | add_executable(informational informational.cpp) |
| 115 | target_link_libraries(informational PUBLIC CLI11) | 122 | target_link_libraries(informational PUBLIC CLI11) |
| 123 | +if(CLI11_FORCE_LIBCXX) | ||
| 124 | + set_property(TARGET informational APPEND_STRING | ||
| 125 | + PROPERTY LINK_FLAGS -stdlib=libc++) | ||
| 126 | +endif() | ||
| 127 | + | ||
| 128 | +# Force this to be in a standard location so CTest can find it | ||
| 116 | set_target_properties(informational PROPERTIES | 129 | set_target_properties(informational PROPERTIES |
| 117 | RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}" | 130 | RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}" |
| 118 | RUNTIME_OUTPUT_DIRECTORY_DEBUG "${CMAKE_BINARY_DIR}" | 131 | RUNTIME_OUTPUT_DIRECTORY_DEBUG "${CMAKE_BINARY_DIR}" |
| @@ -124,21 +137,22 @@ set_target_properties(informational PROPERTIES | @@ -124,21 +137,22 @@ set_target_properties(informational PROPERTIES | ||
| 124 | # Adding this printout to CTest | 137 | # Adding this printout to CTest |
| 125 | file(WRITE "${PROJECT_BINARY_DIR}/CTestCustom.cmake" | 138 | file(WRITE "${PROJECT_BINARY_DIR}/CTestCustom.cmake" |
| 126 | "set(CTEST_CUSTOM_PRE_TEST \"${CMAKE_BINARY_DIR}/informational\")" | 139 | "set(CTEST_CUSTOM_PRE_TEST \"${CMAKE_BINARY_DIR}/informational\")" |
| 127 | - ) | 140 | +) |
| 128 | 141 | ||
| 129 | # Add boost to test boost::optional if available | 142 | # Add boost to test boost::optional if available |
| 130 | find_package(Boost 1.61) | 143 | find_package(Boost 1.61) |
| 131 | -if(Boost_FOUND) | ||
| 132 | - if(TARGET Boost::boost) | ||
| 133 | - target_link_libraries(informational PRIVATE Boost::boost) | ||
| 134 | - target_link_libraries(OptionalTest PRIVATE Boost::boost) | ||
| 135 | - else() | ||
| 136 | - target_include_directories(informational PRIVATE ${Boost_INCLUDE_DIRS}) | ||
| 137 | - target_include_directories(OptionalTest PRIVATE ${Boost_INCLUDE_DIRS}) | ||
| 138 | - endif() | ||
| 139 | 144 | ||
| 140 | - target_compile_definitions(informational PRIVATE CLI11_BOOST_OPTIONAL) | ||
| 141 | - target_compile_definitions(OptionalTest PRIVATE CLI11_BOOST_OPTIONAL) | 145 | +set(boost-optional-def $<$<BOOL:${Boost_FOUND}>:CLI11_BOOST_OPTIONAL>) |
| 146 | + | ||
| 147 | +target_compile_definitions(informational PRIVATE ${boost-optional-def}) | ||
| 148 | +target_compile_definitions(OptionalTest PRIVATE ${boost-optional-def}) | ||
| 149 | + | ||
| 150 | +if(TARGET Boost::boost) | ||
| 151 | + target_link_libraries(informational PRIVATE Boost::boost) | ||
| 152 | + target_link_libraries(OptionalTest PRIVATE Boost::boost) | ||
| 153 | +elseif(BOOST_FOUND) | ||
| 154 | + target_include_directories(informational PRIVATE ${Boost_INCLUDE_DIRS}) | ||
| 155 | + target_include_directories(OptionalTest PRIVATE ${Boost_INCLUDE_DIRS}) | ||
| 142 | endif() | 156 | endif() |
| 143 | 157 | ||
| 144 | if(CMAKE_BUILD_TYPE STREQUAL Coverage) | 158 | if(CMAKE_BUILD_TYPE STREQUAL Coverage) |
| @@ -148,6 +162,7 @@ if(CMAKE_BUILD_TYPE STREQUAL Coverage) | @@ -148,6 +162,7 @@ if(CMAKE_BUILD_TYPE STREQUAL Coverage) | ||
| 148 | EXECUTABLE ctest | 162 | EXECUTABLE ctest |
| 149 | DEPENDENCIES | 163 | DEPENDENCIES |
| 150 | ${CLI11_TESTS} | 164 | ${CLI11_TESTS} |
| 151 | - ${CLI11_MULTIONLY_TESTS}) | 165 | + ${CLI11_MULTIONLY_TESTS} |
| 166 | + ) | ||
| 152 | endif() | 167 | endif() |
| 153 | 168 |