Skip to content

Commit ae30473

Browse files
committed
Ensure consistency of the compiler and linker flags
Signed-off-by: Muntashir Al-Islam <muntashirakon@riseup.net>
1 parent 836c724 commit ae30473

1 file changed

Lines changed: 17 additions & 12 deletions

File tree

app/src/main/cpp/CMakeLists.txt

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,30 @@
11
cmake_minimum_required(VERSION 3.4.1)
22

3+
project(AppManager LANGUAGES C CXX)
4+
35
set(CMAKE_CXX_STANDARD 17)
46

5-
set(C_FLAGS "-Werror=format -fdata-sections -ffunction-sections -fno-exceptions -fno-rtti -fno-threadsafe-statics")
6-
set(LINKER_FLAGS "-Wl,--hash-style=both -Wl,--build-id=none")
7+
# Global compiler flags
8+
set(COMMON_C_FLAGS "-Werror=format -fdata-sections -ffunction-sections -fno-exceptions -fno-rtti -fno-threadsafe-statics")
9+
if (NOT CMAKE_BUILD_TYPE STREQUAL "Debug")
10+
set(COMMON_C_FLAGS "${COMMON_C_FLAGS} -O2 -fvisibility=hidden -fvisibility-inlines-hidden")
11+
endif()
12+
13+
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${COMMON_C_FLAGS}")
14+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${COMMON_C_FLAGS}")
715

16+
# Global linker flags
17+
set(BASE_LINK_FLAGS "-Wl,--hash-style=both -Wl,--build-id=none")
818
if (NOT CMAKE_BUILD_TYPE STREQUAL "Debug")
919
message("Building Release...")
1020

11-
set(C_FLAGS "${C_FLAGS} -O2 -fvisibility=hidden -fvisibility-inlines-hidden")
12-
set(LINKER_FLAGS "${LINKER_FLAGS} -Wl,-exclude-libs,ALL -Wl,--gc-sections")
21+
set(BASE_LINK_FLAGS "${BASE_LINK_FLAGS} -Wl,-exclude-libs,ALL -Wl,--gc-sections")
1322
else()
1423
message("Building Debug...")
1524

1625
add_definitions(-DDEBUG)
1726
endif ()
1827

19-
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${C_FLAGS}")
20-
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${C_FLAGS}")
21-
22-
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} ${LINKER_FLAGS}")
23-
set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} ${LINKER_FLAGS}")
24-
2528
find_library(log-lib log)
2629

2730
# BEGIN libam.so
@@ -33,9 +36,11 @@ add_library(am SHARED
3336

3437
target_link_libraries(am ${log-lib})
3538

39+
set_target_properties(am PROPERTIES LINK_FLAGS "${BASE_LINK_FLAGS}")
40+
3641
if (NOT CMAKE_BUILD_TYPE STREQUAL "Debug")
3742
add_custom_command(TARGET am POST_BUILD
38-
COMMAND ${CMAKE_STRIP} --remove-section=.comment "${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/libam.so")
43+
COMMAND ${CMAKE_STRIP} --remove-section=.comment "$<TARGET_FILE:am>")
3944
endif ()
4045

4146
# END libam.so
@@ -49,7 +54,7 @@ set_target_properties(run_server PROPERTIES
4954
PREFIX "lib"
5055
SUFFIX ".so"
5156
COMPILE_FLAGS "-fPIE -fPIC"
52-
LINK_FLAGS "-pie"
57+
LINK_FLAGS "-pie ${BASE_LINK_FLAGS}"
5358
)
5459

5560
if (NOT CMAKE_BUILD_TYPE STREQUAL "Debug")

0 commit comments

Comments
 (0)