Commit c55726ee29dc41cb4d0b462c988041f536cd6e12

Authored by jpr89
Committed by GitHub
1 parent 2d8e17c4

Cmake Revamp (#270)

* Cmake Revamp

I needed to do a variety of things to ensure cxxopts worked well in my own project.

I created a new cmake module to abstract a lot of the logic in the main CMakelists.txt, I think it really assists in the readability of the project. Consequently a lot of logic is now written in functions.

I made a lot of the project options off by default unless the project is being built standalone. As a frequent consumer of cmake libraries this is a huge issue. Since examples, tests, installation, etc. aren't things I expect/desired by default when using libraries.

Co-authored-by: Juan Ramos <juanr0911@gmail.com>
CMakeLists.txt
1 # Copyright (c) 2014 Jarryd Beck 1 # Copyright (c) 2014 Jarryd Beck
2 -# 2 +#
3 # Permission is hereby granted, free of charge, to any person obtaining a copy 3 # Permission is hereby granted, free of charge, to any person obtaining a copy
4 # of this software and associated documentation files (the "Software"), to deal 4 # of this software and associated documentation files (the "Software"), to deal
5 # in the Software without restriction, including without limitation the rights 5 # in the Software without restriction, including without limitation the rights
6 # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 6 # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7 # copies of the Software, and to permit persons to whom the Software is 7 # copies of the Software, and to permit persons to whom the Software is
8 # furnished to do so, subject to the following conditions: 8 # furnished to do so, subject to the following conditions:
9 -# 9 +#
10 # The above copyright notice and this permission notice shall be included in 10 # The above copyright notice and this permission notice shall be included in
11 # all copies or substantial portions of the Software. 11 # all copies or substantial portions of the Software.
12 -# 12 +#
13 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 13 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 14 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 15 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
@@ -17,96 +17,61 @@ @@ -17,96 +17,61 @@
17 # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 17 # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 18 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19 # THE SOFTWARE. 19 # THE SOFTWARE.
20 -cmake_minimum_required(VERSION 3.1) 20 +cmake_minimum_required(VERSION 3.1...3.19)
21 21
22 -# parse the current version from the cxxopts header  
23 -file(STRINGS "${CMAKE_CURRENT_SOURCE_DIR}/include/cxxopts.hpp" cxxopts_version_defines  
24 - REGEX "#define CXXOPTS__VERSION_(MAJOR|MINOR|PATCH)")  
25 -foreach(ver ${cxxopts_version_defines})  
26 - if(ver MATCHES "#define CXXOPTS__VERSION_(MAJOR|MINOR|PATCH) +([^ ]+)$")  
27 - set(CXXOPTS__VERSION_${CMAKE_MATCH_1} "${CMAKE_MATCH_2}" CACHE INTERNAL "")  
28 - endif()  
29 -endforeach()  
30 -set(VERSION ${CXXOPTS__VERSION_MAJOR}.${CXXOPTS__VERSION_MINOR}.${CXXOPTS__VERSION_PATCH})  
31 -message(STATUS "cxxopts version ${VERSION}") 22 +list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/")
  23 +include(cxxopts)
32 24
33 -project(cxxopts VERSION "${VERSION}" LANGUAGES CXX) 25 +# Get the version of the library
  26 +cxxopts_getversion(VERSION)
34 27
35 -enable_testing() 28 +project(cxxopts
  29 + VERSION "${VERSION}"
  30 + LANGUAGES CXX
  31 +)
36 32
37 -option(CXXOPTS_BUILD_EXAMPLES "Set to ON to build examples" ON)  
38 -option(CXXOPTS_BUILD_TESTS "Set to ON to build tests" ON)  
39 -option(CXXOPTS_ENABLE_INSTALL "Generate the install target" ON)  
40 -option(CXXOPTS_ENABLE_WARNINGS "Add warnings to CMAKE_CXX_FLAGS" ON)  
41 -  
42 -# request c++11 without gnu extension for the whole project and enable more warnings  
43 -if (CXXOPTS_CXX_STANDARD)  
44 - set(CMAKE_CXX_STANDARD ${CXXOPTS_CXX_STANDARD})  
45 -else()  
46 - set(CMAKE_CXX_STANDARD 11) 33 +# Determine whether this is a standalone project or included by other projects
  34 +set(CXXOPTS_STANDALONE_PROJECT OFF)
  35 +if (CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR)
  36 + set(CXXOPTS_STANDALONE_PROJECT ON)
47 endif() 37 endif()
48 38
49 -set(CMAKE_CXX_EXTENSIONS OFF) 39 +# Establish the project options
  40 +option(CXXOPTS_BUILD_EXAMPLES "Set to ON to build examples" ${CXXOPTS_STANDALONE_PROJECT})
  41 +option(CXXOPTS_BUILD_TESTS "Set to ON to build tests" ${CXXOPTS_STANDALONE_PROJECT})
  42 +option(CXXOPTS_ENABLE_INSTALL "Generate the install target" ${CXXOPTS_STANDALONE_PROJECT})
  43 +option(CXXOPTS_ENABLE_WARNINGS "Add warnings to CMAKE_CXX_FLAGS" ${CXXOPTS_STANDALONE_PROJECT})
  44 +option(CXXOPTS_USE_UNICODE_HELP "Use ICU Unicode library" OFF)
50 45
51 -if (CXXOPTS_ENABLE_WARNINGS)  
52 -if(MSVC)  
53 - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W2")  
54 -elseif(CMAKE_CXX_COMPILER_ID MATCHES "[Cc]lang" OR CMAKE_CXX_COMPILER_ID MATCHES "GNU")  
55 - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Werror -Wextra -Wshadow -Weffc++ -Wsign-compare -Wshadow -Wwrite-strings -Wpointer-arith -Winit-self -Wconversion -Wno-sign-conversion -Wsuggest-override") 46 +if (CXXOPTS_STANDALONE_PROJECT)
  47 + cxxopts_set_cxx_standard()
56 endif() 48 endif()
  49 +
  50 +if (CXXOPTS_ENABLE_WARNINGS)
  51 + cxxopts_enable_warnings()
57 endif() 52 endif()
58 53
59 add_library(cxxopts INTERFACE) 54 add_library(cxxopts INTERFACE)
60 add_library(cxxopts::cxxopts ALIAS cxxopts) 55 add_library(cxxopts::cxxopts ALIAS cxxopts)
  56 +add_subdirectory(include)
61 57
62 -# optionally, enable unicode support using the ICU library  
63 -set(CXXOPTS_USE_UNICODE_HELP FALSE CACHE BOOL "Use ICU Unicode library") 58 +# Link against the ICU library when requested
64 if(CXXOPTS_USE_UNICODE_HELP) 59 if(CXXOPTS_USE_UNICODE_HELP)
65 - find_package(PkgConfig)  
66 - pkg_check_modules(ICU REQUIRED icu-uc)  
67 -  
68 - target_link_libraries(cxxopts INTERFACE ${ICU_LDFLAGS})  
69 - target_compile_options(cxxopts INTERFACE ${ICU_CFLAGS})  
70 - target_compile_definitions(cxxopts INTERFACE CXXOPTS_USE_UNICODE) 60 + cxxopts_use_unicode()
71 endif() 61 endif()
72 62
73 -target_include_directories(cxxopts INTERFACE  
74 - $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>  
75 - $<INSTALL_INTERFACE:include>  
76 - )  
77 -  
78 -if(CXXOPTS_ENABLE_INSTALL)  
79 - include(GNUInstallDirs)  
80 - include(CMakePackageConfigHelpers)  
81 - set(CXXOPTS_CMAKE_DIR "${CMAKE_INSTALL_LIBDIR}/cmake/cxxopts" CACHE STRING  
82 - "Installation directory for cmake files, relative to ${CMAKE_INSTALL_PREFIX}.")  
83 - set(version_config "${PROJECT_BINARY_DIR}/cxxopts-config-version.cmake")  
84 - set(project_config "${PROJECT_BINARY_DIR}/cxxopts-config.cmake")  
85 - set(targets_export_name cxxopts-targets)  
86 -  
87 - # Generate the version, config and target files into the build directory.  
88 - write_basic_package_version_file(  
89 - ${version_config}  
90 - VERSION ${VERSION}  
91 - COMPATIBILITY AnyNewerVersion)  
92 - configure_package_config_file(  
93 - ${PROJECT_SOURCE_DIR}/cxxopts-config.cmake.in  
94 - ${project_config}  
95 - INSTALL_DESTINATION ${CXXOPTS_CMAKE_DIR})  
96 - export(TARGETS cxxopts NAMESPACE cxxopts::  
97 - FILE ${PROJECT_BINARY_DIR}/${targets_export_name}.cmake)  
98 -  
99 - # Install version, config and target files.  
100 - install(  
101 - FILES ${project_config} ${version_config}  
102 - DESTINATION ${CXXOPTS_CMAKE_DIR})  
103 - install(EXPORT ${targets_export_name} DESTINATION ${CXXOPTS_CMAKE_DIR}  
104 - NAMESPACE cxxopts::) 63 +# Install cxxopts when requested by the user
  64 +if (CXXOPTS_ENABLE_INSTALL)
  65 + cxxopts_install_logic()
  66 +endif()
105 67
106 - # Install the header file and export the target  
107 - install(TARGETS cxxopts EXPORT ${targets_export_name} DESTINATION ${CMAKE_INSTALL_LIBDIR})  
108 - install(FILES ${PROJECT_SOURCE_DIR}/include/cxxopts.hpp DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}) 68 +# Build examples when requested by the user
  69 +if (CXXOPTS_BUILD_EXAMPLES)
  70 + add_subdirectory(src)
109 endif() 71 endif()
110 72
111 -add_subdirectory(src)  
112 -add_subdirectory(test) 73 +# Enable testing when requested by the user
  74 +if (CXXOPTS_BUILD_TESTS)
  75 + enable_testing()
  76 + add_subdirectory(test)
  77 +endif()
cmake/cxxopts.cmake 0 โ†’ 100644
  1 +# Copyright (c) 2014 Jarryd Beck
  2 +#
  3 +# Permission is hereby granted, free of charge, to any person obtaining a copy
  4 +# of this software and associated documentation files (the "Software"), to deal
  5 +# in the Software without restriction, including without limitation the rights
  6 +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  7 +# copies of the Software, and to permit persons to whom the Software is
  8 +# furnished to do so, subject to the following conditions:
  9 +#
  10 +# The above copyright notice and this permission notice shall be included in
  11 +# all copies or substantial portions of the Software.
  12 +#
  13 +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  14 +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  15 +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  16 +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  17 +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  18 +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  19 +# THE SOFTWARE.
  20 +if (CMAKE_VERSION VERSION_GREATER 3.10 OR CMAKE_VERSION VERSION_EQUAL 3.10)
  21 + # Use include_guard() added in cmake 3.10
  22 + include_guard()
  23 +endif()
  24 +
  25 +include(GNUInstallDirs)
  26 +include(CMakePackageConfigHelpers)
  27 +
  28 +function(cxxopts_getversion version_arg)
  29 + # Parse the current version from the cxxopts header
  30 + file(STRINGS "${CMAKE_CURRENT_SOURCE_DIR}/include/cxxopts.hpp" cxxopts_version_defines
  31 + REGEX "#define CXXOPTS__VERSION_(MAJOR|MINOR|PATCH)")
  32 + foreach(ver ${cxxopts_version_defines})
  33 + if(ver MATCHES "#define CXXOPTS__VERSION_(MAJOR|MINOR|PATCH) +([^ ]+)$")
  34 + set(CXXOPTS__VERSION_${CMAKE_MATCH_1} "${CMAKE_MATCH_2}" CACHE INTERNAL "")
  35 + endif()
  36 + endforeach()
  37 + set(VERSION ${CXXOPTS__VERSION_MAJOR}.${CXXOPTS__VERSION_MINOR}.${CXXOPTS__VERSION_PATCH})
  38 +
  39 + # Give feedback to the user. Prefer DEBUG when available since large projects tend to have a lot
  40 + # going on already
  41 + if (CMAKE_VERSION VERSION_GREATER 3.15 OR CMAKE_VERSION VERSION_EQUAL 3.15)
  42 + message(DEBUG "cxxopts version ${VERSION}")
  43 + else()
  44 + message(STATUS "cxxopts version ${VERSION}")
  45 + endif()
  46 +
  47 + # Return the information to the caller
  48 + set(${version_arg} ${VERSION} PARENT_SCOPE)
  49 +endfunction()
  50 +
  51 +# Optionally, enable unicode support using the ICU library
  52 +function(cxxopts_use_unicode)
  53 + find_package(PkgConfig)
  54 + pkg_check_modules(ICU REQUIRED icu-uc)
  55 +
  56 + target_link_libraries(cxxopts INTERFACE ${ICU_LDFLAGS})
  57 + target_compile_options(cxxopts INTERFACE ${ICU_CFLAGS})
  58 + target_compile_definitions(cxxopts INTERFACE CXXOPTS_USE_UNICODE)
  59 +endfunction()
  60 +
  61 +# Request C++11 without gnu extension for the whole project and enable more warnings
  62 +macro(cxxopts_set_cxx_standard)
  63 + if (CXXOPTS_CXX_STANDARD)
  64 + set(CMAKE_CXX_STANDARD ${CXXOPTS_CXX_STANDARD})
  65 + else()
  66 + set(CMAKE_CXX_STANDARD 11)
  67 + endif()
  68 +
  69 + set(CMAKE_CXX_EXTENSIONS OFF)
  70 +endmacro()
  71 +
  72 +# Helper function to enable warnings
  73 +function(cxxopts_enable_warnings)
  74 + if(MSVC)
  75 + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W2")
  76 + elseif(CMAKE_CXX_COMPILER_ID MATCHES "[Cc]lang" OR CMAKE_CXX_COMPILER_ID MATCHES "GNU")
  77 + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Werror -Wextra -Wshadow -Weffc++ -Wsign-compare -Wshadow -Wwrite-strings -Wpointer-arith -Winit-self -Wconversion -Wno-sign-conversion -Wsuggest-override")
  78 + endif()
  79 +
  80 + set(CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS} PARENT_SCOPE)
  81 +endfunction()
  82 +
  83 +# Helper function to ecapsulate install logic
  84 +function(cxxopts_install_logic)
  85 + set(CXXOPTS_CMAKE_DIR "${CMAKE_INSTALL_LIBDIR}/cmake/cxxopts" CACHE STRING "Installation directory for cmake files, relative to ${CMAKE_INSTALL_PREFIX}.")
  86 + set(version_config "${PROJECT_BINARY_DIR}/cxxopts-config-version.cmake")
  87 + set(project_config "${PROJECT_BINARY_DIR}/cxxopts-config.cmake")
  88 + set(targets_export_name cxxopts-targets)
  89 +
  90 + # Generate the version, config and target files into the build directory.
  91 + write_basic_package_version_file(
  92 + ${version_config}
  93 + VERSION ${VERSION}
  94 + COMPATIBILITY AnyNewerVersion)
  95 + configure_package_config_file(
  96 + ${PROJECT_SOURCE_DIR}/cxxopts-config.cmake.in
  97 + ${project_config}
  98 + INSTALL_DESTINATION ${CXXOPTS_CMAKE_DIR})
  99 + export(TARGETS cxxopts NAMESPACE cxxopts::
  100 + FILE ${PROJECT_BINARY_DIR}/${targets_export_name}.cmake)
  101 +
  102 + # Install version, config and target files.
  103 + install(
  104 + FILES ${project_config} ${version_config}
  105 + DESTINATION ${CXXOPTS_CMAKE_DIR})
  106 + install(EXPORT ${targets_export_name} DESTINATION ${CXXOPTS_CMAKE_DIR}
  107 + NAMESPACE cxxopts::)
  108 +
  109 + # Install the header file and export the target
  110 + install(TARGETS cxxopts EXPORT ${targets_export_name} DESTINATION ${CMAKE_INSTALL_LIBDIR})
  111 + install(FILES ${PROJECT_SOURCE_DIR}/include/cxxopts.hpp DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
  112 +endfunction()
include/CMakeLists.txt 0 โ†’ 100644
  1 +# Copyright (c) 2014 Jarryd Beck
  2 +#
  3 +# Permission is hereby granted, free of charge, to any person obtaining a copy
  4 +# of this software and associated documentation files (the "Software"), to deal
  5 +# in the Software without restriction, including without limitation the rights
  6 +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  7 +# copies of the Software, and to permit persons to whom the Software is
  8 +# furnished to do so, subject to the following conditions:
  9 +#
  10 +# The above copyright notice and this permission notice shall be included in
  11 +# all copies or substantial portions of the Software.
  12 +#
  13 +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  14 +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  15 +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  16 +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  17 +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  18 +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  19 +# THE SOFTWARE.
  20 +target_include_directories(cxxopts INTERFACE
  21 + $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
  22 + $<INSTALL_INTERFACE:include>
  23 +)
src/CMakeLists.txt
1 # Copyright (c) 2014 Jarryd Beck 1 # Copyright (c) 2014 Jarryd Beck
2 -# 2 +#
3 # Permission is hereby granted, free of charge, to any person obtaining a copy 3 # Permission is hereby granted, free of charge, to any person obtaining a copy
4 # of this software and associated documentation files (the "Software"), to deal 4 # of this software and associated documentation files (the "Software"), to deal
5 # in the Software without restriction, including without limitation the rights 5 # in the Software without restriction, including without limitation the rights
6 # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 6 # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7 # copies of the Software, and to permit persons to whom the Software is 7 # copies of the Software, and to permit persons to whom the Software is
8 # furnished to do so, subject to the following conditions: 8 # furnished to do so, subject to the following conditions:
9 -# 9 +#
10 # The above copyright notice and this permission notice shall be included in 10 # The above copyright notice and this permission notice shall be included in
11 # all copies or substantial portions of the Software. 11 # all copies or substantial portions of the Software.
12 -# 12 +#
13 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 13 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 14 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 15 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
@@ -18,7 +18,5 @@ @@ -18,7 +18,5 @@
18 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 18 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19 # THE SOFTWARE. 19 # THE SOFTWARE.
20 20
21 -if(CXXOPTS_BUILD_EXAMPLES)  
22 - add_executable(example example.cpp)  
23 - target_link_libraries(example cxxopts)  
24 -endif() 21 +add_executable(example example.cpp)
  22 +target_link_libraries(example cxxopts)
test/CMakeLists.txt
1 -if (CXXOPTS_BUILD_TESTS)  
2 - add_executable(options_test main.cpp options.cpp)  
3 - target_link_libraries(options_test cxxopts)  
4 - add_test(options options_test) 1 +# Copyright (c) 2014 Jarryd Beck
  2 +#
  3 +# Permission is hereby granted, free of charge, to any person obtaining a copy
  4 +# of this software and associated documentation files (the "Software"), to deal
  5 +# in the Software without restriction, including without limitation the rights
  6 +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  7 +# copies of the Software, and to permit persons to whom the Software is
  8 +# furnished to do so, subject to the following conditions:
  9 +#
  10 +# The above copyright notice and this permission notice shall be included in
  11 +# all copies or substantial portions of the Software.
  12 +#
  13 +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  14 +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  15 +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  16 +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  17 +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  18 +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  19 +# THE SOFTWARE.
5 20
6 - # test if the targets are findable from the build directory  
7 - add_test(find-package-test ${CMAKE_CTEST_COMMAND}  
8 - -C ${CMAKE_BUILD_TYPE}  
9 - --build-and-test  
10 - "${CMAKE_CURRENT_SOURCE_DIR}/find-package-test"  
11 - "${CMAKE_CURRENT_BINARY_DIR}/find-package-test"  
12 - --build-generator ${CMAKE_GENERATOR}  
13 - --build-makeprogram ${CMAKE_MAKE_PROGRAM}  
14 - --build-options  
15 - "-DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}"  
16 - "-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}"  
17 - "-Dcxxopts_DIR=${PROJECT_BINARY_DIR}"  
18 - ) 21 +add_executable(options_test main.cpp options.cpp)
  22 +target_link_libraries(options_test cxxopts)
  23 +add_test(options options_test)
19 24
20 - # test if the targets are findable when add_subdirectory is used  
21 - add_test(add-subdirectory-test ${CMAKE_CTEST_COMMAND}  
22 - -C ${CMAKE_BUILD_TYPE}  
23 - --build-and-test  
24 - "${CMAKE_CURRENT_SOURCE_DIR}/add-subdirectory-test"  
25 - "${CMAKE_CURRENT_BINARY_DIR}/add-subdirectory-test"  
26 - --build-generator ${CMAKE_GENERATOR}  
27 - --build-makeprogram ${CMAKE_MAKE_PROGRAM}  
28 - --build-options  
29 - "-DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}"  
30 - "-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}"  
31 - ) 25 +# test if the targets are findable from the build directory
  26 +add_test(find-package-test ${CMAKE_CTEST_COMMAND}
  27 + -C ${CMAKE_BUILD_TYPE}
  28 + --build-and-test
  29 + "${CMAKE_CURRENT_SOURCE_DIR}/find-package-test"
  30 + "${CMAKE_CURRENT_BINARY_DIR}/find-package-test"
  31 + --build-generator ${CMAKE_GENERATOR}
  32 + --build-makeprogram ${CMAKE_MAKE_PROGRAM}
  33 + --build-options
  34 + "-DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}"
  35 + "-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}"
  36 + "-Dcxxopts_DIR=${PROJECT_BINARY_DIR}"
  37 +)
32 38
33 - add_executable(link_test link_a.cpp link_b.cpp)  
34 - target_link_libraries(link_test cxxopts)  
35 -endif() 39 +# test if the targets are findable when add_subdirectory is used
  40 +add_test(add-subdirectory-test ${CMAKE_CTEST_COMMAND}
  41 + -C ${CMAKE_BUILD_TYPE}
  42 + --build-and-test
  43 + "${CMAKE_CURRENT_SOURCE_DIR}/add-subdirectory-test"
  44 + "${CMAKE_CURRENT_BINARY_DIR}/add-subdirectory-test"
  45 + --build-generator ${CMAKE_GENERATOR}
  46 + --build-makeprogram ${CMAKE_MAKE_PROGRAM}
  47 + --build-options
  48 + "-DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}"
  49 + "-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}"
  50 +)
  51 +
  52 +add_executable(link_test link_a.cpp link_b.cpp)
  53 +target_link_libraries(link_test cxxopts)