This commit adds the ability to conditionally compile tests. To implement this, common source files needed to be moved to a subdirectory `common`. Additionally, this commit splits each `mat` template instantiation into a separate source file. This enables the linker to discard unused instantations. If each instantiation is placed in the same file and also into the .iwram section, the linker will include every symbol in the resulting binary, leading to an extremely high IWRAM usage. To introduce this split, a new header file "mat_impl.hpp" was added containing implementation details for the template instantiations. "mat_impl.hpp" should ONLY be included by the source files containing explicit instantiations of `mat`.
57 lines
2.5 KiB
CMake
57 lines
2.5 KiB
CMake
cmake_minimum_required(VERSION 3.5)
|
|
|
|
project(mtl LANGUAGES CXX C ASM)
|
|
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
|
|
|
|
option(BUILD_TESTS "Build tests" ON)
|
|
|
|
message("Compiling MTL for ${CMAKE_SYSTEM_PROCESSOR}")
|
|
|
|
# CONFIGURE_DEPENDS option was added in CMake v3.12. This option allows the
|
|
# build system to automatically re-run CMake if the glob changes, solving the
|
|
# major issue with globbing. May have a performance impact, but it should be
|
|
# negligible compared to the time spent building.
|
|
file(GLOB mtl_sources_common LIST_DIRECTORIES false CONFIGURE_DEPENDS src/common/*.cpp src/common/*.c src/common/*.s)
|
|
file(GLOB mtl_sources_armv4t LIST_DIRECTORIES false CONFIGURE_DEPENDS src/armv4t/*.cpp src/armv4t/*.c src/armv4t/*.s)
|
|
file(GLOB mtl_sources_gba LIST_DIRECTORIES false CONFIGURE_DEPENDS src/gba/*.cpp src/gba/*.c src/gba/*.s)
|
|
file(GLOB mtl_sources_test LIST_DIRECTORIES false CONFIGURE_DEPENDS src/tests/*.cpp)
|
|
|
|
set(mtl_include_common "include")
|
|
set(mtl_include_gba "include/gba")
|
|
set(mtl_include_armv4t "include/armv4t")
|
|
|
|
# Sources are built into separate libraries and then linked into one static
|
|
# library. The libraries which are linked first will have their symbols
|
|
# prioritized over later libraries.
|
|
add_library(${PROJECT_NAME} STATIC)
|
|
add_library(${PROJECT_NAME}_common OBJECT)
|
|
|
|
if (CMAKE_SYSTEM_NAME STREQUAL "NintendoGBA")
|
|
add_library(${PROJECT_NAME}_gba OBJECT)
|
|
target_sources(${PROJECT_NAME}_gba PRIVATE "${mtl_sources_gba}")
|
|
target_include_directories(${PROJECT_NAME}_gba PUBLIC "${mtl_include_common}")
|
|
target_include_directories(${PROJECT_NAME}_gba PUBLIC "${mtl_include_gba}")
|
|
target_link_libraries(${PROJECT_NAME} PUBLIC ${PROJECT_NAME}_gba)
|
|
endif()
|
|
|
|
if (CMAKE_SYSTEM_PROCESSOR STREQUAL "armv4t")
|
|
add_library(${PROJECT_NAME}_armv4t OBJECT)
|
|
target_sources(${PROJECT_NAME}_armv4t PRIVATE "${mtl_sources_armv4t}")
|
|
target_include_directories(${PROJECT_NAME}_armv4t PUBLIC "${mtl_include_common}")
|
|
target_include_directories(${PROJECT_NAME}_armv4t PUBLIC "${mtl_include_armv4t}")
|
|
target_link_libraries(${PROJECT_NAME} PUBLIC ${PROJECT_NAME}_armv4t)
|
|
endif()
|
|
|
|
if (BUILD_TESTS STREQUAL "ON")
|
|
add_library(${PROJECT_NAME}_test OBJECT)
|
|
target_sources(${PROJECT_NAME}_test PRIVATE "${mtl_sources_test}")
|
|
target_link_libraries(${PROJECT_NAME} PUBLIC ${PROJECT_NAME}_test)
|
|
endif()
|
|
|
|
target_sources(${PROJECT_NAME}_common PRIVATE "${mtl_sources_common}")
|
|
target_include_directories(${PROJECT_NAME}_common PUBLIC "${mtl_include_common}")
|
|
target_link_libraries(${PROJECT_NAME} PUBLIC ${PROJECT_NAME}_common)
|
|
|
|
# TODO: Support installing library
|
|
|