Skip to content

Commit

Permalink
[cmake] Create explicit warnings target (#1948)
Browse files Browse the repository at this point in the history
* Add ecal warnings target; use keyword target_link_libraries
  • Loading branch information
DownerCase authored Jan 27, 2025
1 parent ce3d715 commit 8c2f54d
Show file tree
Hide file tree
Showing 75 changed files with 125 additions and 79 deletions.
1 change: 1 addition & 0 deletions .github/workflows/build-windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ jobs:
# --------------------------------------------------------------------------------------------------

sign-windows-installer:
if: github.repository == 'eclipse-ecal/ecal'
runs-on: windows-2019
needs: build-windows

Expand Down
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -495,6 +495,7 @@ install(FILES ${eCAL_config} ${eCAL_config_version}

install(FILES
cmake/helper_functions/ecal_add_functions.cmake
cmake/helper_functions/ecal_compiler_warnings.cmake
cmake/helper_functions/ecal_helper_functions.cmake
cmake/helper_functions/ecal_install_functions.cmake
DESTINATION ${${PROJECT_NAME}_install_cmake_dir}/helper_functions
Expand Down
2 changes: 1 addition & 1 deletion app/app_pb/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ target_compile_options(${PROJECT_NAME}

set_property(TARGET ${PROJECT_NAME} PROPERTY POSITION_INDEPENDENT_CODE ON)

target_link_libraries(${PROJECT_NAME} protobuf::libprotobuf)
target_link_libraries(${PROJECT_NAME} PUBLIC protobuf::libprotobuf)
target_compile_features(${PROJECT_NAME} PUBLIC cxx_std_14)

ecal_install_library(${PROJECT_NAME})
Expand Down
12 changes: 7 additions & 5 deletions app/meas_cutter/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,13 @@ ecal_add_app_console(${PROJECT_NAME} ${meas_cutter_src})
target_include_directories(${PROJECT_NAME}
PRIVATE $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>)

target_link_libraries(${PROJECT_NAME} yaml-cpp::yaml-cpp
tclap::tclap
eCAL::ecal-utils
eCAL::hdf5
Threads::Threads)
target_link_libraries(${PROJECT_NAME} PRIVATE
yaml-cpp::yaml-cpp
tclap::tclap
eCAL::ecal-utils
eCAL::hdf5
Threads::Threads
)

target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_14)

Expand Down
2 changes: 1 addition & 1 deletion app/mon/mon_cli/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ target_compile_definitions(${PROJECT_NAME}

create_targets_protobuf()

target_link_libraries(${PROJECT_NAME}
target_link_libraries(${PROJECT_NAME} PRIVATE
tclap::tclap
eCAL::protobuf_core
eCAL::string_core
Expand Down
4 changes: 2 additions & 2 deletions app/mon/mon_gui/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ ecal_add_app_qt(${PROJECT_NAME}
${autogen_ui}
)

target_link_libraries (${PROJECT_NAME}
target_link_libraries (${PROJECT_NAME} PRIVATE
protobuf::libprotobuf
eCAL::core
eCAL::core_pb
Expand All @@ -209,7 +209,7 @@ target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_14)

if(ECAL_NPCAP_SUPPORT)
add_definitions(-DECAL_NPCAP_SUPPORT)
target_link_libraries(${PROJECT_NAME}
target_link_libraries(${PROJECT_NAME} PRIVATE
udpcap::udpcap
)
endif(ECAL_NPCAP_SUPPORT)
Expand Down
2 changes: 1 addition & 1 deletion app/mon/mon_plugins/capnproto_reflection/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ ecal_add_mon_plugin(${PROJECT_NAME}
METADATA src/metadata.json
)

target_link_libraries (${PROJECT_NAME}
target_link_libraries (${PROJECT_NAME} PRIVATE
Qt${QT_VERSION_MAJOR}::Core
Qt${QT_VERSION_MAJOR}::Widgets
eCAL::capnproto_core
Expand Down
2 changes: 1 addition & 1 deletion app/mon/mon_plugins/plugin_template/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ ecal_add_mon_plugin(${PROJECT_NAME}
METADATA src/metadata.json
)

target_link_libraries (${PROJECT_NAME}
target_link_libraries (${PROJECT_NAME} PRIVATE
Qt${QT_VERSION_MAJOR}::Core
Qt${QT_VERSION_MAJOR}::Widgets
eCAL::core
Expand Down
2 changes: 1 addition & 1 deletion app/mon/mon_plugins/protobuf_reflection/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ ecal_add_mon_plugin(${PROJECT_NAME}
)

create_targets_protobuf()
target_link_libraries (${PROJECT_NAME}
target_link_libraries (${PROJECT_NAME} PRIVATE
Qt${QT_VERSION_MAJOR}::Core
Qt${QT_VERSION_MAJOR}::Widgets
eCAL::protobuf_core
Expand Down
2 changes: 1 addition & 1 deletion app/mon/mon_plugins/raw_data_reflection/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ ecal_add_mon_plugin(${PROJECT_NAME}
)

create_targets_protobuf()
target_link_libraries (${PROJECT_NAME}
target_link_libraries (${PROJECT_NAME} PRIVATE
Qt${QT_VERSION_MAJOR}::Core
Qt${QT_VERSION_MAJOR}::Widgets
eCAL::core
Expand Down
2 changes: 1 addition & 1 deletion app/mon/mon_plugins/signals_plotting/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ ecal_add_mon_plugin(${PROJECT_NAME}

create_targets_protobuf()

target_link_libraries (${PROJECT_NAME}
target_link_libraries (${PROJECT_NAME} PRIVATE
Qt${QT_VERSION_MAJOR}::Core
Qt${QT_VERSION_MAJOR}::Widgets
eCAL::core
Expand Down
2 changes: 1 addition & 1 deletion app/mon/mon_plugins/string_reflection/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ ecal_add_mon_plugin(${PROJECT_NAME}
)

create_targets_protobuf()
target_link_libraries (${PROJECT_NAME}
target_link_libraries (${PROJECT_NAME} PRIVATE
Qt${QT_VERSION_MAJOR}::Core
Qt${QT_VERSION_MAJOR}::Widgets
eCAL::string_core
Expand Down
2 changes: 1 addition & 1 deletion app/mon/mon_tui/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ target_compile_definitions(${PROJECT_NAME}

create_targets_protobuf()

target_link_libraries(${PROJECT_NAME}
target_link_libraries(${PROJECT_NAME} PRIVATE
protobuf::libprotobuf
tclap::tclap
eCAL::protobuf_core
Expand Down
2 changes: 1 addition & 1 deletion app/play/play_cli/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ target_include_directories(${PROJECT_NAME} PRIVATE src)
target_compile_definitions(${PROJECT_NAME}
PRIVATE $<$<BOOL:${MSVC}>:PCRE_STATIC;_UNICODE>)

target_link_libraries(${PROJECT_NAME}
target_link_libraries(${PROJECT_NAME} PRIVATE
termcolor::termcolor
tclap::tclap
eCAL::play_core
Expand Down
2 changes: 1 addition & 1 deletion app/play/play_gui/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ ecal_add_app_qt(${PROJECT_NAME}
)

create_targets_protobuf()
target_link_libraries (${PROJECT_NAME}
target_link_libraries (${PROJECT_NAME} PRIVATE
tclap::tclap
CustomTclap
eCAL::play_core
Expand Down
4 changes: 2 additions & 2 deletions app/rec/rec_gui/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ ecal_add_app_qt(${PROJECT_NAME}
)

create_targets_protobuf()
target_link_libraries (${PROJECT_NAME}
target_link_libraries (${PROJECT_NAME} PRIVATE
tclap::tclap
protobuf::libprotobuf
eCAL::core
Expand All @@ -195,7 +195,7 @@ if (WIN32 AND (${QT_VERSION_MAJOR} EQUAL 5))
# Maybe we can re-enable the functionality with the following external lib:
# https://github.com/oblivioncth/Qx
#
target_link_libraries (${PROJECT_NAME}
target_link_libraries (${PROJECT_NAME} PRIVATE
Qt${QT_VERSION_MAJOR}::WinExtras
)
endif()
Expand Down
2 changes: 1 addition & 1 deletion app/rec/rec_server_cli/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ target_compile_definitions(${PROJECT_NAME}

create_targets_protobuf()

target_link_libraries(${PROJECT_NAME}
target_link_libraries(${PROJECT_NAME} PRIVATE
tclap::tclap
termcolor::termcolor
eCAL::rec_server_core
Expand Down
2 changes: 1 addition & 1 deletion app/sys/sys_cli/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ target_compile_definitions(${PROJECT_NAME}

create_targets_protobuf()

target_link_libraries(${PROJECT_NAME}
target_link_libraries(${PROJECT_NAME} PRIVATE
tclap::tclap
termcolor::termcolor
eCAL::sys_core
Expand Down
2 changes: 1 addition & 1 deletion app/sys/sys_client_cli/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ ecal_add_app_console(${PROJECT_NAME} ${source_files} ${win_src})

create_targets_protobuf()

target_link_libraries(${PROJECT_NAME}
target_link_libraries(${PROJECT_NAME} PRIVATE
spdlog::spdlog
tclap::tclap
protobuf::libprotobuf
Expand Down
2 changes: 1 addition & 1 deletion app/sys/sys_gui/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ ecal_add_app_qt(${PROJECT_NAME}

create_targets_protobuf()

target_link_libraries (${PROJECT_NAME}
target_link_libraries (${PROJECT_NAME} PRIVATE
Qt${QT_VERSION_MAJOR}::Core
Qt${QT_VERSION_MAJOR}::Widgets
CustomQt
Expand Down
2 changes: 1 addition & 1 deletion app/util/config/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ target_include_directories(${PROJECT_NAME}
target_compile_definitions(${PROJECT_NAME}
PRIVATE $<$<BOOL:${MSVC}>:PCRE_STATIC;_UNICODE>)

target_link_libraries(${PROJECT_NAME} eCAL::core)
target_link_libraries(${PROJECT_NAME} PRIVATE eCAL::core)
target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_14)

ecal_install_app(${PROJECT_NAME})
Expand Down
2 changes: 1 addition & 1 deletion app/util/launcher/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ ecal_add_app_qt(${PROJECT_NAME}
${autogen_ui}
)

target_link_libraries (${PROJECT_NAME}
target_link_libraries (${PROJECT_NAME} PRIVATE
Qt${QT_VERSION_MAJOR}::Core
Qt${QT_VERSION_MAJOR}::Widgets
eCAL::apps
Expand Down
2 changes: 1 addition & 1 deletion app/util/stop/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ target_include_directories(${PROJECT_NAME}
target_compile_definitions(${PROJECT_NAME}
PRIVATE $<$<BOOL:${MSVC}>:PCRE_STATIC;_UNICODE>)

target_link_libraries(${PROJECT_NAME} eCAL::core)
target_link_libraries(${PROJECT_NAME} PRIVATE eCAL::core)
target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_14)

ecal_install_app(${PROJECT_NAME})
Expand Down
16 changes: 14 additions & 2 deletions cmake/helper_functions/ecal_add_functions.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@
#
# ========================= eCAL LICENSE =================================

include_guard(GLOBAL)

include("${CMAKE_CURRENT_LIST_DIR}/ecal_compiler_warnings.cmake")

# This function will set the output names of the target according to eCAL conventions.
function(ecal_add_app_console TARGET_NAME)
add_executable(${TARGET_NAME} ${ARGN})
Expand All @@ -24,6 +28,7 @@ function(ecal_add_app_console TARGET_NAME)
VERSION ${eCAL_VERSION_STRING}
SOVERSION ${eCAL_VERSION_MAJOR}
OUTPUT_NAME ecal_${TARGET_NAME})
ecal_add_compiler_warnings(${TARGET_NAME})
endfunction()

# This helper function automatically adds a gtest to ecal.
Expand All @@ -50,6 +55,7 @@ function(ecal_add_gtest TARGET_NAME)
VERSION ${eCAL_VERSION_STRING}
SOVERSION ${eCAL_VERSION_MAJOR}
OUTPUT_NAME ecal_${TARGET_NAME})
ecal_add_compiler_warnings(${TARGET_NAME})
endfunction()

function(ecal_add_app_gui TARGET_NAME)
Expand All @@ -59,6 +65,7 @@ function(ecal_add_app_gui TARGET_NAME)
VERSION ${eCAL_VERSION_STRING}
SOVERSION ${eCAL_VERSION_MAJOR}
OUTPUT_NAME ecal_${TARGET_NAME})
ecal_add_compiler_warnings(${TARGET_NAME})
endfunction()

function(ecal_add_app_qt TARGET_NAME)
Expand All @@ -70,6 +77,7 @@ function(ecal_add_app_qt TARGET_NAME)
if(WIN32)
set_target_properties(${PROJECT_NAME} PROPERTIES LINK_FLAGS "/SUBSYSTEM:WINDOWS /ENTRY:mainCRTStartup")
endif()
ecal_add_compiler_warnings(${TARGET_NAME})
endfunction()

function(ecal_add_mon_plugin TARGET_NAME)
Expand All @@ -94,7 +102,7 @@ function(ecal_add_mon_plugin TARGET_NAME)
$<$<CONFIG:RelWithDebInfo>:QT_NO_DEBUG>
$<$<CONFIG:MinSizeRel>:QT_NO_DEBUG>
)
ecal_add_compiler_warnings(${TARGET_NAME})
endfunction()

function(ecal_add_rec_addon TARGET_NAME)
Expand All @@ -105,7 +113,7 @@ function(ecal_add_rec_addon TARGET_NAME)
OUTPUT_NAME ecal_${TARGET_NAME}
RUNTIME_OUTPUT_DIRECTORY $<IF:$<BOOL:${WIN32}>,${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/$<CONFIG>/ecalrec_addons,${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/ecal/addons/rec>
)
ecal_add_compiler_warnings(${TARGET_NAME})
endfunction()

function(ecal_add_time_plugin TARGET_NAME)
Expand All @@ -114,6 +122,7 @@ function(ecal_add_time_plugin TARGET_NAME)
VERSION ${eCAL_VERSION_STRING}
SOVERSION ${eCAL_VERSION_MAJOR}
)
ecal_add_compiler_warnings(${TARGET_NAME})
endfunction()

function(ecal_add_shared_library TARGET_NAME)
Expand All @@ -122,6 +131,7 @@ function(ecal_add_shared_library TARGET_NAME)
VERSION ${eCAL_VERSION_STRING}
SOVERSION ${eCAL_VERSION_MAJOR}
OUTPUT_NAME ecal_${TARGET_NAME})
ecal_add_compiler_warnings(${TARGET_NAME})
endfunction()

function(ecal_add_static_library TARGET_NAME)
Expand All @@ -132,6 +142,7 @@ function(ecal_add_static_library TARGET_NAME)
OUTPUT_NAME ecal_${TARGET_NAME}
POSITION_INDEPENDENT_CODE ON
)
ecal_add_compiler_warnings(${TARGET_NAME})
endfunction()

function(ecal_add_interface_library TARGET_NAME)
Expand All @@ -152,5 +163,6 @@ function(ecal_add_sample TARGET_NAME)
VERSION ${eCAL_VERSION_STRING}
SOVERSION ${eCAL_VERSION_MAJOR}
OUTPUT_NAME ecal_sample_${TARGET_NAME})
ecal_add_compiler_warnings(${TARGET_NAME})
endfunction()

27 changes: 27 additions & 0 deletions cmake/helper_functions/ecal_compiler_warnings.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
include_guard(GLOBAL)

add_library(_ecal_warnings INTERFACE)

set(cxx_compiler_flags "")

if("${CMAKE_CXX_COMPILER_ID}" MATCHES "MSVC")
message(STATUS "MSVC detected - Adding flags")
set(cxx_compiler_flags "/MP" "/W4")
elseif("${CMAKE_CXX_COMPILER_ID}" MATCHES "GNU|Clang")
message(STATUS "Setting GNU/Clang flags")
set(cxx_compiler_flags "-Wall" "-Wextra")
else()
message(WARNING "Unknown compiler, will not set warning flags")
endif()

target_compile_options(_ecal_warnings INTERFACE
"$<$<COMPILE_LANGUAGE:C,CXX>:${cxx_compiler_flags}>"
)

unset(cxx_compiler_flags)

function(ecal_add_compiler_warnings TARGET_NAME)
target_link_libraries("${TARGET_NAME}" PRIVATE
"$<BUILD_INTERFACE:_ecal_warnings>"
)
endfunction()
2 changes: 1 addition & 1 deletion contrib/ecaltime/ecaltime_pb/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ target_compile_options(${PROJECT_NAME}

set_property(TARGET ${PROJECT_NAME} PROPERTY POSITION_INDEPENDENT_CODE ON)

target_link_libraries(${PROJECT_NAME} protobuf::libprotobuf)
target_link_libraries(${PROJECT_NAME} PUBLIC protobuf::libprotobuf)
target_compile_features(${PROJECT_NAME} PUBLIC cxx_std_14)

ecal_install_library(${PROJECT_NAME})
Expand Down
2 changes: 1 addition & 1 deletion contrib/ecaltime/linuxptp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ endif()

ecal_add_time_plugin(${PROJECT_NAME} SHARED ${ecal_time_linuxptp_src} ${ecal_time_linuxptp_header})

target_link_libraries(${PROJECT_NAME} eCAL::core yaml-cpp::yaml-cpp)
target_link_libraries(${PROJECT_NAME} PRIVATE eCAL::core yaml-cpp::yaml-cpp)

target_include_directories(${PROJECT_NAME}
PRIVATE
Expand Down
2 changes: 1 addition & 1 deletion contrib/ecaltime/localtime/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ target_include_directories(${PROJECT_NAME}
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/../include>)

target_link_libraries(${PROJECT_NAME}
target_link_libraries(${PROJECT_NAME} PRIVATE
Threads::Threads
$<$<AND:$<BOOL:${UNIX}>,$<NOT:$<BOOL:${APPLE}>>,$<NOT:$<BOOL:${QNXNTO}>>>:rt>
)
Expand Down
2 changes: 1 addition & 1 deletion contrib/mma/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ target_include_directories(${PROJECT_NAME}

create_targets_protobuf()

target_link_libraries(${PROJECT_NAME}
target_link_libraries(${PROJECT_NAME} PRIVATE
Threads::Threads
eCAL::protobuf_core
eCAL::app_pb
Expand Down
2 changes: 1 addition & 1 deletion ecal/core_pb/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ target_compile_options(${PROJECT_NAME}

set_property(TARGET ${PROJECT_NAME} PROPERTY POSITION_INDEPENDENT_CODE ON)

target_link_libraries(${PROJECT_NAME} protobuf::libprotobuf)
target_link_libraries(${PROJECT_NAME} PUBLIC protobuf::libprotobuf)
target_compile_features(${PROJECT_NAME} PUBLIC cxx_std_14)

ecal_install_library(${PROJECT_NAME})
Expand Down
Loading

0 comments on commit 8c2f54d

Please sign in to comment.