From c6794757ce71013d9137de124aec759209004882 Mon Sep 17 00:00:00 2001 From: Georgiy Lebedev <g.lebedev@tarantool.org> Date: Sat, 15 Oct 2022 16:10:45 +0300 Subject: [PATCH] build: refactor passing compiler flags to dependencies e6abe1c passes compiler flags to dependencies via a `<project>_build` macro parameter, which is, firstly, inconvenient, and, secondly, as a result, not all dependencies got the required compiler flags passed: use global variables instead and pass these flags to skipped dependencies. Follow-up e6abe1c NO_CHANGELOG=refactoring NO_DOC=refactoring NO_TEST=refactoring --- CMakeLists.txt | 10 ++++++---- cmake/BuildAres.cmake | 4 ++-- cmake/BuildCDT.cmake | 2 +- cmake/BuildDecNumber.cmake | 1 + cmake/BuildLibCORO.cmake | 2 +- cmake/BuildLibCURL.cmake | 4 ++-- cmake/BuildLibEIO.cmake | 2 +- cmake/BuildLibEV.cmake | 2 +- cmake/BuildLibUnwind.cmake | 4 ++-- cmake/BuildLibXXhash.cmake | 2 +- cmake/BuildLibYAML.cmake | 3 +-- cmake/BuildMisc.cmake | 1 + cmake/BuildNghttp2.cmake | 4 ++-- cmake/BuildZSTD.cmake | 7 +++---- 14 files changed, 25 insertions(+), 23 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 1d0abf5f33..e7b3eeacb1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -88,6 +88,8 @@ if (ENABLE_HARDENING) set(HARDENING_LDFLAGS "-pie -z relro -z now") endif() add_compile_flags("C;CXX" ${HARDENING_FLAGS}) + set(DEPENDENCY_CFLAGS "${DEPENDENCY_CFLAGS} ${HARDENING_FLAGS}") + set(DEPENDENCY_CXXFLAGS "${DEPENDENCY_CXXFLAGS} ${HARDENING_FLAGS}") set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${HARDENING_LDFLAGS}") endif() @@ -458,14 +460,14 @@ option(BUNDLED_LIBCURL_USE_NGHTTP2 "Build curl with bundled nghttp2" if (ENABLE_BUNDLED_LIBCURL) if(BUNDLED_LIBCURL_USE_ARES) include(BuildAres) - ares_build(${HARDENING_FLAGS}) + ares_build() endif() if(BUNDLED_LIBCURL_USE_NGHTTP2) include(BuildNghttp2) - nghttp2_build(${HARDENING_FLAGS}) + nghttp2_build() endif() include(BuildLibCURL) - curl_build(${HARDENING_FLAGS}) + curl_build() add_dependencies(build_bundled_libs bundled-libcurl) else() set(CURL_FIND_REQUIRED ON) @@ -542,7 +544,7 @@ if(ENABLE_BACKTRACE) endif() include(BuildLibUnwind) - libunwind_build(${HARDENING_FLAGS}) + libunwind_build() add_dependencies(build_bundled_libs bundled-libunwind bundled-libunwind-platform) diff --git a/cmake/BuildAres.cmake b/cmake/BuildAres.cmake index 5dc3584f4a..b86d793d14 100644 --- a/cmake/BuildAres.cmake +++ b/cmake/BuildAres.cmake @@ -1,11 +1,11 @@ # A macro to build the bundled libcares -macro(ares_build CFLAGS) +macro(ares_build) set(ARES_SOURCE_DIR ${PROJECT_SOURCE_DIR}/third_party/c-ares) set(ARES_BINARY_DIR ${PROJECT_BINARY_DIR}/build/ares/work) set(ARES_INSTALL_DIR ${PROJECT_BINARY_DIR}/build/ares/dest) # See BuildLibCURL.cmake for details. - set(ARES_CFLAGS ${CFLAGS}) + set(ARES_CFLAGS ${DEPENDENCY_CFLAGS}) if (TARGET_OS_DARWIN AND NOT "${CMAKE_OSX_SYSROOT}" STREQUAL "") set(ARES_CFLAGS "${ARES_CFLAGS} ${CMAKE_C_SYSROOT_FLAG} ${CMAKE_OSX_SYSROOT}") endif() diff --git a/cmake/BuildCDT.cmake b/cmake/BuildCDT.cmake index 8c89e8a117..e2e4629028 100644 --- a/cmake/BuildCDT.cmake +++ b/cmake/BuildCDT.cmake @@ -7,7 +7,7 @@ macro(libccdt_build) ${CMAKE_CURRENT_BINARY_DIR}/third_party/c-dt/build/) set_target_properties(cdt PROPERTIES COMPILE_FLAGS - "-DDT_NAMESPACE=tnt_ -DDT_PARSE_ISO_YEAR0 -DDT_PARSE_ISO_TNT" + "${DEPENDENCY_CFLAGS} -DDT_NAMESPACE=tnt_ -DDT_PARSE_ISO_YEAR0 -DDT_PARSE_ISO_TNT" ) add_definitions("-DDT_NAMESPACE=tnt_") endmacro() diff --git a/cmake/BuildDecNumber.cmake b/cmake/BuildDecNumber.cmake index abc6c64c41..e51d59b27a 100644 --- a/cmake/BuildDecNumber.cmake +++ b/cmake/BuildDecNumber.cmake @@ -8,6 +8,7 @@ macro(decnumber_build) ) add_library(decNumber STATIC ${decnumber_src}) + set_target_properties(decNumber PROPERTIES COMPILE_FLAGS "${DEPENDENCY_CFLAGS}") set(DECNUMBER_INCLUDE_DIR ${PROJECT_BINARY_DIR}/third_party/decNumber) unset(decnumber_src) diff --git a/cmake/BuildLibCORO.cmake b/cmake/BuildLibCORO.cmake index 860aabd5e3..de8c0664b4 100644 --- a/cmake/BuildLibCORO.cmake +++ b/cmake/BuildLibCORO.cmake @@ -5,7 +5,7 @@ macro(libcoro_build) ${PROJECT_SOURCE_DIR}/third_party/coro/coro.c ) set_source_files_properties(${coro_src} PROPERTIES - COMPILE_FLAGS -fomit-frame-pointer) + COMPILE_FLAGS "${DEPENDENCY_CFLAGS} -fomit-frame-pointer") add_library(coro STATIC ${coro_src}) diff --git a/cmake/BuildLibCURL.cmake b/cmake/BuildLibCURL.cmake index 99f1ead0fc..32c4aec088 100644 --- a/cmake/BuildLibCURL.cmake +++ b/cmake/BuildLibCURL.cmake @@ -1,9 +1,9 @@ # A macro to build the bundled libcurl -macro(curl_build CFLAGS) +macro(curl_build) set(LIBCURL_SOURCE_DIR ${PROJECT_SOURCE_DIR}/third_party/curl) set(LIBCURL_BINARY_DIR ${PROJECT_BINARY_DIR}/build/curl/work) set(LIBCURL_INSTALL_DIR ${PROJECT_BINARY_DIR}/build/curl/dest) - set(LIBCURL_CFLAGS ${CFLAGS}) + set(LIBCURL_CFLAGS ${DEPENDENCY_CFLAGS}) get_filename_component(FOUND_ZLIB_ROOT_DIR ${ZLIB_INCLUDE_DIR} DIRECTORY) list(APPEND LIBCURL_CMAKE_FLAGS "-DZLIB_ROOT=${FOUND_ZLIB_ROOT_DIR}") diff --git a/cmake/BuildLibEIO.cmake b/cmake/BuildLibEIO.cmake index 57561b56cc..a542a3deaf 100644 --- a/cmake/BuildLibEIO.cmake +++ b/cmake/BuildLibEIO.cmake @@ -1,7 +1,7 @@ # # A macro to build the bundled libeio macro(libeio_build) - set(eio_compile_flags) + set(eio_compile_flags ${DEPENDENCY_CFLAGS}) # See comments in BuildLibEV.cmake set(eio_compile_flags "${eio_compile_flags} -w") diff --git a/cmake/BuildLibEV.cmake b/cmake/BuildLibEV.cmake index 58e970851e..a8fef0a8d0 100644 --- a/cmake/BuildLibEV.cmake +++ b/cmake/BuildLibEV.cmake @@ -1,7 +1,7 @@ # # A macro to build the bundled libev macro(libev_build) - set(ev_compile_flags) + set(ev_compile_flags ${DEPENDENCY_CFLAGS}) set(ev_link_libraries) # There are warnings in libev code which are impossible to selectively # turn off, see diff --git a/cmake/BuildLibUnwind.cmake b/cmake/BuildLibUnwind.cmake index 750e6df6d0..27d7961d18 100644 --- a/cmake/BuildLibUnwind.cmake +++ b/cmake/BuildLibUnwind.cmake @@ -18,12 +18,12 @@ Cache Variables The paths to the libunwind libraries. #]========================================================================] -macro(libunwind_build CFLAGS) +macro(libunwind_build) set(LIBUNWIND_SOURCE_DIR ${PROJECT_SOURCE_DIR}/third_party/libunwind) set(LIBUNWIND_BUILD_DIR ${PROJECT_BINARY_DIR}/build/libunwind) set(LIBUNWIND_BINARY_DIR ${LIBUNWIND_BUILD_DIR}/work) set(LIBUNWIND_INSTALL_DIR ${LIBUNWIND_BUILD_DIR}/dest) - set(LIBUNWIND_CFLAGS "-g -O2 ${CFLAGS}") + set(LIBUNWIND_CFLAGS "${DEPENDENCY_CFLAGS} -g -O2") set(LIBUNWIND_CXXFLAGS "-g -O2") include(ExternalProject) diff --git a/cmake/BuildLibXXhash.cmake b/cmake/BuildLibXXhash.cmake index d9b8e6180b..9a96bf9e13 100644 --- a/cmake/BuildLibXXhash.cmake +++ b/cmake/BuildLibXXhash.cmake @@ -12,7 +12,7 @@ macro(libxxhash_build) # Remaining properties are the same as for zstd # (see cmake/BuildZSTD.cmake). set_source_files_properties(${xxhash_src} - PROPERTIES COMPILE_FLAGS "-Ofast -DXXH_NAMESPACE=tnt_") + PROPERTIES COMPILE_FLAGS "${DEPENDENCY_CFLAGS} -Ofast -DXXH_NAMESPACE=tnt_") add_library(xxhash STATIC ${xxhash_src}) set(XXHASH_LIBRARIES xxhash) diff --git a/cmake/BuildLibYAML.cmake b/cmake/BuildLibYAML.cmake index 7caa1828ca..a1bc8b4efb 100644 --- a/cmake/BuildLibYAML.cmake +++ b/cmake/BuildLibYAML.cmake @@ -6,7 +6,7 @@ macro(libyaml_build) add_subdirectory(${PROJECT_SOURCE_DIR}/third_party/libyaml EXCLUDE_FROM_ALL) # See comments in BuildLibEV.cmake - set_target_properties(yaml PROPERTIES COMPILE_FLAGS "-w") + set_target_properties(yaml PROPERTIES COMPILE_FLAGS "${DEPENDENCY_CFLAGS} -w") find_package_message(LIBYAML "Using bundled libyaml" @@ -14,4 +14,3 @@ macro(libyaml_build) unset(yaml_src) endmacro(libyaml_build) - diff --git a/cmake/BuildMisc.cmake b/cmake/BuildMisc.cmake index 7b11acb114..edd076528b 100644 --- a/cmake/BuildMisc.cmake +++ b/cmake/BuildMisc.cmake @@ -32,6 +32,7 @@ macro(libmisc_build) endif() add_library(misc STATIC ${misc_src}) + set_target_properties(misc PROPERTIES COMPILE_FLAGS "${DEPENDENCY_CFLAGS}") if (HAVE_OPENMP) if(BUILD_STATIC) diff --git a/cmake/BuildNghttp2.cmake b/cmake/BuildNghttp2.cmake index 54c37137fa..464eafaecf 100644 --- a/cmake/BuildNghttp2.cmake +++ b/cmake/BuildNghttp2.cmake @@ -1,12 +1,12 @@ # # A macro to build the bundled nghttp2 library. -macro(nghttp2_build CFLAGS) +macro(nghttp2_build) set(NGHTTP2_SOURCE_DIR ${PROJECT_SOURCE_DIR}/third_party/nghttp2) set(NGHTTP2_BINARY_DIR ${PROJECT_BINARY_DIR}/build/nghttp2/work) set(NGHTTP2_INSTALL_DIR ${PROJECT_BINARY_DIR}/build/nghttp2/dest) # See BuildLibCURL.cmake for details. - set(NGHTTP2_CFLAGS ${CFLAGS}) + set(NGHTTP2_CFLAGS ${DEPENDENCY_CFLAGS}) if (TARGET_OS_DARWIN AND NOT "${CMAKE_OSX_SYSROOT}" STREQUAL "") set(NGHTTP2_CFLAGS "${NGHTTP2_CFLAGS} ${CMAKE_C_SYSROOT_FLAG} ${CMAKE_OSX_SYSROOT}") endif() diff --git a/cmake/BuildZSTD.cmake b/cmake/BuildZSTD.cmake index 9b2e1b9dba..995a5245de 100644 --- a/cmake/BuildZSTD.cmake +++ b/cmake/BuildZSTD.cmake @@ -26,13 +26,12 @@ macro(zstd_build) third_party/zstd/lib/compress/zstd_compress_sequences.c third_party/zstd/lib/compress/zstd_compress_literals.c ) - + set(zstd_cflags "${DEPENDENCY_CFLAGS} -Ofast") if (CC_HAS_WNO_IMPLICIT_FALLTHROUGH) - set_source_files_properties(${zstd_src} - PROPERTIES COMPILE_FLAGS -Wno-implicit-fallthrough) + set(zstd_cflags "${zstd_cflags} -Wno-implicit-fallthrough") endif() set_source_files_properties(${zstd_src} - PROPERTIES COMPILE_FLAGS -Ofast) + PROPERTIES COMPILE_FLAGS ${zstd_cflags}) add_library(zstd STATIC ${zstd_src}) set(ZSTD_LIBRARIES zstd) -- GitLab