|
1 | 1 | add_executable(adaparse adaparse.cpp line_iterator.h)
|
2 | 2 | target_link_libraries(adaparse PRIVATE ada)
|
3 | 3 | 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 | + |
4 | 33 | if(MSVC AND BUILD_SHARED_LIBS)
|
5 | 34 | # Copy the ada dll into the directory
|
6 | 35 | add_custom_command(TARGET adaparse POST_BUILD # Adds a post-build event
|
|
0 commit comments