Skip to content

Commit 5f42869

Browse files
committed
Updated compiler identification
Using CMAKE_COMPILER_IS_GNUCC or CMAKE_COMPILER_IS_GNUCXX is deprecated, and it is recommended to do string matching using CMAKE_C_COMPILER_ID or CMAKE_CXX_COMPILER_ID instead, which is far more flexible.
1 parent bb724e2 commit 5f42869

File tree

2 files changed

+18
-12
lines changed

2 files changed

+18
-12
lines changed

code-coverage.cmake

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,8 @@ if(CODE_COVERAGE AND NOT CODE_COVERAGE_ADDED)
144144
COMMAND ;
145145
COMMENT "libs ready for coverage report.")
146146

147-
elseif(CMAKE_COMPILER_IS_GNUCXX)
147+
elseif(CMAKE_C_COMPILER_ID MATCHES "GNU"
148+
OR CMAKE_CXX_COMPILER_ID MATCHES "GNU")
148149
# Messages
149150
message(STATUS "Building with lcov Code Coverage Tools")
150151

@@ -259,7 +260,8 @@ function(target_code_coverage TARGET_NAME)
259260
${TARGET_VISIBILITY}
260261
-fprofile-instr-generate
261262
-fcoverage-mapping)
262-
elseif(CMAKE_COMPILER_IS_GNUCXX)
263+
elseif(CMAKE_C_COMPILER_ID MATCHES "GNU"
264+
OR CMAKE_CXX_COMPILER_ID MATCHES "GNU")
263265
target_compile_options(
264266
${TARGET_NAME}
265267
${TARGET_VISIBILITY}
@@ -370,7 +372,8 @@ function(target_code_coverage TARGET_NAME)
370372
-format="html" ${EXCLUDE_REGEX}
371373
DEPENDS ccov-processing-${target_code_coverage_COVERAGE_TARGET_NAME})
372374

373-
elseif(CMAKE_COMPILER_IS_GNUCXX)
375+
elseif(CMAKE_C_COMPILER_ID MATCHES "GNU"
376+
OR CMAKE_CXX_COMPILER_ID MATCHES "GNU")
374377
set(COVERAGE_INFO
375378
"${CMAKE_COVERAGE_OUTPUT_DIRECTORY}/${target_code_coverage_COVERAGE_TARGET_NAME}.info"
376379
)
@@ -439,7 +442,8 @@ function(target_code_coverage TARGET_NAME)
439442
endif()
440443
add_dependencies(ccov ccov-${target_code_coverage_COVERAGE_TARGET_NAME})
441444

442-
if(NOT CMAKE_COMPILER_IS_GNUCXX)
445+
if(NOT CMAKE_C_COMPILER_ID MATCHES "GNU"
446+
OR NOT CMAKE_CXX_COMPILER_ID MATCHES "GNU")
443447
if(NOT TARGET ccov-report)
444448
add_custom_target(ccov-report)
445449
endif()
@@ -473,7 +477,8 @@ function(add_code_coverage)
473477
OR CMAKE_CXX_COMPILER_ID MATCHES "(Apple)?[Cc]lang")
474478
add_compile_options(-fprofile-instr-generate -fcoverage-mapping)
475479
add_link_options(-fprofile-instr-generate -fcoverage-mapping)
476-
elseif(CMAKE_COMPILER_IS_GNUCXX)
480+
elseif(CMAKE_C_COMPILER_ID MATCHES "GNU"
481+
OR CMAKE_CXX_COMPILER_ID MATCHES "GNU")
477482
add_compile_options(-fprofile-arcs -ftest-coverage)
478483
link_libraries(gcov)
479484
endif()
@@ -552,7 +557,8 @@ function(add_code_coverage_all_targets)
552557
-format="html" ${EXCLUDE_REGEX}
553558
DEPENDS ccov-all-processing)
554559

555-
elseif(CMAKE_COMPILER_IS_GNUCXX)
560+
elseif(CMAKE_C_COMPILER_ID MATCHES "GNU"
561+
OR CMAKE_CXX_COMPILER_ID MATCHES "GNU")
556562
set(COVERAGE_INFO "${CMAKE_COVERAGE_OUTPUT_DIRECTORY}/all-merged.info")
557563

558564
# Nothing required for gcov

compiler-options.cmake

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ option(GENERATE_DEPENDENCY_DATA "Generates .d files with header dependencies"
2020
OFF)
2121

2222
if(ENABLE_ALL_WARNINGS)
23-
if(CMAKE_COMPILER_IS_GNUCC
24-
OR CMAKE_COMPILER_IS_GNUCXX
23+
if(CMAKE_C_COMPILER_ID MATCHES "GNU"
24+
OR CMAKE_CXX_COMPILER_ID MATCHES "GNU"
2525
OR CMAKE_C_COMPILER_ID MATCHES "(Apple)?[Cc]lang"
2626
OR CMAKE_CXX_COMPILER_ID MATCHES "(Apple)?[Cc]lang")
2727
# GCC/Clang
@@ -33,17 +33,17 @@ if(ENABLE_ALL_WARNINGS)
3333
endif()
3434

3535
if(ENABLE_EFFECTIVE_CXX)
36-
if(CMAKE_COMPILER_IS_GNUCC
37-
OR CMAKE_COMPILER_IS_GNUCXX
36+
if(CMAKE_C_COMPILER_ID MATCHES "GNU"
37+
OR CMAKE_CXX_COMPILER_ID MATCHES "GNU"
3838
OR CMAKE_C_COMPILER_ID MATCHES "(Apple)?[Cc]lang"
3939
OR CMAKE_CXX_COMPILER_ID MATCHES "(Apple)?[Cc]lang")
4040
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Weffc++")
4141
endif()
4242
endif()
4343

4444
if(GENERATE_DEPENDENCY_DATA)
45-
if(CMAKE_COMPILER_IS_GNUCC
46-
OR CMAKE_COMPILER_IS_GNUCXX
45+
if(CMAKE_C_COMPILER_ID MATCHES "GNU"
46+
OR CMAKE_CXX_COMPILER_ID MATCHES "GNU"
4747
OR CMAKE_C_COMPILER_ID MATCHES "(Apple)?[Cc]lang"
4848
OR CMAKE_CXX_COMPILER_ID MATCHES "(Apple)?[Cc]lang")
4949
add_compile_options(-MD)

0 commit comments

Comments
 (0)