From add17b14ae4d22ec313b8515c7f69f96adff8933 Mon Sep 17 00:00:00 2001 From: Duncan Date: Mon, 14 Apr 2025 09:45:37 +0100 Subject: [PATCH] Use aliases in cmake to prevent mistakes. Fix g2 dependency mistake (#24213) Move libopenrct2 cmake to libopenrct2 Revert using aliases for install --- CMakeLists.txt | 18 +----------------- src/openrct2-cli/CMakeLists.txt | 2 ++ src/openrct2-ui/CMakeLists.txt | 2 ++ src/openrct2/CMakeLists.txt | 18 ++++++++++++++++++ test/tests/CMakeLists.txt | 2 ++ 5 files changed, 25 insertions(+), 17 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 5ee06f91ac..7f366ff347 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -391,22 +391,6 @@ if(NOT DISABLE_GUI) include("${ROOT_DIR}/src/openrct2-ui/CMakeLists.txt" NO_POLICY_SCOPE) endif() -# Defines -target_compile_definitions(libopenrct2 PUBLIC - $<$:USE_MMAP> - $<$:DISABLE_NETWORK> - $<$:DISABLE_HTTP> - $<$:DISABLE_TTF> - $<$:DISABLE_VERSION_CHECKER> - $<$:ENABLE_SCRIPTING> -) - -target_compile_options(libopenrct2 PUBLIC $<$:-fsanitize=address>) -target_link_options(libopenrct2 PUBLIC $<$:-fsanitize=address>) - -target_compile_options(libopenrct2 PUBLIC $<$:-fsanitize=undefined>) -target_link_options(libopenrct2 PUBLIC $<$:-fsanitize=undefined>) - # g2 if (NOT (MACOS_BUNDLE AND (NOT CMAKE_OSX_ARCHITECTURES MATCHES "${SYSTEM_MACOS_ARCH}"))) add_custom_command( @@ -414,7 +398,7 @@ if (NOT (MACOS_BUNDLE AND (NOT CMAKE_OSX_ARCHITECTURES MATCHES "${SYSTEM_MACOS_A COMMAND ./openrct2-cli sprite build ${CMAKE_BINARY_DIR}/g2.dat ${ROOT_DIR}/resources/g2/sprites.json WORKING_DIRECTORY ${CMAKE_BINARY_DIR} ) - add_custom_target(g2 DEPENDS openrct2 g2.dat) + add_custom_target(g2 DEPENDS OpenRCT2::openrct2-cli g2.dat) else () message("Skipping g2.dat generation in macOS cross-compile") endif () diff --git a/src/openrct2-cli/CMakeLists.txt b/src/openrct2-cli/CMakeLists.txt index 06e220d117..19d41a6ff7 100644 --- a/src/openrct2-cli/CMakeLists.txt +++ b/src/openrct2-cli/CMakeLists.txt @@ -7,6 +7,8 @@ file(GLOB_RECURSE OPENRCT2_CLI_SOURCES "${CMAKE_CURRENT_LIST_DIR}/*.hpp") add_executable(openrct2-cli ${OPENRCT2_CLI_SOURCES}) +add_executable(OpenRCT2::openrct2-cli ALIAS openrct2-cli) + target_include_directories(openrct2-cli PRIVATE "${CMAKE_CURRENT_LIST_DIR}/..") ipo_set_target_properties(openrct2-cli) if (EMSCRIPTEN) diff --git a/src/openrct2-ui/CMakeLists.txt b/src/openrct2-ui/CMakeLists.txt index c3e0e4e06c..f33d780dbb 100644 --- a/src/openrct2-ui/CMakeLists.txt +++ b/src/openrct2-ui/CMakeLists.txt @@ -59,6 +59,8 @@ endif () # Outputs add_executable(openrct2 ${OPENRCT2_UI_SOURCES} ${OPENRCT2_UI_MM_SOURCES}) +add_executable(OpenRCT2::openrct2 ALIAS openrct2) + SET_CHECK_CXX_FLAGS(openrct2) ipo_set_target_properties(openrct2) diff --git a/src/openrct2/CMakeLists.txt b/src/openrct2/CMakeLists.txt index 548922df70..137b5925b5 100644 --- a/src/openrct2/CMakeLists.txt +++ b/src/openrct2/CMakeLists.txt @@ -20,6 +20,8 @@ if (ENABLE_SCRIPTING) endif () add_library(libopenrct2 ${OPENRCT2_CORE_SOURCES} ${OPENRCT2_CORE_MM_SOURCES} ${OPENRCT2_DUKTAPE_SOURCES}) +add_library(OpenRCT2::libopenrct2 ALIAS libopenrct2) + if (CMAKE_COMPILER_IS_GNUCXX AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS "13") message(WARNING "Buggy GCC 12 detected! Disabling some warnings") set_source_files_properties("${CMAKE_CURRENT_LIST_DIR}/localisation/FormatCodes.cpp" PROPERTIES COMPILE_FLAGS "-Wno-restrict") @@ -281,6 +283,22 @@ if (UNIX) add_definitions(-D_FILE_OFFSET_BITS=64) endif () +# Defines +target_compile_definitions(libopenrct2 PUBLIC + $<$:USE_MMAP> + $<$:DISABLE_NETWORK> + $<$:DISABLE_HTTP> + $<$:DISABLE_TTF> + $<$:DISABLE_VERSION_CHECKER> + $<$:ENABLE_SCRIPTING> +) + +target_compile_options(libopenrct2 PUBLIC $<$:-fsanitize=address>) +target_link_options(libopenrct2 PUBLIC $<$:-fsanitize=address>) + +target_compile_options(libopenrct2 PUBLIC $<$:-fsanitize=undefined>) +target_link_options(libopenrct2 PUBLIC $<$:-fsanitize=undefined>) + if (CMAKE_LIBRARY_ARCHITECTURE MATCHES "arm-linux-gnueabihf") message(STATUS "Linking to armhf libs; adding libatomic") target_link_libraries(libopenrct2 atomic) diff --git a/test/tests/CMakeLists.txt b/test/tests/CMakeLists.txt index 61b0446e60..707bdf0434 100644 --- a/test/tests/CMakeLists.txt +++ b/test/tests/CMakeLists.txt @@ -37,6 +37,8 @@ set(test_files "${CMAKE_CURRENT_SOURCE_DIR}/TileElementsView.cpp") add_executable(OpenRCT2Tests ${test_files}) +add_executable(OpenRCT2::OpenRCT2Tests ALIAS OpenRCT2Tests) + target_link_libraries(OpenRCT2Tests GTest::gtest GTest::gtest_main libopenrct2) target_include_directories(OpenRCT2Tests PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/../../src") set_target_properties(OpenRCT2Tests PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})