|
1 |
| -cmake_minimum_required( VERSION 3.1 ) |
2 |
| -project( ProgramOptions ) |
| 1 | +cmake_minimum_required( VERSION 3.5 ) |
| 2 | + |
| 3 | +if( NOT DEFINED PROJECT_NAME ) |
| 4 | + set( PROGRAMOPTIONS_NOT_SUBPROJECT ON ) |
| 5 | +endif() |
| 6 | + |
| 7 | +project( ProgramOptions LANGUAGES CXX VERSION 1.0.0 ) |
3 | 8 | set( CMAKE_CXX_STANDARD 11 )
|
4 | 9 | set( CMAKE_CXX_STANDARD_REQUIRED ON )
|
5 | 10 | set( CMAKE_CXX_EXTENSIONS OFF )
|
6 | 11 |
|
7 |
| -option( PROGRAMOPTIONS_NO_EXCEPTIONS "disable exceptions" OFF ) |
8 |
| -option( PROGRAMOPTIONS_NO_COLORS "disable colored output" OFF ) |
9 |
| -option( PROGRAMOPTIONS_BUILD_TEST "build test" ON ) |
10 |
| -option( PROGRAMOPTIONS_BUILD_EXAMPLES "build examples" ON ) |
11 |
| - |
12 |
| -if( CMAKE_CXX_COMPILER_ID MATCHES "Clang" OR |
13 |
| - CMAKE_CXX_COMPILER_ID MATCHES "GNU" OR |
14 |
| - CMAKE_CXX_COMPILER_ID MATCHES "Intel" ) |
15 |
| - set( PROGRAMOPTIONS_GNU_OPTIONS TRUE ) |
16 |
| -elseif( CMAKE_CXX_COMPILER_ID MATCHES "MSVC" ) |
17 |
| - set( PROGRAMOPTIONS_MS_OPTIONS TRUE ) |
18 |
| -endif() |
| 12 | +add_library( ProgramOptionsHxx INTERFACE ) |
| 13 | +target_include_directories( ProgramOptionsHxx INTERFACE "${CMAKE_CURRENT_LIST_DIR}/include" ) |
19 | 14 |
|
20 |
| -include_directories( "${CMAKE_CURRENT_LIST_DIR}/include/" ) |
| 15 | +if( PROGRAMOPTIONS_NOT_SUBPROJECT ) |
| 16 | + option( PROGRAMOPTIONS_NO_EXCEPTIONS "disable exceptions" OFF ) |
| 17 | + option( PROGRAMOPTIONS_NO_COLORS "disable colored output" OFF ) |
| 18 | + option( PROGRAMOPTIONS_BUILD_TEST "build test" ON ) |
| 19 | + option( PROGRAMOPTIONS_BUILD_EXAMPLES "build examples" ON ) |
21 | 20 |
|
22 |
| -if( PROGRAMOPTIONS_GNU_OPTIONS ) |
23 |
| - set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Wpedantic -Wno-deprecated -fno-rtti" ) |
24 |
| - set( CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -g -ggdb -fno-omit-frame-pointer" ) |
25 |
| - set( CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O3 -march=native -DNDEBUG -s -flto" ) |
26 |
| -endif() |
| 21 | + if( CMAKE_CXX_COMPILER_ID MATCHES "Clang" OR |
| 22 | + CMAKE_CXX_COMPILER_ID MATCHES "GNU" OR |
| 23 | + CMAKE_CXX_COMPILER_ID MATCHES "Intel" ) |
| 24 | + set( PROGRAMOPTIONS_GNU_OPTIONS TRUE ) |
| 25 | + elseif( CMAKE_CXX_COMPILER_ID MATCHES "MSVC" ) |
| 26 | + set( PROGRAMOPTIONS_MS_OPTIONS TRUE ) |
| 27 | + endif() |
27 | 28 |
|
28 |
| -if( PROGRAMOPTIONS_NO_EXCEPTIONS ) |
29 |
| - add_definitions( -DPROGRAMOPTIONS_NO_EXCEPTIONS ) |
30 | 29 | if( PROGRAMOPTIONS_GNU_OPTIONS )
|
31 |
| - set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-exceptions" ) |
32 |
| - elseif( PROGRAMOPTIONS_MS_OPTIONS ) |
33 |
| - set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /EHsc" ) |
| 30 | + set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Wpedantic -Wno-deprecated -fno-rtti" ) |
| 31 | + set( CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -g -ggdb -fno-omit-frame-pointer" ) |
| 32 | + set( CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O3 -march=native -DNDEBUG -s -flto" ) |
34 | 33 | endif()
|
35 |
| -endif() |
36 | 34 |
|
37 |
| -if( PROGRAMOPTIONS_NO_COLORS ) |
38 |
| - add_definitions( -DPROGRAMOPTIONS_NO_COLORS ) |
39 |
| -endif() |
| 35 | + if( PROGRAMOPTIONS_NO_EXCEPTIONS ) |
| 36 | + add_definitions( -DPROGRAMOPTIONS_NO_EXCEPTIONS ) |
| 37 | + if( PROGRAMOPTIONS_GNU_OPTIONS ) |
| 38 | + set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-exceptions" ) |
| 39 | + elseif( PROGRAMOPTIONS_MS_OPTIONS ) |
| 40 | + set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /EHsc" ) |
| 41 | + endif() |
| 42 | + endif() |
40 | 43 |
|
41 |
| -if( PROGRAMOPTIONS_BUILD_TEST ) |
42 |
| - add_subdirectory( "${CMAKE_CURRENT_LIST_DIR}/ext/Catch2" ) |
| 44 | + if( PROGRAMOPTIONS_NO_COLORS ) |
| 45 | + add_definitions( -DPROGRAMOPTIONS_NO_COLORS ) |
| 46 | + endif() |
43 | 47 |
|
44 |
| - file( GLOB_RECURSE test_src test/*.cxx ) |
45 |
| - add_executable( Test ${test_src} ) |
46 |
| - target_link_libraries( Test Catch2::Catch2 ) |
47 |
| -endif() |
| 48 | + if( PROGRAMOPTIONS_BUILD_TEST ) |
| 49 | + add_subdirectory( "${CMAKE_CURRENT_LIST_DIR}/ext/Catch2" ) |
48 | 50 |
|
49 |
| -if( PROGRAMOPTIONS_BUILD_EXAMPLES ) |
50 |
| - file( GLOB_RECURSE examples_src examples/*.cxx ) |
51 |
| - foreach( src_name ${examples_src} ) |
52 |
| - # CMake's regex engine doesn't support lazy evaluation (?), hence the hack below |
53 |
| - string( REGEX REPLACE "^.*[^a-zA-Z_]([a-zA-Z_]+)\\.cxx$" "\\1" exe_name ${src_name} ) |
54 |
| - add_executable( ${exe_name} ${src_name} ) |
55 |
| - endforeach( src_name ${examples_src} ) |
| 51 | + file( GLOB_RECURSE test_src test/*.cxx ) |
| 52 | + add_executable( Test ${test_src} ) |
| 53 | + target_link_libraries( Test |
| 54 | + Catch2::Catch2 |
| 55 | + ProgramOptionsHxx |
| 56 | + ) |
| 57 | + endif() |
| 58 | + |
| 59 | + if( PROGRAMOPTIONS_BUILD_EXAMPLES ) |
| 60 | + file( GLOB_RECURSE examples_src examples/*.cxx ) |
| 61 | + foreach( src_name ${examples_src} ) |
| 62 | + # CMake's regex engine doesn't support lazy evaluation (?), hence the hack below |
| 63 | + string( REGEX REPLACE "^.*[^a-zA-Z_]([a-zA-Z_]+)\\.cxx$" "\\1" exe_name ${src_name} ) |
| 64 | + add_executable( ${exe_name} ${src_name} ) |
| 65 | + |
| 66 | + target_link_libraries( ${exe_name} ProgramOptionsHxx ) |
| 67 | + endforeach( src_name ${examples_src} ) |
| 68 | + endif() |
56 | 69 | endif()
|
0 commit comments