Skip to content

Commit 667c3cd

Browse files
authored
faster and smaller adaparse (#956)
1 parent bba18f3 commit 667c3cd

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

tools/cli/CMakeLists.txt

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,35 @@
11
add_executable(adaparse adaparse.cpp line_iterator.h)
22
target_link_libraries(adaparse PRIVATE ada)
33
target_include_directories(adaparse PUBLIC "$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>")
4+
5+
6+
if(CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang")
7+
# We are on an Apple platform, so we can use dead_strip and LTO
8+
# to reduce the size of the final binary.
9+
message(STATUS "Apple platform detected, using dead_strip and LTO")
10+
target_link_options(adaparse PRIVATE "-Wl,-dead_strip")
11+
target_compile_options(adaparse PRIVATE "-flto")
12+
target_link_options(adaparse PRIVATE "-flto")
13+
endif(CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang")
14+
15+
if((CMAKE_CXX_COMPILER_ID STREQUAL "GNU") OR (CMAKE_CXX_COMPILER_ID STREQUAL "Clang"))
16+
execute_process(COMMAND ${CMAKE_CXX_COMPILER} -print-libgcc-file-name OUTPUT_VARIABLE ADA_GCC_LIB)
17+
get_filename_component(ADA_GCC_DIR "${ADA_GCC_LIB}" DIRECTORY)
18+
message(STATUS "looking for static C++ library in " ${ADA_GCC_DIR})
19+
find_library(LIBSTDCPP libstdc++.a PATHS "${ADA_GCC_DIR}")
20+
if(LIBSTDCPP)
21+
# static linkink for speed
22+
message(STATUS "libstdc++.a found")
23+
target_link_options(adaparse PRIVATE "-static-libstdc++")
24+
else()
25+
message(STATUS "libstdc++.a not found")
26+
endif()
27+
# Note that we are not under Apple at this time.
28+
# We can use the -Wl,--gc-sections option to remove unused sections
29+
# from the final binary, which can reduce the size of the binary.
30+
target_link_options(adaparse PRIVATE "-Wl,--gc-sections")
31+
endif()
32+
433
if(MSVC AND BUILD_SHARED_LIBS)
534
# Copy the ada dll into the directory
635
add_custom_command(TARGET adaparse POST_BUILD # Adds a post-build event

0 commit comments

Comments
 (0)