From 904d049a8ac2a3f61c8449f6b85c3dc69b7c021f Mon Sep 17 00:00:00 2001 From: Anonymous Maarten Date: Thu, 1 Feb 2024 02:03:32 +0100 Subject: [PATCH] cmake: test with -Wparentheses + optionally with -Werror --- .github/workflows/build.yml | 7 ++++++- CMakeLists.txt | 28 ++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 33b3a995..4a6bf01a 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -47,7 +47,12 @@ jobs: - name: Build run: | - cmake -S . -B build -DCMAKE_BUILD_TYPE=Debug -GNinja -Werror=dev -DISLE_USE_DX5_LIBS=${{ !matrix.toolchain.no-dx5-libs }} -DENABLE_CLANG_TIDY=${{ !!matrix.toolchain.clang-tidy }} + cmake -S . -B build -GNinja \ + -DCMAKE_BUILD_TYPE=Debug \ + -DISLE_USE_DX5_LIBS=${{ !matrix.toolchain.no-dx5-libs }} \ + -DENABLE_CLANG_TIDY=${{ !!matrix.toolchain.clang-tidy }} \ + -DISLE_WERROR=ON \ + -Werror=dev -- -k0 cmake --build build build: diff --git a/CMakeLists.txt b/CMakeLists.txt index 8bf32551..ab3acf4b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,7 +2,9 @@ cmake_minimum_required(VERSION 3.13 FATAL_ERROR) project(isle CXX) +include(CheckCXXSourceCompiles) include(CMakeDependentOption) +include(CMakePushCheckState) set(CMAKE_EXPORT_COMPILE_COMMANDS TRUE) option(ENABLE_CLANG_TIDY "Enable clang-tidy") @@ -31,13 +33,39 @@ macro(register_lego1_target __target) list(APPEND lego1_targets ${__target}) endmacro() +function(check_cxx_has_option VAR OPTION) + cmake_push_check_state(RESET) + set(CMAKE_REQUIRED_FLAGS "${OPTION} ") + if(MSVC) + string(APPEND CMAKE_REQUIRED_FLAGS "/WX") + else() + string(APPEND CMAKE_REQUIRED_FLAGS "-Werror") + endif() + check_cxx_source_compiles("int main() { return 0; }" ${VAR}) + cmake_pop_check_state() +endfunction() + message(STATUS "MSVC for decompilation: ${MSVC_FOR_DECOMP}") +option(ISLE_WERROR "Treat warnings as errors" OFF) option(ISLE_BUILD_APP "Build ISLE.EXE application" ON) option(ISLE_USE_SMARTHEAP "Build with SmartHeap" ${MSVC_FOR_DECOMP}) option(ISLE_USE_DX5 "Build with internal DirectX 5 SDK" ON) cmake_dependent_option(ISLE_USE_DX5_LIBS "Build with internal DirectX 5 SDK Libraries" ON ISLE_USE_DX5 OFF) +if(ISLE_WERROR) + if(MSVC) + add_compile_options(-WX) + else() + add_compile_options(-Werror) + endif() +endif() + +check_cxx_has_option(COMPILER_SUPPORTS_Wparentheses -Wparentheses) +if(COMPILER_SUPPORTS_Wparentheses) + add_compile_options(-Wparentheses) +endif() + add_library(DirectX5::DirectX5 INTERFACE IMPORTED) target_include_directories(DirectX5::DirectX5 INTERFACE "${CMAKE_SOURCE_DIR}/3rdparty/dx5/inc") if(ISLE_USE_DX5_LIBS)