Codechange: split building into a library and executable

pull/544/head
Rubidium 1 year ago committed by rubidium42
parent 9e89eb5726
commit 9b56505fec

@ -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

@ -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()

@ -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)

@ -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()

@ -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()

@ -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()

@ -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()

@ -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()

Loading…
Cancel
Save