Skip to content

Commit 42853ec

Browse files
Update (C|CXX|LD)FLAGS for Meson and Autotools
1 parent 152abdf commit 42853ec

File tree

2 files changed

+19
-9
lines changed

2 files changed

+19
-9
lines changed

3rdparty/CompilerFlags.cmake

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,33 @@
11
# Get Compiler flags from our current CMake environment,
22
# Will be passed to Autotools and Meson
33

4-
# -g -DANDROID -fdata-sections -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -fno-addrsig -Wa,--noexecstack -Wformat -Werror=format-security
54
SET(CFLAGS ${CMAKE_C_FLAGS})
6-
# -g -DANDROID -fdata-sections -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -fno-addrsig -Wa,--noexecstack -Wformat -Werror=format-security -stdlib=libc++
75
SET(CXXFLAGS ${CMAKE_CXX_FLAGS})
8-
# -Wl,--exclude-libs,libgcc.a -Wl,--exclude-libs,libatomic.a -static-libstdc++ -Wl,--build-id -Wl,--warn-shared-textrel -Wl,--fatal-warnings -Wl,--no-undefined -Qunused-arguments -Wl,-z,noexecstack -Wl,-z,relro -Wl,-z,now
96
SET(LDFLAGS ${ANDROID_LINKER_FLAGS})
107

118
if (CMAKE_BUILD_TYPE STREQUAL Debug)
12-
# -O0 -fno-limit-debug-info
139
STRING(APPEND CFLAGS ${CMAKE_C_FLAGS_DEBUG})
14-
# -O0 -fno-limit-debug-info
1510
STRING(APPEND CXXFLAGS ${CMAKE_CXX_FLAGS_DEBUG})
1611
elseif(CMAKE_BUILD_TYPE STREQUAL Release)
17-
# -O2 -DNDEBUG
1812
STRING(APPEND CFLAGS ${CMAKE_C_FLAGS_RELEASE})
19-
# -O2 -DNDEBUG
2013
STRING(APPEND CXXFLAGS ${CMAKE_CXX_FLAGS_RELEASE})
2114
elseif(CMAKE_BUILD_TYPE STREQUAL RelWithDebInfo)
22-
# -O2 -g -DNDEBUG
15+
STRING(APPEND CFLAGS ${CMAKE_C_FLAGS_RELWITHDEBINFO})
2316
STRING(APPEND CXXFLAGS ${CMAKE_CXX_FLAGS_RELWITHDEBINFO})
2417
elseif(CMAKE_BUILD_TYPE STREQUAL MinSizeRel)
25-
# -Os -DNDEBUG
18+
STRING(APPEND CFLAGS ${CMAKE_C_FLAGS_MINSIZEREL})
2619
STRING(APPEND CXXFLAGS ${CMAKE_CXX_FLAGS_MINSIZEREL})
2720
endif()
2821

2922
STRING(APPEND CFLAGS " -I${THIRDPARTY_PREFIX}/include")
3023
STRING(APPEND CXXFLAGS " -I${THIRDPARTY_PREFIX}/include")
3124
STRING(APPEND LDFLAGS " -L${THIRDPARTY_PREFIX}/lib")
3225

26+
if(CMAKE_BUILD_TYPE STREQUAL MinSizeRel)
27+
STRING(REPLACE "-g " " " CFLAGS ${CFLAGS})
28+
STRING(REPLACE "-g " " " CXXFLAGS ${CXXFLAGS})
29+
endif()
30+
3331
if (ANDROID)
3432
if(ANDROID_ABI STREQUAL armeabi-v7a)
3533
SET(AS ${ANDROID_TOOLCHAIN_ROOT}/bin/armv7a-linux-androideabi-as)

3rdparty/EPMeson.cmake

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,14 @@ function(ExternalProjectMeson EXTERNAL_PROJECT_NAME)
6363
message(FATAL_ERROR "Unknown build type:" ${CMAKE_BUILD_TYPE})
6464
endif()
6565

66+
# Filter out unsupported arguments from FLAGS
67+
STRING(REPLACE "-no-canonical-prefixes" " " MESON_CFLAGS ${CFLAGS})
68+
STRING(REPLACE "-no-canonical-prefixes" " " MESON_CXXFLAGS ${CXXFLAGS})
69+
70+
# https://github.com/android-ndk/ndk/issues/884
71+
STRING(REPLACE "-fno-addrsig" " " MESON_CFLAGS ${MESON_CFLAGS})
72+
STRING(REPLACE "-fno-addrsig" " " MESON_CXXFLAGS ${MESON_CXXFLAGS})
73+
6674
SET(MESON_ENV
6775
# https://github.com/mesonbuild/meson/issues/217
6876
# find_library is now cc.find_library and now uses the linker to check if a particular library is available (similar to how AC_CHECK_LIB does it). This means you can set the LIBRARY_PATH env variable (when using gcc/clang and the LIBPATH env variable when using MSVC) to point to your "library providing" root. It also accepts a colon-separated list of directories. This is how almost everyone does non-default-linker-search-path library searching and linking.
@@ -73,6 +81,10 @@ function(ExternalProjectMeson EXTERNAL_PROJECT_NAME)
7381
# Note that if you have a single prefix with all your dependencies, you might find it easier to append to the environment variables C_INCLUDE_PATH with GCC/Clang and INCLUDE with MSVC to expand the default include path, and LIBRARY_PATH with GCC/Clang and LIB with MSVC to expand the default library search path.
7482
C_INCLUDE_PATH=${THIRDPARTY_PREFIX}/include
7583
INCLUDE=${THIRDPARTY_PREFIX}/include
84+
85+
CFLAGS=${MESON_CFLAGS}
86+
CXXFLAGS=${MESON_CXXFLAGS}
87+
LDFLAGS=${LDFLAGS}
7688
)
7789

7890
set(EPM_CONFIGURE_COMMAND ${CMAKE_COMMAND} -E env ${MESON_ENV}

0 commit comments

Comments
 (0)