From 9b56505feca991736c323ae64e3fc5416522de70 Mon Sep 17 00:00:00 2001 From: Rubidium Date: Mon, 10 Apr 2023 18:00:53 +0200 Subject: [PATCH] Codechange: split building into a library and executable --- CMakeLists.txt | 19 ++++++++++++------- cmake/CheckAtomic.cmake | 2 +- cmake/LinkPackage.cmake | 4 ++-- cmake/SourceList.cmake | 2 +- src/os/macosx/CMakeLists.txt | 5 ++++- src/os/os2/CMakeLists.txt | 5 ++++- src/os/unix/CMakeLists.txt | 5 ++++- src/os/windows/CMakeLists.txt | 5 ++++- 8 files changed, 32 insertions(+), 15 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 19ebc760d6..e911625cfa 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -224,7 +224,8 @@ include_directories(${CMAKE_SOURCE_DIR}/src/3rdparty/squirrel/include) include(MSVCFilters) -add_executable(openttd WIN32 ${GENERATED_SOURCE_FILES}) +add_library(openttd_lib OBJECT ${GENERATED_SOURCE_FILES}) +add_executable(openttd WIN32) set_target_properties(openttd PROPERTIES OUTPUT_NAME "${BINARY_NAME}") # All other files are added via target_sources() @@ -240,17 +241,21 @@ add_subdirectory(${CMAKE_SOURCE_DIR}/media) add_dependencies(openttd find_version) -target_link_libraries(openttd +target_link_libraries(openttd_lib openttd::languages openttd::settings - openttd::media - openttd::basesets openttd::script_api Threads::Threads ) +target_link_libraries(openttd + openttd_lib + openttd::media + openttd::basesets +) + if(HAIKU) - target_link_libraries(openttd "be" "network" "midi") + target_link_libraries(openttd_lib "be" "network" "midi") endif() if(IPO_FOUND) @@ -297,7 +302,7 @@ include(CheckAtomic) if(APPLE) link_package(Iconv TARGET Iconv::Iconv) - target_link_libraries(openttd + target_link_libraries(openttd_lib ${AUDIOTOOLBOX_LIBRARY} ${AUDIOUNIT_LIBRARY} ${COCOA_LIBRARY} @@ -376,7 +381,7 @@ if(WIN32) -DPSAPI_VERSION=1 ) - target_link_libraries(openttd + target_link_libraries(openttd_lib ws2_32 winmm imm32 diff --git a/cmake/CheckAtomic.cmake b/cmake/CheckAtomic.cmake index 52d93f4f5b..990c52c37c 100644 --- a/cmake/CheckAtomic.cmake +++ b/cmake/CheckAtomic.cmake @@ -83,5 +83,5 @@ else() endif() if(HAVE_CXX_ATOMICS_WITH_LIB OR HAVE_CXX_ATOMICS64_WITH_LIB) - target_link_libraries(openttd atomic) + target_link_libraries(openttd_lib atomic) endif() diff --git a/cmake/LinkPackage.cmake b/cmake/LinkPackage.cmake index bea9deb0cf..afbd921cf7 100644 --- a/cmake/LinkPackage.cmake +++ b/cmake/LinkPackage.cmake @@ -8,13 +8,13 @@ function(link_package NAME) # which (later) cmake considers to be an error. Work around this with by stripping the incoming string. if(LP_TARGET AND TARGET ${LP_TARGET}) string(STRIP "${LP_TARGET}" LP_TARGET) - target_link_libraries(openttd ${LP_TARGET}) + target_link_libraries(openttd_lib ${LP_TARGET}) message(STATUS "${NAME} found -- -DWITH_${UCNAME} -- ${LP_TARGET}") else() string(STRIP "${${NAME}_LIBRARY}" ${NAME}_LIBRARY) string(STRIP "${${NAME}_LIBRARIES}" ${NAME}_LIBRARIES) include_directories(${${NAME}_INCLUDE_DIRS} ${${NAME}_INCLUDE_DIR}) - target_link_libraries(openttd ${${NAME}_LIBRARIES} ${${NAME}_LIBRARY}) + target_link_libraries(openttd_lib ${${NAME}_LIBRARIES} ${${NAME}_LIBRARY}) message(STATUS "${NAME} found -- -DWITH_${UCNAME} -- ${${NAME}_INCLUDE_DIRS} ${${NAME}_INCLUDE_DIR} -- ${${NAME}_LIBRARIES} ${${NAME}_LIBRARY}") endif() elseif(LP_ENCOURAGED) diff --git a/cmake/SourceList.cmake b/cmake/SourceList.cmake index 6e95be2017..b576e20a02 100644 --- a/cmake/SourceList.cmake +++ b/cmake/SourceList.cmake @@ -17,7 +17,7 @@ function(add_files) endif() foreach(FILE IN LISTS PARAM_FILES) - target_sources(openttd PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/${FILE}) + target_sources(openttd_lib PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/${FILE}) endforeach() endfunction() diff --git a/src/os/macosx/CMakeLists.txt b/src/os/macosx/CMakeLists.txt index 6442d1a27b..acb30baf88 100644 --- a/src/os/macosx/CMakeLists.txt +++ b/src/os/macosx/CMakeLists.txt @@ -4,9 +4,12 @@ add_files( font_osx.h macos.h macos.mm - osx_main.cpp osx_stdafx.h string_osx.cpp string_osx.h CONDITION APPLE ) + +if(APPLE) + target_sources(openttd PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/osx_main.cpp) +endif() diff --git a/src/os/os2/CMakeLists.txt b/src/os/os2/CMakeLists.txt index fbcd4783b0..141dd98043 100644 --- a/src/os/os2/CMakeLists.txt +++ b/src/os/os2/CMakeLists.txt @@ -1,5 +1,8 @@ add_files( os2.cpp - os2_main.cpp CONDITION OPTION_OS2 ) + +if(OPTION_OS2) + target_sources(openttd PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/os2_main.cpp) +endif() diff --git a/src/os/unix/CMakeLists.txt b/src/os/unix/CMakeLists.txt index a8a421163d..a95d8ce2db 100644 --- a/src/os/unix/CMakeLists.txt +++ b/src/os/unix/CMakeLists.txt @@ -1,6 +1,5 @@ add_files( crashlog_unix.cpp - unix_main.cpp CONDITION UNIX AND NOT APPLE AND NOT OPTION_OS2 ) @@ -13,3 +12,7 @@ add_files( font_unix.cpp CONDITION Fontconfig_FOUND ) + +if(UNIX AND NOT APPLE AND NOT OPTION_OS2) + target_sources(openttd PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/unix_main.cpp) +endif() diff --git a/src/os/windows/CMakeLists.txt b/src/os/windows/CMakeLists.txt index 2f41ea16e5..a1b73a6d8f 100644 --- a/src/os/windows/CMakeLists.txt +++ b/src/os/windows/CMakeLists.txt @@ -6,6 +6,9 @@ add_files( string_uniscribe.h win32.cpp win32.h - win32_main.cpp CONDITION WIN32 ) + +if(WIN32) + target_sources(openttd PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/win32_main.cpp) +endif()