Skip to content

refactor(cmake): replace CheckC/CXXCompilerFlag with CheckCompilerFlag#2092

Open
predat wants to merge 2 commits intodevelopfrom
dev/cmake-modernize-compiler-flag-checks
Open

refactor(cmake): replace CheckC/CXXCompilerFlag with CheckCompilerFlag#2092
predat wants to merge 2 commits intodevelopfrom
dev/cmake-modernize-compiler-flag-checks

Conversation

@predat
Copy link
Contributor

@predat predat commented Mar 19, 2026

Description

Remove two redundant local CMake module overrides and modernize the
compiler flag detection in CodeCoverage.cmake to use the unified
CheckCompilerFlag module.

Changes

Deleted

  • src/cmake/CheckCCompilerFlag.cmake
  • src/cmake/CheckCXXCompilerFlag.cmake

These files were local copies of CMake built-in modules. Having them in
src/cmake/ (which is on CMAKE_MODULE_PATH) caused them to shadow the
official CMake versions, leading to potential silent regressions on newer
CMake releases.

Modified — src/cmake/CodeCoverage.cmake

Replaced the two language-specific includes:

include(CheckCXXCompilerFlag)
check_cxx_compiler_flag(-fprofile-abs-path HAVE_cxx_fprofile_abs_path)

include(CheckCCompilerFlag)
check_c_compiler_flag(-fprofile-abs-path HAVE_c_fprofile_abs_path)

with the unified module available since CMake 3.19:

include(CheckCompilerFlag)
check_compiler_flag(CXX -fprofile-abs-path HAVE_cxx_fprofile_abs_path)
check_compiler_flag(C   -fprofile-abs-path HAVE_c_fprofile_abs_path)

Motivation

Aligns with the cmake_minimum_required(VERSION 3.30) already set in
the project. CheckCompilerFlag is the modern, language-agnostic
successor to the deprecated per-language variants, and also supports
CUDA, HIP and Fortran with the same syntax.

Drop the local copies of CheckCCompilerFlag.cmake and
CheckCXXCompilerFlag.cmake, which were redundant overrides of CMake
built-in modules.

In CodeCoverage.cmake, replace the two language-specific includes and
calls with the unified CheckCompilerFlag module (introduced in CMake
3.19), consistent with the project's cmake_minimum_required of 3.30:

  - include(CheckCXXCompilerFlag) + check_cxx_compiler_flag(...)
  - include(CheckCCompilerFlag)   + check_c_compiler_flag(...)

become:

  - include(CheckCompilerFlag)    [once, shared by both blocks]
  - check_compiler_flag(CXX ...)
  - check_compiler_flag(C   ...)
Drop three legacy CMake module files that are no longer referenced
anywhere in the build system:
  - src/cmake/FindSSE.cmake

SSE/AVX detection is handled by Eigen and the compiler directly.
Compiler flag checking is now done via the built-in CheckCompilerFlag
module (CMake 3.19+) in CodeCoverage.cmake.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant