Using CMake 3.14 or greater and gcc
/g++
, I wrote
set(GCC_COVERAGE_COMPILE_FLAGS "-Wno-comment -Werror=incompatible-pointer-types -Werror=return-type")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${GCC_COVERAGE_COMPILE_FLAGS}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${GCC_COVERAGE_COMPILE_FLAGS}")
in the CMakeLists.txt
for a target (call it "T"). But the following C code gives me no error :
bool_T DC_CompressData(int rate)
{
/* Compress data */
...
/* Forget return statement because I am absent-minded */
}
This code is in a C-file that belongs to target A, which is linked to target B, which is linked to target T where I originally set the flags. Even if I add those lines to the CMakeLists.txt
of target A, I still get no result.
CMakeLists.txt
for T
project(T VERSION 4.0 LANGUAGES C CXX)
add_library(T STATIC)
target_sources(T
PRIVATE
t.c
t.h
)
CMakeLists.txt
for B
cmake_minimum_required(VERSION 3.14 FATAL_ERROR)
project(B VERSION 4.1 LANGUAGES C CXX)
add_library(B INTERFACE)
add_subdirectory(T)
target_link_libraries(B INTERFACE T)
CMakeLists.txt
for A
cmake_minimum_required(VERSION 3.14 FATAL_ERROR)
project(A VERSION 2.0 LANGUAGES CXX)
set(TARGET ${PROJECT_NAME})
add_library(${TARGET} MODULE)
# COMPILE/LINK FLAGS
set(GCC_COVERAGE_COMPILE_FLAGS "-Wno-comment -Werror=incompatible-pointer-types -Werror=return-type")
set(GCC_COVERAGE_LINK_FLAGS "-Werror=return-type")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${GCC_COVERAGE_COMPILE_FLAGS}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${GCC_COVERAGE_COMPILE_FLAGS}")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${GCC_COVERAGE_LINK_FLAGS}")
target_link_libraries(${TARGET}
PRIVATE
A::A
install(TARGETS ${TARGET} LIBRARY DESTINATION ${INSTALLATION_PATH}
COMPONENT ${TARGET})
I use Qt Creator 4.9.2 and use the "Deploy" command in order to build & install & whatever else CMake does.
I am mostly new to CMake, so what am I doing wrong ? Could it be that g++
is called instead of gcc
, even though this is a C file ? I mention this because other files in other target (in T) are C++ files. Would I then need to set the flagsfor g++
?