Skip to content

Commit 4232fe6

Browse files
committed
Refactor warnings and extra args cache variables
1 parent f90e3f7 commit 4232fe6

File tree

3 files changed

+32
-22
lines changed

3 files changed

+32
-22
lines changed

CMakeLists.txt

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -202,13 +202,23 @@ option(ECAL_INSTALL_SAMPLE_SOURCES "Install the sources of eCAL
202202
option(ECAL_USE_NPCAP "Enable the eCAL Npcap Receiver (i.e. the Win10 performance fix)" OFF)
203203
option(ECAL_USE_CLOCKLOCK_MUTEX "Use native mutex with monotonic clock (requires glibc >= 2.30)" OFF)
204204

205-
set(ECAL_EXTRA_COMPILER_ARGS "" CACHE STRING "; separated list of additional compiler arguments to use for eCAL code")
206-
include(./cmake/helper_functions/ecal_compiler_warnings.cmake)
205+
206+
# Compiler warnings and additional flag configuration
207+
include(${CMAKE_CURRENT_LIST_DIR}/cmake/helper_functions/ecal_compiler_warnings.cmake)
207208
ecal_get_default_compiler_warnings(ecal_default_warnings)
208-
list(APPEND ecal_default_warnings ${ECAL_EXTRA_COMPILER_ARGS})
209-
set(ECAL_COMPILER_WARNINGS "${ecal_default_warnings}" CACHE STRING "Warning flags used for eCAL code")
209+
210+
set(ECAL_COMPILER_WARNINGS "${ecal_default_warnings}" CACHE STRING "List of warning flags for eCAL code")
210211
mark_as_advanced(FORCE ECAL_COMPILER_WARNINGS)
211212

213+
set(ECAL_COMPILER_EXTRA_ARGS "" CACHE STRING "List of additional compiler arguments for eCAL code")
214+
mark_as_advanced(FORCE ECAL_COMPILER_EXTRA_ARGS)
215+
216+
# Internal cache variable combining the warning and extra flags
217+
set(ECAL_COMPILER_ARGS
218+
${ECAL_COMPILER_WARNINGS} ${ECAL_COMPILER_EXTRA_ARGS}
219+
CACHE INTERNAL "Compiler flags used for eCAL code" FORCE
220+
)
221+
212222
# --------------------------------------------------------
213223
# ecal core configuration
214224
# --------------------------------------------------------

cmake/helper_functions/ecal_add_functions.cmake

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,14 @@
1919
include_guard(GLOBAL)
2020

2121
# ECAL_COMPILER_WARNINGS is set by the root CMakeLists and may be user customized
22-
add_library(_ecal_warnings INTERFACE)
23-
target_compile_options(_ecal_warnings INTERFACE
24-
"$<$<COMPILE_LANGUAGE:C,CXX>:${ECAL_COMPILER_WARNINGS}>"
22+
add_library(_ecal_compiler_args INTERFACE)
23+
target_compile_options(_ecal_compiler_args INTERFACE
24+
"$<$<COMPILE_LANGUAGE:C,CXX>:${ECAL_COMPILER_ARGS}>"
2525
)
2626

27-
function(ecal_add_compiler_warnings TARGET_NAME)
27+
function(ecal_add_compiler_flags TARGET_NAME)
2828
target_link_libraries("${TARGET_NAME}" PRIVATE
29-
"$<BUILD_INTERFACE:_ecal_warnings>"
29+
"$<BUILD_INTERFACE:_ecal_compiler_args>"
3030
)
3131
endfunction()
3232

@@ -38,7 +38,7 @@ function(ecal_add_app_console TARGET_NAME)
3838
VERSION ${eCAL_VERSION_STRING}
3939
SOVERSION ${eCAL_VERSION_MAJOR}
4040
OUTPUT_NAME ecal_${TARGET_NAME})
41-
ecal_add_compiler_warnings(${TARGET_NAME})
41+
ecal_add_compiler_flags(${TARGET_NAME})
4242
endfunction()
4343

4444
# This helper function automatically adds a gtest to ecal.
@@ -65,7 +65,7 @@ function(ecal_add_gtest TARGET_NAME)
6565
VERSION ${eCAL_VERSION_STRING}
6666
SOVERSION ${eCAL_VERSION_MAJOR}
6767
OUTPUT_NAME ecal_${TARGET_NAME})
68-
ecal_add_compiler_warnings(${TARGET_NAME})
68+
ecal_add_compiler_flags(${TARGET_NAME})
6969
endfunction()
7070

7171
function(ecal_add_app_gui TARGET_NAME)
@@ -75,7 +75,7 @@ function(ecal_add_app_gui TARGET_NAME)
7575
VERSION ${eCAL_VERSION_STRING}
7676
SOVERSION ${eCAL_VERSION_MAJOR}
7777
OUTPUT_NAME ecal_${TARGET_NAME})
78-
ecal_add_compiler_warnings(${TARGET_NAME})
78+
ecal_add_compiler_flags(${TARGET_NAME})
7979
endfunction()
8080

8181
function(ecal_add_app_qt TARGET_NAME)
@@ -87,7 +87,7 @@ function(ecal_add_app_qt TARGET_NAME)
8787
if(WIN32)
8888
set_target_properties(${PROJECT_NAME} PROPERTIES LINK_FLAGS "/SUBSYSTEM:WINDOWS /ENTRY:mainCRTStartup")
8989
endif()
90-
ecal_add_compiler_warnings(${TARGET_NAME})
90+
ecal_add_compiler_flags(${TARGET_NAME})
9191
endfunction()
9292

9393
function(ecal_add_mon_plugin TARGET_NAME)
@@ -112,7 +112,7 @@ function(ecal_add_mon_plugin TARGET_NAME)
112112
$<$<CONFIG:RelWithDebInfo>:QT_NO_DEBUG>
113113
$<$<CONFIG:MinSizeRel>:QT_NO_DEBUG>
114114
)
115-
ecal_add_compiler_warnings(${TARGET_NAME})
115+
ecal_add_compiler_flags(${TARGET_NAME})
116116
endfunction()
117117

118118
function(ecal_add_rec_addon TARGET_NAME)
@@ -123,7 +123,7 @@ function(ecal_add_rec_addon TARGET_NAME)
123123
OUTPUT_NAME ecal_${TARGET_NAME}
124124
RUNTIME_OUTPUT_DIRECTORY $<IF:$<BOOL:${WIN32}>,${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/$<CONFIG>/ecalrec_addons,${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/ecal/addons/rec>
125125
)
126-
ecal_add_compiler_warnings(${TARGET_NAME})
126+
ecal_add_compiler_flags(${TARGET_NAME})
127127
endfunction()
128128

129129
function(ecal_add_time_plugin TARGET_NAME)
@@ -132,7 +132,7 @@ function(ecal_add_time_plugin TARGET_NAME)
132132
VERSION ${eCAL_VERSION_STRING}
133133
SOVERSION ${eCAL_VERSION_MAJOR}
134134
)
135-
ecal_add_compiler_warnings(${TARGET_NAME})
135+
ecal_add_compiler_flags(${TARGET_NAME})
136136
endfunction()
137137

138138
function(ecal_add_shared_library TARGET_NAME)
@@ -141,7 +141,7 @@ function(ecal_add_shared_library TARGET_NAME)
141141
VERSION ${eCAL_VERSION_STRING}
142142
SOVERSION ${eCAL_VERSION_MAJOR}
143143
OUTPUT_NAME ecal_${TARGET_NAME})
144-
ecal_add_compiler_warnings(${TARGET_NAME})
144+
ecal_add_compiler_flags(${TARGET_NAME})
145145
endfunction()
146146

147147
function(ecal_add_static_library TARGET_NAME)
@@ -152,7 +152,7 @@ function(ecal_add_static_library TARGET_NAME)
152152
OUTPUT_NAME ecal_${TARGET_NAME}
153153
POSITION_INDEPENDENT_CODE ON
154154
)
155-
ecal_add_compiler_warnings(${TARGET_NAME})
155+
ecal_add_compiler_flags(${TARGET_NAME})
156156
endfunction()
157157

158158
function(ecal_add_interface_library TARGET_NAME)
@@ -173,6 +173,6 @@ function(ecal_add_sample TARGET_NAME)
173173
VERSION ${eCAL_VERSION_STRING}
174174
SOVERSION ${eCAL_VERSION_MAJOR}
175175
OUTPUT_NAME ecal_sample_${TARGET_NAME})
176-
ecal_add_compiler_warnings(${TARGET_NAME})
176+
ecal_add_compiler_flags(${TARGET_NAME})
177177
endfunction()
178178

ecal/service/CMakeLists.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@
1919
cmake_minimum_required(VERSION 3.16)
2020
project(ecal_service)
2121

22-
if(TARGET _ecal_warnings)
23-
# _ecal_warnings is the internal eCAL target containing the warning flags
22+
if(TARGET _ecal_compiler_args)
23+
# _ecal_compiler_args is the internal eCAL target containing the warning flags
2424
# and will be absent if this is being built standalone
25-
add_library(_ecal_service_warnings ALIAS _ecal_warnings)
25+
add_library(_ecal_service_warnings ALIAS _ecal_compiler_args)
2626
else()
2727
# Otherwise, use a fallback implementation
2828
if("${CMAKE_CXX_COMPILER_ID}" MATCHES "MSVC")

0 commit comments

Comments
 (0)