Change architecture dependent compilation to not use janky hacks
Previously didn't add the source to the target if a source of the same name already existed. This was janky because these files would be considered the same: src/foo.cpp src/armv4t/bar/baz/foo.cpp, even though they really shouldn't. What should happen instead, is that the symbols of the architecture-specific code should not be overridden by the common implementation regardless of where the file is placed. This means that if the files src/foo.cpp and src/armv4t/bar.cpp contain implementations of the function foo, the armv4t implementation will be exported even though it uses a different filename from the common implementation. This commit implements this behaviour by using the way symbols are naturally resolved. Multiple smaller libraries are built for each architecture dependent code. Afterwards the libraries are linked into one, with the arch specific libraries linked first.
This commit is contained in:
parent
93a8603ce0
commit
55b1658e45
@ -5,62 +5,43 @@ set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
|
||||
|
||||
message("Compiling MTL for ${CMAKE_SYSTEM_PROCESSOR}")
|
||||
|
||||
# Adds the sources to the target if there is not already a source with the
|
||||
# same filename (ie. no clobber/noc). (Note, the files can be in different directories)
|
||||
function(target_sources_noc target linkage sources)
|
||||
get_target_property(cur_sources ${target} SOURCES)
|
||||
|
||||
foreach(src_fq ${sources})
|
||||
cmake_path(GET src_fq FILENAME src)
|
||||
set(already_exists false)
|
||||
|
||||
# Check if the source already exists
|
||||
foreach (csrc_fq ${cur_sources})
|
||||
cmake_path(GET csrc_fq FILENAME csrc)
|
||||
if (src STREQUAL csrc)
|
||||
set(already_exists true)
|
||||
break()
|
||||
endif()
|
||||
endforeach()
|
||||
|
||||
if (NOT already_exists)
|
||||
target_sources(${target} ${linkage} "${src_fq}")
|
||||
endif()
|
||||
endforeach()
|
||||
endfunction()
|
||||
|
||||
# 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/*.cpp src/*.c src/*.s)
|
||||
file(GLOB mtl_sources_debug LIST_DIRECTORIES false CONFIGURE_DEPENDS src/debug/*.cpp src/debug/*.c src/debug/*.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)
|
||||
|
||||
set(mtl_include_common "include")
|
||||
set(mtl_include_debug "include/debug")
|
||||
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)
|
||||
|
||||
set(mtl_processor_generic true)
|
||||
set(mtl_platform_generic true)
|
||||
add_library(${PROJECT_NAME}_common OBJECT)
|
||||
|
||||
if (CMAKE_SYSTEM_NAME STREQUAL "NintendoGBA")
|
||||
target_sources_noc(${PROJECT_NAME} PRIVATE "${mtl_sources_gba}")
|
||||
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")
|
||||
target_sources_noc(${PROJECT_NAME} PRIVATE "${mtl_sources_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()
|
||||
|
||||
target_sources_noc(${PROJECT_NAME} PRIVATE "${mtl_sources_common}")
|
||||
target_include_directories(${PROJECT_NAME} PUBLIC "${mtl_include_common}")
|
||||
|
||||
if (CMAKE_BUILD_TYPE STREQUAL "Debug")
|
||||
target_sources_noc(${PROJECT_NAME} PRIVATE "${mtl_sources_debug}")
|
||||
target_include_directories(${PROJECT_NAME} PUBLIC "${mtl_include_debug}")
|
||||
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
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user