diff --git a/.github/workflows/linux-gcc13.yaml b/.github/workflows/linux-gcc13.yaml index fb0b7ceb..92c26f7c 100644 --- a/.github/workflows/linux-gcc13.yaml +++ b/.github/workflows/linux-gcc13.yaml @@ -17,7 +17,7 @@ jobs: { "name": "Static", "option": "OFF"} ] env: - CMAKE_OPTIONS: -DCMAKE_CXX_EXTENSIONS=OFF -DBUILD_TESTING=ON + CMAKE_OPTIONS: -DDEV_MODE=ON -DBUILD_TESTING=ON steps: - uses: lukka/get-cmake@latest diff --git a/.github/workflows/linux.yaml b/.github/workflows/linux.yaml index 8ae292e1..c38b9b2d 100644 --- a/.github/workflows/linux.yaml +++ b/.github/workflows/linux.yaml @@ -10,7 +10,7 @@ jobs: name: libebml runs-on: ubuntu-latest env: - CMAKE_OPTIONS: -DCMAKE_CXX_EXTENSIONS=OFF -DBUILD_TESTING=ON + CMAKE_OPTIONS: -DDEV_MODE=ON -DBUILD_TESTING=ON steps: - uses: lukka/get-cmake@latest diff --git a/.github/workflows/macos.yaml b/.github/workflows/macos.yaml index 3683143a..daa9fa31 100644 --- a/.github/workflows/macos.yaml +++ b/.github/workflows/macos.yaml @@ -14,7 +14,7 @@ jobs: matrix: arch: [x86_64, arm64] env: - CMAKE_OPTIONS: -DCMAKE_CXX_EXTENSIONS=OFF -DBUILD_TESTING=ON + CMAKE_OPTIONS: -DDEV_MODE=ON -DBUILD_TESTING=ON steps: - uses: lukka/get-cmake@latest diff --git a/.github/workflows/uwp.yaml b/.github/workflows/uwp.yaml index b27e1c6c..21276638 100644 --- a/.github/workflows/uwp.yaml +++ b/.github/workflows/uwp.yaml @@ -18,14 +18,14 @@ jobs: { "name": "arm64", "option": "arm64"}, ] env: - CMAKE_OPTIONS: -DCMAKE_CXX_EXTENSIONS=OFF -DCMAKE_SYSTEM_NAME="WindowsStore" -DCMAKE_SYSTEM_VERSION="10.0" -DCMAKE_CXX_FLAGS_INIT="-DWINVER=0x0A00 -DWINAPI_FAMILY=WINAPI_FAMILY_PC_APP" + CMAKE_OPTIONS: -DDEV_MODE=ON -DCMAKE_SYSTEM_NAME="WindowsStore" -DCMAKE_SYSTEM_VERSION="10.0" -DCMAKE_CXX_FLAGS_INIT="-DWINVER=0x0A00 -DWINAPI_FAMILY=WINAPI_FAMILY_PC_APP" # TODO use CreateFile2 and add -DENABLE_WIN32_IO=ON steps: - uses: lukka/get-cmake@latest - name: Get pushed code uses: actions/checkout@v3 - + - name: Configure run: cmake -S . -B _build ${{ env.CMAKE_OPTIONS }} -A ${{ matrix.arch.option }} -DBUILD_SHARED_LIBS=OFF diff --git a/.github/workflows/windows.yaml b/.github/workflows/windows.yaml index a7fbf6a0..8c3152f0 100644 --- a/.github/workflows/windows.yaml +++ b/.github/workflows/windows.yaml @@ -19,7 +19,7 @@ jobs: { "name": "arm64", "option": "arm64", "env": "ARM64"}, ] env: - CMAKE_OPTIONS: -DENABLE_WIN32_IO=ON -DCMAKE_CXX_EXTENSIONS=OFF -DCMAKE_CXX_FLAGS_INIT="-DWINVER=0x0501" -DBUILD_TESTING=ON + CMAKE_OPTIONS: -DENABLE_WIN32_IO=ON -DDEV_MODE=ON -DCMAKE_CXX_FLAGS_INIT="-DWINVER=0x0501" -DBUILD_TESTING=ON steps: - uses: lukka/get-cmake@latest diff --git a/CMakeLists.txt b/CMakeLists.txt index b48d6358..debe4c62 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -8,12 +8,37 @@ option(DISABLE_PKGCONFIG "Disable PkgConfig module generation" OFF) option(DISABLE_CMAKE_CONFIG "Disable CMake package config module generation" OFF) cmake_dependent_option(BUILD_SHARED_LIBS "Build libebml as a shared library (except Windows)" OFF "NOT WIN32" OFF) option(BUILD_TESTING "Build tests" OFF) +option(DEV_MODE "Developer mode with extra compilation checks" OFF) 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() + +if(DEV_MODE) + message(STATUS "Using developer mode for ${CMAKE_CXX_COMPILER_ID}") + set(CMAKE_CXX_EXTENSIONS OFF) + add_cxx_flag_if_supported(-Wall -Wno-comment -Wfatal-errors -fstack-protector-strong -Wnon-virtual-dtor -Wextra + -Wunused -Wpedantic -Woverloaded-virtual -Wshadow + -Wno-self-assign -Wno-mismatched-tags -Wno-inconsistent-missing-override + -Wno-potentially-evaluated-expression -Wno-extra-semi -Wno-gnu-zero-variadic-macro-arguments) + add_cxx_flag_if_supported(-Qunused-arguments) +endif() + set(libebml_SOURCES src/EbmlBinary.cpp src/EbmlContexts.cpp