|
1 |
| -cmake_minimum_required(VERSION 3.10) |
| 1 | +cmake_minimum_required(VERSION 3.20) |
2 | 2 |
|
3 | 3 | project(OS2DSRules VERSION 0.0.1)
|
4 | 4 |
|
5 |
| -set(CMAKE_CXX_STANDARD 20) |
6 |
| -set(CMAKE_CXX_STANDARD_REQUIRED True) |
| 5 | +# Detect available compiler on the host system. |
| 6 | +set(gcc_like_cxx "$<COMPILE_LANG_AND_ID:CXX,ARMClang,AppleClang,Clang,GNU,LCC>") |
| 7 | +set(msvc_cxx "$<COMPILE_LANG_AND_ID:CXX,MSVC>") |
7 | 8 |
|
| 9 | +# Define C++ standard and compiler flags as a target library. |
| 10 | +add_library(os2dsrules_compiler_flags INTERFACE) |
| 11 | +target_compile_features(os2dsrules_compiler_flags INTERFACE cxx_std_20) |
| 12 | +# Build flags. |
| 13 | +target_compile_options(os2dsrules_compiler_flags INTERFACE |
| 14 | + "$<${gcc_like_cxx}:-Wall;-Wextra;-Wshadow;-Wformat=2;-Wunused;-Wconversion;-Wpedantic;-Werror;-O3>" |
| 15 | + "$<${msvc_cxx}:-W3>" |
| 16 | +) |
| 17 | + |
| 18 | +# Compile as a shared library. |
8 | 19 | add_library(os2dsrules SHARED lib/cpr-detector.cpp)
|
9 | 20 | include_directories(os2dsrules include)
|
| 21 | +target_link_libraries(os2dsrules PUBLIC os2dsrules_compiler_flags) |
10 | 22 |
|
11 |
| -add_executable(test tests/test.cpp) |
12 |
| -target_include_directories(test PUBLIC "${PROJECT_BINARY_DIR}" "${PROJECT_SOURCE_DIR/include}") |
13 |
| -target_link_libraries(test os2dsrules) |
| 23 | +# Compile test suite. |
| 24 | +enable_testing() |
| 25 | +add_executable(testsuite tests/test.cpp) |
| 26 | +target_include_directories(testsuite PUBLIC "${PROJECT_BINARY_DIR}" "${PROJECT_SOURCE_DIR/include}") |
| 27 | +target_link_libraries(testsuite os2dsrules os2dsrules_compiler_flags) |
| 28 | +add_test(unittests testsuite) |
14 | 29 |
|
| 30 | +# Install library on system. |
| 31 | +set(installable_libs os2dsrules os2dsrules_compiler_flags) |
| 32 | +install(TARGETS ${installable_libs} DESTINATION lib) |
15 | 33 |
|
| 34 | +# Install header files on system. |
| 35 | +install(FILES include/os2dsrules.hpp include/cpr-detector.hpp DESTINATION include) |
0 commit comments