diff --git a/CMakeLists.txt b/CMakeLists.txt index 64d3360ed8..9a7278f079 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -202,6 +202,23 @@ option(ECAL_INSTALL_SAMPLE_SOURCES "Install the sources of eCAL option(ECAL_USE_NPCAP "Enable the eCAL Npcap Receiver (i.e. the Win10 performance fix)" OFF) option(ECAL_USE_CLOCKLOCK_MUTEX "Use native mutex with monotonic clock (requires glibc >= 2.30)" OFF) + +# Compiler warnings and additional flag configuration +include(${CMAKE_CURRENT_LIST_DIR}/cmake/helper_functions/ecal_compiler_warnings.cmake) +ecal_get_default_compiler_warnings(ecal_default_warnings) + +set(ECAL_COMPILER_WARNINGS "${ecal_default_warnings}" CACHE STRING "List of warning flags for eCAL code") +mark_as_advanced(FORCE ECAL_COMPILER_WARNINGS) + +set(ECAL_COMPILER_EXTRA_ARGS "" CACHE STRING "List of additional compiler arguments for eCAL code") +mark_as_advanced(FORCE ECAL_COMPILER_EXTRA_ARGS) + +# Internal cache variable combining the warning and extra flags +set(ECAL_COMPILER_ARGS + ${ECAL_COMPILER_WARNINGS} ${ECAL_COMPILER_EXTRA_ARGS} + CACHE INTERNAL "Compiler flags used for eCAL code" FORCE +) + # -------------------------------------------------------- # ecal core configuration # -------------------------------------------------------- @@ -587,7 +604,6 @@ 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 diff --git a/app/mon/mon_plugins/monitor_tree_view/CMakeLists.txt b/app/mon/mon_plugins/monitor_tree_view/CMakeLists.txt index 2e86602c2c..8079e8e3fd 100644 --- a/app/mon/mon_plugins/monitor_tree_view/CMakeLists.txt +++ b/app/mon/mon_plugins/monitor_tree_view/CMakeLists.txt @@ -37,12 +37,12 @@ set(source_files set(CMAKE_AUTOMOC ON) -add_library(${PROJECT_NAME} ${source_files}) +ecal_add_library(${PROJECT_NAME} ${source_files}) add_library(eCAL::${PROJECT_NAME} ALIAS ${PROJECT_NAME}) target_include_directories(${PROJECT_NAME} PUBLIC src) -target_link_libraries(${PROJECT_NAME} +target_link_libraries(${PROJECT_NAME} PUBLIC Qt${QT_VERSION_MAJOR}::Core Qt${QT_VERSION_MAJOR}::Widgets CustomQt diff --git a/app/play/play_core/CMakeLists.txt b/app/play/play_core/CMakeLists.txt index b978dcca9c..ff1116394c 100644 --- a/app/play/play_core/CMakeLists.txt +++ b/app/play/play_core/CMakeLists.txt @@ -43,7 +43,7 @@ set(source_files src/measurement_container.h ) -add_library(${PROJECT_NAME} ${source_files}) +ecal_add_library(${PROJECT_NAME} ${source_files}) add_library(eCAL::${PROJECT_NAME} ALIAS ${PROJECT_NAME}) target_include_directories(${PROJECT_NAME} PRIVATE src) diff --git a/app/rec/rec_client_core/CMakeLists.txt b/app/rec/rec_client_core/CMakeLists.txt index e6b2aaf07d..2f7dadb560 100644 --- a/app/rec/rec_client_core/CMakeLists.txt +++ b/app/rec/rec_client_core/CMakeLists.txt @@ -78,7 +78,7 @@ if (ECAL_USE_CURL) ) endif() -add_library (${PROJECT_NAME} ${source_files}) +ecal_add_library (${PROJECT_NAME} ${source_files}) add_library (eCAL::${PROJECT_NAME} ALIAS ${PROJECT_NAME}) target_include_directories(${PROJECT_NAME} PRIVATE src) diff --git a/app/rec/rec_server_core/CMakeLists.txt b/app/rec/rec_server_core/CMakeLists.txt index 8092dc0a1e..8d31390ca5 100644 --- a/app/rec/rec_server_core/CMakeLists.txt +++ b/app/rec/rec_server_core/CMakeLists.txt @@ -56,7 +56,7 @@ set(source_files src/recorder/remote_recorder.h ) -add_library (${PROJECT_NAME} ${source_files}) +ecal_add_library (${PROJECT_NAME} ${source_files}) add_library (eCAL::${PROJECT_NAME} ALIAS ${PROJECT_NAME}) target_include_directories(${PROJECT_NAME} PRIVATE src) diff --git a/app/sys/sys_cli/CMakeLists.txt b/app/sys/sys_cli/CMakeLists.txt index bdc1929246..405f585986 100644 --- a/app/sys/sys_cli/CMakeLists.txt +++ b/app/sys/sys_cli/CMakeLists.txt @@ -77,6 +77,7 @@ target_link_libraries(${PROJECT_NAME} PRIVATE protobuf::libprotobuf CustomTclap eCAL::core_pb + eCAL::protobuf_core ) target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_14) diff --git a/app/sys/sys_client_core/CMakeLists.txt b/app/sys/sys_client_core/CMakeLists.txt index 47d703ef44..93ee57bc30 100644 --- a/app/sys/sys_client_core/CMakeLists.txt +++ b/app/sys/sys_client_core/CMakeLists.txt @@ -34,7 +34,7 @@ set(source_files src/task.cpp ) -add_library (${PROJECT_NAME} ${source_files}) +ecal_add_library (${PROJECT_NAME} ${source_files}) add_library (eCAL::${PROJECT_NAME} ALIAS ${PROJECT_NAME}) target_include_directories(${PROJECT_NAME} PRIVATE src) diff --git a/app/sys/sys_core/CMakeLists.txt b/app/sys/sys_core/CMakeLists.txt index 9ad5abd70e..ef48c460ad 100644 --- a/app/sys/sys_core/CMakeLists.txt +++ b/app/sys/sys_core/CMakeLists.txt @@ -74,7 +74,7 @@ set(ecalsyscore_src src/task/task_group.cpp ) -add_library(${PROJECT_NAME} ${ecalsyscore_src}) +ecal_add_library(${PROJECT_NAME} ${ecalsyscore_src}) add_library(eCAL::${PROJECT_NAME} ALIAS ${PROJECT_NAME}) target_include_directories(${PROJECT_NAME} @@ -87,16 +87,19 @@ target_compile_definitions(${PROJECT_NAME} create_targets_protobuf() target_link_libraries(${PROJECT_NAME} + PUBLIC + eCAL::core + spdlog::spdlog + eCAL::sys_client_core + eCAL::core_pb + eCAL::app_pb + eCAL::ecal-utils + PRIVATE Threads::Threads tinyxml2::tinyxml2 - spdlog::spdlog protobuf::libprotobuf eCAL::protobuf_core - eCAL::core_pb - eCAL::app_pb EcalParser - eCAL::sys_client_core - eCAL::ecal-utils ) target_compile_features(${PROJECT_NAME} PUBLIC cxx_std_14) diff --git a/app/sys/sys_gui/CMakeLists.txt b/app/sys/sys_gui/CMakeLists.txt index 7b66f7822b..91c2dd5432 100644 --- a/app/sys/sys_gui/CMakeLists.txt +++ b/app/sys/sys_gui/CMakeLists.txt @@ -181,6 +181,7 @@ target_link_libraries (${PROJECT_NAME} PRIVATE CustomTclap tclap::tclap eCAL::core + eCAL::protobuf_core eCAL::sys_core protobuf::libprotobuf EcalParser diff --git a/cmake/helper_functions/ecal_add_functions.cmake b/cmake/helper_functions/ecal_add_functions.cmake index 089c46c5ff..65a2105349 100644 --- a/cmake/helper_functions/ecal_add_functions.cmake +++ b/cmake/helper_functions/ecal_add_functions.cmake @@ -18,7 +18,17 @@ include_guard(GLOBAL) -include("${CMAKE_CURRENT_LIST_DIR}/ecal_compiler_warnings.cmake") +# ECAL_COMPILER_WARNINGS is set by the root CMakeLists and may be user customized +add_library(_ecal_compiler_args INTERFACE) +target_compile_options(_ecal_compiler_args INTERFACE + "$<$:${ECAL_COMPILER_ARGS}>" +) + +function(ecal_add_compiler_flags TARGET_NAME) + target_link_libraries("${TARGET_NAME}" PRIVATE + "$" + ) +endfunction() # This function will set the output names of the target according to eCAL conventions. function(ecal_add_app_console TARGET_NAME) @@ -28,7 +38,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}) + ecal_add_compiler_flags(${TARGET_NAME}) endfunction() # This helper function automatically adds a gtest to ecal. @@ -55,7 +65,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}) + ecal_add_compiler_flags(${TARGET_NAME}) endfunction() function(ecal_add_app_gui TARGET_NAME) @@ -65,7 +75,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}) + ecal_add_compiler_flags(${TARGET_NAME}) endfunction() function(ecal_add_app_qt TARGET_NAME) @@ -77,7 +87,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}) + ecal_add_compiler_flags(${TARGET_NAME}) endfunction() function(ecal_add_mon_plugin TARGET_NAME) @@ -102,7 +112,7 @@ function(ecal_add_mon_plugin TARGET_NAME) $<$:QT_NO_DEBUG> $<$:QT_NO_DEBUG> ) - ecal_add_compiler_warnings(${TARGET_NAME}) + ecal_add_compiler_flags(${TARGET_NAME}) endfunction() function(ecal_add_rec_addon TARGET_NAME) @@ -113,7 +123,7 @@ function(ecal_add_rec_addon TARGET_NAME) OUTPUT_NAME ecal_${TARGET_NAME} RUNTIME_OUTPUT_DIRECTORY $,${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/$/ecalrec_addons,${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/ecal/addons/rec> ) - ecal_add_compiler_warnings(${TARGET_NAME}) + ecal_add_compiler_flags(${TARGET_NAME}) endfunction() function(ecal_add_time_plugin TARGET_NAME) @@ -122,7 +132,7 @@ function(ecal_add_time_plugin TARGET_NAME) VERSION ${eCAL_VERSION_STRING} SOVERSION ${eCAL_VERSION_MAJOR} ) - ecal_add_compiler_warnings(${TARGET_NAME}) + ecal_add_compiler_flags(${TARGET_NAME}) endfunction() function(ecal_add_shared_library TARGET_NAME) @@ -131,7 +141,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}) + ecal_add_compiler_flags(${TARGET_NAME}) endfunction() function(ecal_add_static_library TARGET_NAME) @@ -142,7 +152,7 @@ function(ecal_add_static_library TARGET_NAME) OUTPUT_NAME ecal_${TARGET_NAME} POSITION_INDEPENDENT_CODE ON ) - ecal_add_compiler_warnings(${TARGET_NAME}) + ecal_add_compiler_flags(${TARGET_NAME}) endfunction() function(ecal_add_interface_library TARGET_NAME) @@ -163,6 +173,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}) + ecal_add_compiler_flags(${TARGET_NAME}) endfunction() diff --git a/cmake/helper_functions/ecal_compiler_warnings.cmake b/cmake/helper_functions/ecal_compiler_warnings.cmake index dc657e3e0c..e992a1c120 100644 --- a/cmake/helper_functions/ecal_compiler_warnings.cmake +++ b/cmake/helper_functions/ecal_compiler_warnings.cmake @@ -1,27 +1,17 @@ include_guard(GLOBAL) -add_library(_ecal_warnings INTERFACE) +function(ecal_get_default_compiler_warnings cxx_out_var) + set(cxx_compiler_flags "") -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() -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 - "$<$:${cxx_compiler_flags}>" -) - -unset(cxx_compiler_flags) - -function(ecal_add_compiler_warnings TARGET_NAME) - target_link_libraries("${TARGET_NAME}" PRIVATE - "$" - ) + set("${cxx_out_var}" "${cxx_compiler_flags}" PARENT_SCOPE) endfunction() diff --git a/contrib/measurement/base/CMakeLists.txt b/contrib/measurement/base/CMakeLists.txt index b6be8282f7..9ecfc62306 100644 --- a/contrib/measurement/base/CMakeLists.txt +++ b/contrib/measurement/base/CMakeLists.txt @@ -21,7 +21,7 @@ project(measurement) ################################### # Base Measurement common headers # ################################### -add_library(measurement_base INTERFACE) +ecal_add_interface_library(measurement_base) add_library(eCAL::measurement_base ALIAS measurement_base) target_sources(measurement_base @@ -49,7 +49,7 @@ install( ################################### # Measurement library # ################################### -add_library(measurement INTERFACE) +ecal_add_interface_library(measurement) add_library(eCAL::measurement ALIAS measurement) target_sources(measurement diff --git a/contrib/measurement/hdf5/CMakeLists.txt b/contrib/measurement/hdf5/CMakeLists.txt index 209d68daaa..efcabb3be1 100644 --- a/contrib/measurement/hdf5/CMakeLists.txt +++ b/contrib/measurement/hdf5/CMakeLists.txt @@ -18,7 +18,7 @@ project(measurement_hdf5) -add_library(${PROJECT_NAME} +ecal_add_library(${PROJECT_NAME} include/ecal/measurement/hdf5/reader.h include/ecal/measurement/hdf5/writer.h src/reader.cpp diff --git a/ecal/service/CMakeLists.txt b/ecal/service/CMakeLists.txt index 8743239f47..9a1a2bdf16 100644 --- a/ecal/service/CMakeLists.txt +++ b/ecal/service/CMakeLists.txt @@ -19,6 +19,25 @@ cmake_minimum_required(VERSION 3.16) project(ecal_service) +if(TARGET _ecal_compiler_args) + # _ecal_compiler_args is the internal eCAL target containing the warning flags + # and will be absent if this is being built standalone + add_library(_ecal_service_warnings ALIAS _ecal_compiler_args) +else() + # Otherwise, use a fallback implementation + if("${CMAKE_CXX_COMPILER_ID}" MATCHES "MSVC") + set(cxx_compiler_flags "/MP" "/W4") + elseif("${CMAKE_CXX_COMPILER_ID}" MATCHES "GNU|Clang") + set(cxx_compiler_flags "-Wall" "-Wextra") + else() + message(WARNING "Unknown compiler, will not set warning flags") + endif() + + set(ECAL_SERVICE_COMPILER_WARNINGS "${cxx_compiler_flags}" CACHE STRING "Warning flags used for eCAL service code") + add_library(_ecal_service_warnings INTERFACE) + target_compile_options(_ecal_service_warnings INTERFACE "${ECAL_SERVICE_COMPILER_WARNINGS}") +endif() + # Main library add_subdirectory(ecal_service) diff --git a/ecal/service/ecal_service/CMakeLists.txt b/ecal/service/ecal_service/CMakeLists.txt index f4b20103c0..87f26a32a0 100644 --- a/ecal/service/ecal_service/CMakeLists.txt +++ b/ecal/service/ecal_service/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.5.1) +cmake_minimum_required(VERSION 3.16) project(ecal_service) @@ -61,6 +61,7 @@ target_link_libraries(${PROJECT_NAME} Threads::Threads $<$:ws2_32> $<$:wsock32> + _ecal_service_warnings ) @@ -72,12 +73,6 @@ target_compile_definitions(${PROJECT_NAME} target_compile_features(${PROJECT_NAME} PUBLIC cxx_std_14) -target_compile_options(${PROJECT_NAME} PRIVATE - $<$,$,$>: - -Wall -Wextra> - $<$: - /W4>) - # Add own public include directory target_include_directories(${PROJECT_NAME} PUBLIC diff --git a/ecal/service/samples/sample_client/CMakeLists.txt b/ecal/service/samples/sample_client/CMakeLists.txt index 90c4cd4a67..240b994333 100644 --- a/ecal/service/samples/sample_client/CMakeLists.txt +++ b/ecal/service/samples/sample_client/CMakeLists.txt @@ -28,7 +28,9 @@ add_executable(${PROJECT_NAME} ${sources}) target_link_libraries(${PROJECT_NAME} PRIVATE - ecal_service) + ecal_service + _ecal_service_warnings +) target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_14) diff --git a/ecal/service/samples/sample_server/CMakeLists.txt b/ecal/service/samples/sample_server/CMakeLists.txt index ffeca863a7..8ab0f4b92c 100644 --- a/ecal/service/samples/sample_server/CMakeLists.txt +++ b/ecal/service/samples/sample_server/CMakeLists.txt @@ -28,7 +28,9 @@ add_executable(${PROJECT_NAME} ${sources}) target_link_libraries(${PROJECT_NAME} PRIVATE - ecal_service) + ecal_service + _ecal_service_warnings +) target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_14) diff --git a/ecal/service/samples/sample_standalone/CMakeLists.txt b/ecal/service/samples/sample_standalone/CMakeLists.txt index 0806b506a7..8896fbc7c6 100644 --- a/ecal/service/samples/sample_standalone/CMakeLists.txt +++ b/ecal/service/samples/sample_standalone/CMakeLists.txt @@ -28,7 +28,9 @@ add_executable(${PROJECT_NAME} ${sources}) target_link_libraries(${PROJECT_NAME} PRIVATE - ecal_service) + ecal_service + _ecal_service_warnings +) target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_14) diff --git a/lib/EcalParser/CMakeLists.txt b/lib/EcalParser/CMakeLists.txt index 92ede4c3c3..5af7ae8dbf 100644 --- a/lib/EcalParser/CMakeLists.txt +++ b/lib/EcalParser/CMakeLists.txt @@ -42,7 +42,7 @@ set(sources src/functions/username.h ) -# QEcalParser is an internal implementation detail for applications so it can +# EcalParser is an internal implementation detail for applications so it can # always be static and not installed/exported ecal_add_static_library(${PROJECT_NAME} ${includes}