From a27d9508e24b64805a808e1438663bcc1fa08654 Mon Sep 17 00:00:00 2001 From: akallabeth Date: Thu, 24 Oct 2024 16:27:07 +0200 Subject: [PATCH] [cmake] unify CFLAGS to string * move to common CMake function * escape CFLAGS --- cmake/CFlagsToVar.cmake | 11 +++++++++++ include/CMakeLists.txt | 7 ++----- uwac/templates/CMakeLists.txt | 7 ++----- winpr/include/CMakeLists.txt | 7 ++----- 4 files changed, 17 insertions(+), 15 deletions(-) create mode 100644 cmake/CFlagsToVar.cmake diff --git a/cmake/CFlagsToVar.cmake b/cmake/CFlagsToVar.cmake new file mode 100644 index 000000000..67c899d47 --- /dev/null +++ b/cmake/CFlagsToVar.cmake @@ -0,0 +1,11 @@ +function(CFlagsToVar NAME) + set(C_FLAGS ${CMAKE_C_FLAGS}) + if (CMAKE_BUILD_TYPE) + string(TOUPPER "${CMAKE_BUILD_TYPE}" CAPS_BUILD_TYPE) + string(APPEND C_FLAGS " ${CMAKE_C_FLAGS_${CAPS_BUILD_TYPE}}") + endif() + string(REPLACE "\$" "\\\$" C_FLAGS "${C_FLAGS}") + string(REPLACE "\"" "\\\"" C_FLAGS "${C_FLAGS}") + set(${NAME} ${C_FLAGS} PARENT_SCOPE) +endfunction() + diff --git a/include/CMakeLists.txt b/include/CMakeLists.txt index b43b5bb9e..cc387246b 100644 --- a/include/CMakeLists.txt +++ b/include/CMakeLists.txt @@ -38,11 +38,8 @@ if (WIN32) string(REPLACE "\\" "\\\\" NATIVE_FREERDP_PROXY_PLUGINDIR "${NATIVE_FREERDP_PROXY_PLUGINDIR}") endif() -set(C_FLAGS ${CMAKE_C_FLAGS}) -if (CMAKE_BUILD_TYPE) - string(TOUPPER "${CMAKE_BUILD_TYPE}" CAPS_BUILD_TYPE) - string(APPEND C_FLAGS " ${CMAKE_C_FLAGS_${CAPS_BUILD_TYPE}}") -endif() +include(CFlagsToVar) +CFlagsToVar(C_FLAGS) cleaning_configure_file(${CMAKE_CURRENT_SOURCE_DIR}/config/version.h.in ${CMAKE_CURRENT_BINARY_DIR}/freerdp/version.h) cleaning_configure_file(${CMAKE_CURRENT_SOURCE_DIR}/config/build-config.h.in ${CMAKE_CURRENT_BINARY_DIR}/freerdp/build-config.h) diff --git a/uwac/templates/CMakeLists.txt b/uwac/templates/CMakeLists.txt index 884fc6d5d..02e0503c1 100644 --- a/uwac/templates/CMakeLists.txt +++ b/uwac/templates/CMakeLists.txt @@ -33,11 +33,8 @@ FOREACH(var ${res}) ENDIF() ENDFOREACH() -set(C_FLAGS ${CMAKE_C_FLAGS}) -if (CMAKE_BUILD_TYPE) - string(TOUPPER "${CMAKE_BUILD_TYPE}" CAPS_BUILD_TYPE) - string(APPEND C_FLAGS " ${CMAKE_C_FLAGS_${CAPS_BUILD_TYPE}}") -endif() +include(CFlagsToVar) +CFlagsToVar(C_FLAGS) string(REPLACE ";" " " UWAC_BUILD_CONFIG "${UWAC_BUILD_CONFIG_LIST}") cleaning_configure_file(version.h.in ${CMAKE_CURRENT_BINARY_DIR}/../include/uwac/version.h) diff --git a/winpr/include/CMakeLists.txt b/winpr/include/CMakeLists.txt index 0717d20d3..ec8fad0ac 100644 --- a/winpr/include/CMakeLists.txt +++ b/winpr/include/CMakeLists.txt @@ -15,11 +15,8 @@ # See the License for the specific language governing permissions and # limitations under the License. -set(C_FLAGS ${CMAKE_C_FLAGS}) -if (CMAKE_BUILD_TYPE) - string(TOUPPER "${CMAKE_BUILD_TYPE}" CAPS_BUILD_TYPE) - string(APPEND C_FLAGS " ${CMAKE_C_FLAGS_${CAPS_BUILD_TYPE}}") -endif() +include(CFlagsToVar) +CFlagsToVar(C_FLAGS) cleaning_configure_file(config/version.h.in ${CMAKE_CURRENT_BINARY_DIR}/winpr/version.h) cleaning_configure_file(config/wtypes.h.in ${CMAKE_CURRENT_BINARY_DIR}/winpr/wtypes.h)