diff --git a/CMakeLists.txt b/CMakeLists.txt index f610219d..76cf6555 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -26,11 +26,28 @@ feature_info_on_off(DISABLE_CMAKE_CONFIG "won't generate CMake config file" "wil option(ENABLE_WIN32_IO "Build the Windows I/O helper class" OFF) feature_info_on_off(ENABLE_WIN32_IO "will build Windows I/O code" "will not build Windows I/O code") +option(DEV_MODE "Developer mode with extra compilation checks" OFF) +feature_info_on_off(DEV_MODE "added developer mode extra compilation checks" "default build mode") + include(GNUInstallDirs) set(CMAKE_CXX_STANDARD 14) set(CMAKE_CXX_STANDARD_REQUIRED ON) +include(CheckCXXCompilerFlag) +include(CMakeParseArguments) +function(add_cxx_flag_if_supported) + foreach(flagname ${ARGN}) + string(REPLACE "-" "_" TEST_RESULT ${flagname}) + check_cxx_compiler_flag(${flagname} HAVE_FLAG_${TEST_RESULT}) + # message(STATUS "supported ${flagname}: ${HAVE_FLAG_${TEST_RESULT}}") + + if (HAVE_FLAG_${TEST_RESULT}) + add_compile_options(${flagname}) + endif() + endforeach() +endfunction() + find_package(utf8cpp 3.2.0) if(NOT utf8cpp_FOUND) include(FetchContent REQUIRED) @@ -45,6 +62,16 @@ if(NOT utf8cpp_FOUND) FetchContent_MakeAvailable(utf8cpp) endif() +if(DEV_MODE) + message(STATUS "Using developer mode for ${CMAKE_CXX_COMPILER_ID}") + set(CMAKE_CXX_EXTENSIONS OFF) + add_definitions("-D_LIBCPP_REMOVE_TRANSITIVE_INCLUDES") + add_cxx_flag_if_supported(-Wno-error=unused-command-line-argument + -Wall -Wextra -Wpedantic -Wfatal-errors -fstack-protector-strong + -Wcast-align + -W4) +endif() + set(libebml_SOURCES src/Debug.cpp src/EbmlBinary.cpp