Reputation: 50717
I am aware of how to suppress compile warnings with CMake by doing (suppose I want to disable compile warning C4819
):
set_target_properties(${PROJECT_NAME} PROPERTIES COMPILE_FLAGS "/wd4819")
So how to suppress link warnings with CMake (say LNK4099
)?
Upvotes: 14
Views: 21860
Reputation: 15237
Another way to ignore linker warnings for all the targets in the current scope in CMake is by settings CMAKE_EXE_LINKER_FLAGS
, CMAKE_SHARED_LINKER_FLAGS
, CMAKE_STATIC_LINKER_FLAGS
as it follows:
# Ignore warnings about missing pdb
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /ignore:4099")
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} /ignore:4099")
set(CMAKE_STATIC_LINKER_FLAGS "${CMAKE_STATIC_LINKER_FLAGS} /ignore:4099")
It also exists a CMAKE_MODULE_LINKER_FLAGS
, but it seems not related to C++ projects.
Upvotes: 3
Reputation: 41
In case your library depends on some another library that doesn't have PDBs, you may want to add ignore flag only once instead of adding it to each executable. Consider the following:
add_library(my_lib my_lib.cpp)
find_library(EXT_LIBRARY no_pdb.lib REQUIRED)
target_link_libraries(my_lib PUBLIC ${EXT_LIBRARY})
add_executable(my_exe1 "src/exe1.cpp")
target_link_libraries(my_exe1 PUBLIC my_lib)
add_executable(my_exe2 "src/exe2.cpp")
target_link_libraries(my_exe2 PUBLIC my_lib)
So now both my_exe1
and my_exe2
cause LNK4099
error. To fix this, instead of doing this on the executable level like this:
set_target_properties(my_exe1 PROPERTIES LINK_FLAGS "/ignore:4099")
set_target_properties(my_exe2 PROPERTIES LINK_FLAGS "/ignore:4099")
You may want to add ignore flag to your library's interface only once:
target_link_options(my_lib INTERFACE "/ignore:4099")
Upvotes: 1
Reputation: 21564
Try this:
set_target_properties(${PROJECT_NAME} PROPERTIES LINK_FLAGS "/ignore:4099")
It worked perfectly for me with Visual Studio 2015.
Upvotes: 22