From 1b1e9b85a51444751dddc0e94a09d19bd4f0885e Mon Sep 17 00:00:00 2001 From: spicyjpeg Date: Sun, 9 Oct 2022 20:26:25 +0200 Subject: Refactor CMake scripts, add separate debug/release builds --- libpsn00b/CMakeLists.txt | 57 +++++++++++++++++++++++------------------------- 1 file changed, 27 insertions(+), 30 deletions(-) (limited to 'libpsn00b/CMakeLists.txt') diff --git a/libpsn00b/CMakeLists.txt b/libpsn00b/CMakeLists.txt index a662448..71cc659 100644 --- a/libpsn00b/CMakeLists.txt +++ b/libpsn00b/CMakeLists.txt @@ -13,11 +13,7 @@ project( HOMEPAGE_URL "http://lameguy64.net/?page=psn00bsdk" ) -if(NOT DEFINED PSN00BSDK_LIBGCC) - message(FATAL_ERROR "Failed to obtain information about the GCC toolchain. Check your toolchain settings.") -elseif(PSN00BSDK_LIBGCC STREQUAL "PSN00BSDK_LIBGCC-NOTFOUND") - message(FATAL_ERROR "Failed to find libgcc in the GCC toolchain's files. Check your toolchain settings, or set the path to libgcc using -DPSN00BSDK_LIBGCC.") -endif() +include(${PROJECT_SOURCE_DIR}/cmake/flags.cmake) ## Libraries @@ -31,37 +27,36 @@ foreach(_library IN LISTS PSN00BSDK_LIBRARIES) file( GLOB_RECURSE _sources - ${_path}/*.s - ${_path}/*.c - ${_path}/*.cpp - ${_path}/*.cxx + ${_path}/*.s ${_path}/*.c ${_path}/*.cpp ) - psn00bsdk_add_library(${_library} STATIC ${_sources}) -endforeach() + foreach(_suffix IN ITEMS _exe_nogprel _exe_gprel _dll) + set(_name ${_library}${_suffix}) + list(APPEND _libraries ${_name}) -psn00bsdk_target_incbin(psxgpu PRIVATE _gpu_debug_font psxgpu/dbugfont.tim) + psn00bsdk_add_library(${_name} STATIC ${_sources}) + target_link_libraries(${_name} PUBLIC psn00bsdk${_suffix}) + endforeach() +endforeach() -# Extract libgcc's contents and merge them into libc after building. -# Unfortunately glob expressions won't work on Windows, so we have to manually -# enumerate the contents of libgcc and save the list to a temporary file (as it -# is too long to be passed directly on the command line). This is actually the -# most reliable way I found to do this (I tried $ to no avail). -add_custom_command( - TARGET c POST_BUILD - COMMAND ${CMAKE_AR} t ${PSN00BSDK_LIBGCC} $_libgcc.txt - COMMAND ${CMAKE_AR} x ${PSN00BSDK_LIBGCC} - COMMAND ${CMAKE_AR} q $ \@_libgcc.txt - COMMAND ${CMAKE_AR} s $ - #COMMAND ${CMAKE_AR} rsuU $ *.o - COMMENT "Merging libgcc contents into SDK libc" -) +# Add binary assets to each version of the libraries. +foreach(_suffix IN ITEMS _exe_nogprel _exe_gprel _dll) + psn00bsdk_target_incbin( + psxgpu${_suffix} PRIVATE _gpu_debug_font + psxgpu/dbugfont.tim + ) +endforeach() ## Installation install( - TARGETS ${PSN00BSDK_LIBRARIES} - DESTINATION ${CMAKE_INSTALL_LIBDIR}/libpsn00b + TARGETS + psn00bsdk_common + psn00bsdk_exe_gprel + psn00bsdk_exe_nogprel + psn00bsdk_dll + ${_libraries} + DESTINATION ${CMAKE_INSTALL_LIBDIR}/libpsn00b/$> EXPORT libpsn00b ) install( @@ -95,9 +90,11 @@ install( ) # Generate an import script, which will be used by the setup script to find the -# libraries. +# libraries. Note that CMake actually generates two separate import scripts +# (one setting configuration-specific options), so this won't create conflicts +# once the debug and release builds are merged into the same installation tree. install( EXPORT libpsn00b - DESTINATION ${CMAKE_INSTALL_LIBDIR}/libpsn00b/cmake + DESTINATION ${CMAKE_INSTALL_LIBDIR}/libpsn00b #EXPORT_LINK_INTERFACE_LIBRARIES ) -- cgit v1.2.3