1
0
Fork 0
mirror of https://github.com/TheLartians/ModernCppStarter.git synced 2025-08-30 21:51:12 +02:00

add and use WarningsAsErrors cmake module

export cxx_std_20 with target_compile_features()
but do not export pedantic Waning options!
This commit is contained in:
ClausKlein 2022-03-29 10:38:34 +02:00
parent c2751d904b
commit c6c34b02d1
3 changed files with 20 additions and 12 deletions

View file

@ -45,13 +45,16 @@ file(GLOB_RECURSE sources CONFIGURE_DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/source/
# Note: for header-only libraries change all PUBLIC flags to INTERFACE and create an interface # Note: for header-only libraries change all PUBLIC flags to INTERFACE and create an interface
# target: add_library(${PROJECT_NAME} INTERFACE) # target: add_library(${PROJECT_NAME} INTERFACE)
add_library(${PROJECT_NAME} ${headers} ${sources}) add_library(${PROJECT_NAME} ${headers} ${sources})
set_target_properties(${PROJECT_NAME} PROPERTIES CXX_STANDARD 17) target_compile_features(${PROJECT_NAME} PUBLIC cxx_std_20)
# enable compiler warnings
include(cmake/WarningsAsErrors.cmake)
# being a cross-platform target, we enforce standards conformance on MSVC # being a cross-platform target, we enforce standards conformance on MSVC
target_compile_options(${PROJECT_NAME} PUBLIC "$<$<COMPILE_LANG_AND_ID:CXX,MSVC>:/permissive->") target_compile_options(${PROJECT_NAME} PRIVATE "$<$<COMPILE_LANG_AND_ID:CXX,MSVC>:/permissive->")
# Link dependencies # Link dependencies
target_link_libraries(${PROJECT_NAME} PRIVATE fmt::fmt) target_link_libraries(${PROJECT_NAME} PUBLIC fmt::fmt)
target_include_directories( target_include_directories(
${PROJECT_NAME} PUBLIC $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include> ${PROJECT_NAME} PUBLIC $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>

View file

@ -0,0 +1,12 @@
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang" AND CMAKE_CXX_SIMULATE_ID MATCHES "MSVC")
target_compile_options(${PROJECT_NAME} PRIVATE /W4 /WX)
elseif(CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")
target_compile_options(${PROJECT_NAME} PRIVATE -Wall -Wextra -Wpedantic -Werror -Wshadow)
if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang" AND CMAKE_CXX_COMPILER_VERSION GREATER_EQUAL 10.0)
target_compile_options(${PROJECT_NAME} PRIVATE -Wdeprecated-copy-dtor -Wnewline-eof)
endif()
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
string(REGEX REPLACE " /W[0-4]" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
target_compile_options(${PROJECT_NAME} PRIVATE /W4 /WX)
endif()

View file

@ -33,17 +33,10 @@ endif()
file(GLOB sources CONFIGURE_DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/source/*.cpp) file(GLOB sources CONFIGURE_DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/source/*.cpp)
add_executable(${PROJECT_NAME} ${sources}) add_executable(${PROJECT_NAME} ${sources})
target_link_libraries(${PROJECT_NAME} doctest::doctest Greeter::Greeter) target_link_libraries(${PROJECT_NAME} doctest::doctest Greeter::Greeter)
set_target_properties(${PROJECT_NAME} PROPERTIES CXX_STANDARD 17) target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_20)
# enable compiler warnings # enable compiler warnings
if(NOT TEST_INSTALLED_VERSION) include(../cmake/WarningsAsErrors.cmake)
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang" OR CMAKE_CXX_COMPILER_ID MATCHES "GNU")
target_compile_options(Greeter PUBLIC -Wall -Wpedantic -Wextra -Werror)
elseif(MSVC)
target_compile_options(Greeter PUBLIC /W4 /WX)
target_compile_definitions(${PROJECT_NAME} PUBLIC DOCTEST_CONFIG_USE_STD_HEADERS)
endif()
endif()
# ---- Add GreeterTests ---- # ---- Add GreeterTests ----