I am developing a header-only library that uses C++17 features. The project structure is like this:
 - project
   - README.md
   - LICENSE.md
   - CMakeLists.txt
   - include
     - proj_library.h
   - test
     - unittest
       - CMakeLists.txt
       - main.cpp
       - test.cpp
The unit tests use doctest unit testing framework, which I currently do not include in the project.
How should my main CMakeLists.txt file and the unit test CMakeLists.txt files look like to:
- make clients use C++17 (or later) language standard as the library uses std::optionaland the like
- enable generating nice IDE project (I am using Visual Studio 2017)
- enable the equivalent of -Wall-Wextra-pedanticoptions in as compiler-agnostic way as possible (I plan compilation using at least GCC, Clang, and VS 2017)
So far I have this, which I based on several open-source projects and articles:
Main CMakeLists.txt:
cmake_minimum_required(VERSION 3.15)
project("lib-headeronly")
add_library(${PROJECT_NAME} INTERFACE)
target_include_directories(${PROJECT_NAME} INTERFACE include/)
target_compile_features(${PROJECT_NAME} INTERFACE cxx_std_17)
enable_testing()
add_subdirectory(test/unittest)
Unit test CMakeLists.txt:
cmake_minimum_required(VERSION 3.15)
include(CTest)
add_executable(unittest)
target_sources(unittest
    PRIVATE
    main.cpp
    test.cpp)
target_include_directories(unittest
    PRIVATE $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}>/include
    $<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}>)
target_compile_features(unittest PRIVATE cxx_std_17)
add_test(NAME unittest COMMAND unittest)
Currently, while the library is under development, I do not need fancy targets for installation and the like. I just need facilities for building unit tests on several platforms.
Any suggestions?
