|
| 1 | +# include some defines automatically made by qpm |
| 2 | +include(qpm_defines.cmake) |
| 3 | + |
| 4 | +# override mod id |
| 5 | +set(MOD_ID "RedBar") |
| 6 | + |
| 7 | +# Enable link time optimization |
| 8 | +# In my experience, this can be highly unstable but it nets a huge size optimization and likely performance |
| 9 | +# However, the instability was seen using Android.mk/ndk-build builds. With Ninja + CMake, this problem seems to have been solved. |
| 10 | +# As always, test thoroughly |
| 11 | +# - Fern |
| 12 | +# set(CMAKE_INTERPROCEDURAL_OPTIMIZATION TRUE) |
| 13 | + |
| 14 | +cmake_minimum_required(VERSION 3.21) |
| 15 | +project(${COMPILE_ID}) |
| 16 | + |
| 17 | +# c++ standard |
| 18 | +set(CMAKE_CXX_STANDARD 20) |
| 19 | +set(CMAKE_CXX_STANDARD_REQUIRED 20) |
| 20 | + |
| 21 | +# define that stores the actual source directory |
| 22 | +set(SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/src) |
| 23 | +set(INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/include) |
| 24 | + |
| 25 | +# compile options used |
| 26 | +add_compile_options(-frtti -fexceptions) |
| 27 | +add_compile_options(-O3) |
| 28 | +# compile definitions used |
| 29 | +add_compile_definitions(VERSION=\"${MOD_VERSION}\") |
| 30 | +add_compile_definitions(ID=\"${MOD_ID}\") |
| 31 | +add_compile_definitions(MOD_ID=\"${MOD_ID}\") |
| 32 | +
|
| 33 | +# recursively get all src files |
| 34 | +RECURSE_FILES(cpp_file_list ${SOURCE_DIR}/*.cpp) |
| 35 | +RECURSE_FILES(c_file_list ${SOURCE_DIR}/*.c) |
| 36 | +
|
| 37 | +# add all src files to compile |
| 38 | +add_library( |
| 39 | + ${COMPILE_ID} |
| 40 | + SHARED |
| 41 | + ${cpp_file_list} |
| 42 | + ${c_file_list} |
| 43 | +) |
| 44 | +
|
| 45 | +target_include_directories(${COMPILE_ID} PRIVATE .) |
| 46 | +
|
| 47 | +# add src dir as include dir |
| 48 | +target_include_directories(${COMPILE_ID} PRIVATE ${SOURCE_DIR}) |
| 49 | +# add include dir as include dir |
| 50 | +target_include_directories(${COMPILE_ID} PRIVATE ${INCLUDE_DIR}) |
| 51 | +# add shared dir as include dir |
| 52 | +target_include_directories(${COMPILE_ID} PUBLIC ${SHARED_DIR}) |
| 53 | +# codegen includes |
| 54 | +target_include_directories(${COMPILE_ID} PRIVATE ${EXTERN_DIR}/includes/${CODEGEN_ID}/include) |
| 55 | +
|
| 56 | +target_link_libraries(${COMPILE_ID} PRIVATE -llog) |
| 57 | +# add extern stuff like libs and other includes |
| 58 | +include(extern.cmake) |
| 59 | +
|
| 60 | +add_custom_command(TARGET ${COMPILE_ID} POST_BUILD |
| 61 | + COMMAND ${CMAKE_STRIP} -d --strip-all |
| 62 | + "lib${COMPILE_ID}.so" -o "stripped_lib${COMPILE_ID}.so" |
| 63 | + COMMENT "Strip debug symbols done on final binary.") |
| 64 | +
|
| 65 | +add_custom_command(TARGET ${COMPILE_ID} POST_BUILD |
| 66 | + COMMAND ${CMAKE_COMMAND} -E make_directory debug |
| 67 | + COMMENT "Make directory for debug symbols" |
| 68 | + ) |
| 69 | +
|
| 70 | +add_custom_command(TARGET ${COMPILE_ID} POST_BUILD |
| 71 | + COMMAND ${CMAKE_COMMAND} -E rename lib${COMPILE_ID}.so debug/lib${COMPILE_ID}.so |
| 72 | + COMMENT "Rename the lib to debug_ since it has debug symbols" |
| 73 | + ) |
| 74 | +
|
| 75 | +add_custom_command(TARGET ${COMPILE_ID} POST_BUILD |
| 76 | + COMMAND ${CMAKE_COMMAND} -E rename stripped_lib${COMPILE_ID}.so lib${COMPILE_ID}.so |
| 77 | + COMMENT "Rename the stripped lib to regular" |
| 78 | + ) |
0 commit comments