Add: introduce CMake for project management
CMake works on all our supported platforms, like MSVC, Mingw, GCC,
Clang, and many more. It allows for a single way of doing things,
so no longer we need shell scripts and vbs scripts to work on all
our supported platforms.
Additionally, CMake allows to generate project files for like MSVC,
KDevelop, etc.
This heavily reduces the lines of code we need to support multiple
platforms from a project perspective.
Addtiionally, this heavily improves our detection of libraries, etc.
2019-04-07 09:57:55 +00:00
|
|
|
cmake_minimum_required(VERSION 3.5)
|
|
|
|
|
2020-06-11 19:57:14 +00:00
|
|
|
if (NOT BINARY_NAME)
|
|
|
|
set(BINARY_NAME openttd)
|
|
|
|
endif (NOT BINARY_NAME)
|
|
|
|
|
|
|
|
project(${BINARY_NAME})
|
Add: introduce CMake for project management
CMake works on all our supported platforms, like MSVC, Mingw, GCC,
Clang, and many more. It allows for a single way of doing things,
so no longer we need shell scripts and vbs scripts to work on all
our supported platforms.
Additionally, CMake allows to generate project files for like MSVC,
KDevelop, etc.
This heavily reduces the lines of code we need to support multiple
platforms from a project perspective.
Addtiionally, this heavily improves our detection of libraries, etc.
2019-04-07 09:57:55 +00:00
|
|
|
|
|
|
|
if (CMAKE_SOURCE_DIR STREQUAL CMAKE_BINARY_DIR)
|
|
|
|
message(FATAL_ERROR "In-source builds not allowed. Please run \"cmake ..\" from the bin directory")
|
|
|
|
endif (CMAKE_SOURCE_DIR STREQUAL CMAKE_BINARY_DIR)
|
|
|
|
|
|
|
|
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake")
|
2020-06-04 19:59:30 +00:00
|
|
|
set(CMAKE_OSX_DEPLOYMENT_TARGET 10.9)
|
Add: introduce CMake for project management
CMake works on all our supported platforms, like MSVC, Mingw, GCC,
Clang, and many more. It allows for a single way of doing things,
so no longer we need shell scripts and vbs scripts to work on all
our supported platforms.
Additionally, CMake allows to generate project files for like MSVC,
KDevelop, etc.
This heavily reduces the lines of code we need to support multiple
platforms from a project perspective.
Addtiionally, this heavily improves our detection of libraries, etc.
2019-04-07 09:57:55 +00:00
|
|
|
|
2020-06-18 16:34:19 +00:00
|
|
|
# Use GNUInstallDirs to allow customisation
|
|
|
|
# but set our own default data dir
|
|
|
|
if (NOT CMAKE_INSTALL_DATADIR)
|
|
|
|
set(CMAKE_INSTALL_DATADIR "share/games")
|
|
|
|
endif (NOT CMAKE_INSTALL_DATADIR)
|
|
|
|
include(GNUInstallDirs)
|
|
|
|
|
Add: introduce CMake for project management
CMake works on all our supported platforms, like MSVC, Mingw, GCC,
Clang, and many more. It allows for a single way of doing things,
so no longer we need shell scripts and vbs scripts to work on all
our supported platforms.
Additionally, CMake allows to generate project files for like MSVC,
KDevelop, etc.
This heavily reduces the lines of code we need to support multiple
platforms from a project perspective.
Addtiionally, this heavily improves our detection of libraries, etc.
2019-04-07 09:57:55 +00:00
|
|
|
include(Options)
|
|
|
|
set_options()
|
|
|
|
set_directory_options()
|
|
|
|
|
|
|
|
include(Static)
|
|
|
|
set_static_if_needed()
|
|
|
|
|
|
|
|
# Prefer -pthread over -lpthread, which is often the better option of the two.
|
|
|
|
set(CMAKE_THREAD_PREFER_PTHREAD YES)
|
|
|
|
# Make sure we have Threads available.
|
|
|
|
find_package(Threads REQUIRED)
|
|
|
|
|
|
|
|
find_package(ZLIB)
|
|
|
|
find_package(LibLZMA)
|
|
|
|
find_package(LZO)
|
|
|
|
find_package(PNG)
|
2020-06-18 12:24:29 +00:00
|
|
|
|
Add: introduce CMake for project management
CMake works on all our supported platforms, like MSVC, Mingw, GCC,
Clang, and many more. It allows for a single way of doing things,
so no longer we need shell scripts and vbs scripts to work on all
our supported platforms.
Additionally, CMake allows to generate project files for like MSVC,
KDevelop, etc.
This heavily reduces the lines of code we need to support multiple
platforms from a project perspective.
Addtiionally, this heavily improves our detection of libraries, etc.
2019-04-07 09:57:55 +00:00
|
|
|
if (NOT WIN32)
|
|
|
|
find_package(Allegro)
|
2020-06-04 07:48:59 +00:00
|
|
|
if (NOT APPLE)
|
2020-06-18 12:24:29 +00:00
|
|
|
find_package(SDL2)
|
|
|
|
if (NOT SDL2_FOUND)
|
|
|
|
find_package(SDL)
|
|
|
|
endif( NOT SDL2_FOUND)
|
|
|
|
find_package(Fluidsynth)
|
|
|
|
find_package(Freetype)
|
|
|
|
find_package(Fontconfig)
|
2020-06-04 07:48:59 +00:00
|
|
|
find_package(ICU OPTIONAL_COMPONENTS i18n lx)
|
2020-06-18 12:24:29 +00:00
|
|
|
find_package(XDG_basedir)
|
|
|
|
else (NOT APPLE)
|
|
|
|
find_package(Iconv)
|
|
|
|
|
|
|
|
find_library(AUDIOTOOLBOX_LIBRARY AudioToolbox)
|
|
|
|
find_library(AUDIOUNIT_LIBRARY AudioUnit)
|
|
|
|
find_library(COCOA_LIBRARY Cocoa)
|
2020-06-04 07:48:59 +00:00
|
|
|
endif (NOT APPLE)
|
Add: introduce CMake for project management
CMake works on all our supported platforms, like MSVC, Mingw, GCC,
Clang, and many more. It allows for a single way of doing things,
so no longer we need shell scripts and vbs scripts to work on all
our supported platforms.
Additionally, CMake allows to generate project files for like MSVC,
KDevelop, etc.
This heavily reduces the lines of code we need to support multiple
platforms from a project perspective.
Addtiionally, this heavily improves our detection of libraries, etc.
2019-04-07 09:57:55 +00:00
|
|
|
endif (NOT WIN32)
|
|
|
|
|
|
|
|
if (MSVC)
|
|
|
|
find_package(Editbin REQUIRED)
|
|
|
|
endif (MSVC)
|
|
|
|
|
|
|
|
find_package(SSE)
|
|
|
|
find_package(Xaudio2)
|
|
|
|
|
|
|
|
find_package(Grfcodec)
|
|
|
|
|
|
|
|
# IPO is only properly supported from CMake 3.9. Despite the fact we are
|
|
|
|
# CMake 3.5, still enable IPO if we detect we are 3.9+.
|
|
|
|
if (POLICY CMP0069)
|
|
|
|
cmake_policy(SET CMP0069 NEW)
|
|
|
|
include(CheckIPOSupported)
|
|
|
|
check_ipo_supported(RESULT IPO_FOUND)
|
|
|
|
endif (POLICY CMP0069)
|
|
|
|
|
|
|
|
show_options()
|
|
|
|
|
|
|
|
if (UNIX AND NOT APPLE AND NOT OPTION_DEDICATED)
|
|
|
|
if (NOT SDL_FOUND AND NOT SDL2_FOUND)
|
|
|
|
message(FATAL_ERROR "SDL or SDL2 is required for this platform")
|
|
|
|
endif (NOT SDL_FOUND AND NOT SDL2_FOUND)
|
|
|
|
endif (UNIX AND NOT APPLE AND NOT OPTION_DEDICATED)
|
|
|
|
if (APPLE)
|
|
|
|
if (NOT AUDIOTOOLBOX_LIBRARY)
|
|
|
|
message(FATAL_ERROR "AudioToolbox is required for this platform")
|
|
|
|
endif (NOT AUDIOTOOLBOX_LIBRARY)
|
|
|
|
if (NOT AUDIOUNIT_LIBRARY)
|
|
|
|
message(FATAL_ERROR "AudioUnit is required for this platform")
|
|
|
|
endif (NOT AUDIOUNIT_LIBRARY)
|
|
|
|
if (NOT COCOA_LIBRARY)
|
|
|
|
message(FATAL_ERROR "Cocoa is required for this platform")
|
|
|
|
endif (NOT COCOA_LIBRARY)
|
|
|
|
endif (APPLE)
|
|
|
|
|
|
|
|
if (MSVC)
|
|
|
|
# C++17 for MSVC
|
|
|
|
set(CMAKE_CXX_STANDARD 17)
|
|
|
|
else (MSVC)
|
|
|
|
# C++11 for all other targets
|
|
|
|
set(CMAKE_CXX_STANDARD 11)
|
|
|
|
endif (MSVC)
|
|
|
|
|
|
|
|
set(CMAKE_CXX_STANDARD_REQUIRED YES)
|
|
|
|
set(CMAKE_CXX_EXTENSIONS NO)
|
|
|
|
|
2020-06-12 14:33:04 +00:00
|
|
|
set(CMAKE_EXPORT_COMPILE_COMMANDS YES)
|
|
|
|
|
Add: introduce CMake for project management
CMake works on all our supported platforms, like MSVC, Mingw, GCC,
Clang, and many more. It allows for a single way of doing things,
so no longer we need shell scripts and vbs scripts to work on all
our supported platforms.
Additionally, CMake allows to generate project files for like MSVC,
KDevelop, etc.
This heavily reduces the lines of code we need to support multiple
platforms from a project perspective.
Addtiionally, this heavily improves our detection of libraries, etc.
2019-04-07 09:57:55 +00:00
|
|
|
list(APPEND GENERATED_SOURCE_FILES "${CMAKE_BINARY_DIR}/generated/rev.cpp")
|
|
|
|
if (WIN32)
|
|
|
|
list(APPEND GENERATED_SOURCE_FILES "${CMAKE_BINARY_DIR}/generated/ottdres.rc")
|
|
|
|
endif (WIN32)
|
|
|
|
|
|
|
|
# Generate a target to determine version, which is execute every 'make' run
|
|
|
|
add_custom_target(find_version
|
|
|
|
${CMAKE_COMMAND}
|
|
|
|
-DFIND_VERSION_BINARY_DIR=${CMAKE_BINARY_DIR}/generated
|
|
|
|
-DCPACK_BINARY_DIR=${CMAKE_BINARY_DIR}
|
|
|
|
-P "${CMAKE_SOURCE_DIR}/cmake/scripts/FindVersion.cmake"
|
|
|
|
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
|
|
|
|
BYPRODUCTS ${GENERATED_SOURCE_FILES}
|
|
|
|
)
|
|
|
|
|
|
|
|
include(SourceList)
|
|
|
|
include(Endian)
|
|
|
|
add_endian_definition()
|
|
|
|
|
|
|
|
# Needed by rev.cpp
|
|
|
|
include_directories(${CMAKE_SOURCE_DIR}/src)
|
|
|
|
# Needed by everything that uses Squirrel
|
|
|
|
include_directories(${CMAKE_SOURCE_DIR}/src/3rdparty/squirrel/include)
|
|
|
|
|
2020-07-05 12:39:39 +00:00
|
|
|
include(MSVCFilters)
|
|
|
|
|
Add: introduce CMake for project management
CMake works on all our supported platforms, like MSVC, Mingw, GCC,
Clang, and many more. It allows for a single way of doing things,
so no longer we need shell scripts and vbs scripts to work on all
our supported platforms.
Additionally, CMake allows to generate project files for like MSVC,
KDevelop, etc.
This heavily reduces the lines of code we need to support multiple
platforms from a project perspective.
Addtiionally, this heavily improves our detection of libraries, etc.
2019-04-07 09:57:55 +00:00
|
|
|
include(CompileFlags)
|
|
|
|
compile_flags()
|
|
|
|
|
|
|
|
add_executable(openttd WIN32 ${GENERATED_SOURCE_FILES})
|
2020-06-11 19:57:14 +00:00
|
|
|
set_target_properties(openttd PROPERTIES OUTPUT_NAME "${BINARY_NAME}")
|
Add: introduce CMake for project management
CMake works on all our supported platforms, like MSVC, Mingw, GCC,
Clang, and many more. It allows for a single way of doing things,
so no longer we need shell scripts and vbs scripts to work on all
our supported platforms.
Additionally, CMake allows to generate project files for like MSVC,
KDevelop, etc.
This heavily reduces the lines of code we need to support multiple
platforms from a project perspective.
Addtiionally, this heavily improves our detection of libraries, etc.
2019-04-07 09:57:55 +00:00
|
|
|
# All other files are added via target_sources()
|
|
|
|
|
|
|
|
include(AddCustomXXXTimestamp)
|
|
|
|
add_subdirectory(${CMAKE_SOURCE_DIR}/src)
|
|
|
|
add_subdirectory(${CMAKE_SOURCE_DIR}/media/baseset)
|
|
|
|
|
|
|
|
add_dependencies(openttd
|
|
|
|
find_version)
|
|
|
|
|
|
|
|
target_link_libraries(openttd
|
|
|
|
openttd::languages
|
|
|
|
openttd::settings
|
|
|
|
openttd::basesets
|
2019-03-05 14:52:41 +00:00
|
|
|
openttd::script_api
|
Add: introduce CMake for project management
CMake works on all our supported platforms, like MSVC, Mingw, GCC,
Clang, and many more. It allows for a single way of doing things,
so no longer we need shell scripts and vbs scripts to work on all
our supported platforms.
Additionally, CMake allows to generate project files for like MSVC,
KDevelop, etc.
This heavily reduces the lines of code we need to support multiple
platforms from a project perspective.
Addtiionally, this heavily improves our detection of libraries, etc.
2019-04-07 09:57:55 +00:00
|
|
|
Threads::Threads
|
|
|
|
)
|
|
|
|
|
|
|
|
if (IPO_FOUND)
|
|
|
|
set_target_properties(openttd PROPERTIES INTERPROCEDURAL_OPTIMIZATION_RELEASE True)
|
|
|
|
set_target_properties(openttd PROPERTIES INTERPROCEDURAL_OPTIMIZATION_MINSIZEREL True)
|
|
|
|
set_target_properties(openttd PROPERTIES INTERPROCEDURAL_OPTIMIZATION_RELWITHDEBINFO True)
|
|
|
|
endif (IPO_FOUND)
|
|
|
|
set_target_properties(openttd PROPERTIES VS_DEBUGGER_WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}/bin")
|
|
|
|
process_compile_flags()
|
|
|
|
|
|
|
|
if (APPLE OR UNIX)
|
|
|
|
add_definitions(-DUNIX)
|
|
|
|
endif (APPLE OR UNIX)
|
|
|
|
|
|
|
|
include(LinkPackage)
|
|
|
|
link_package(PNG TARGET PNG::PNG ENCOURAGED)
|
|
|
|
link_package(ZLIB TARGET ZLIB::ZLIB ENCOURAGED)
|
|
|
|
link_package(LIBLZMA TARGET LibLZMA::LibLZMA ENCOURAGED)
|
|
|
|
link_package(LZO ENCOURAGED)
|
|
|
|
link_package(XDG_basedir)
|
|
|
|
|
|
|
|
if (NOT OPTION_DEDICATED)
|
|
|
|
link_package(Fluidsynth)
|
|
|
|
link_package(SDL)
|
2020-06-07 10:06:40 +00:00
|
|
|
link_package(SDL2 TARGET SDL2::SDL2)
|
Add: introduce CMake for project management
CMake works on all our supported platforms, like MSVC, Mingw, GCC,
Clang, and many more. It allows for a single way of doing things,
so no longer we need shell scripts and vbs scripts to work on all
our supported platforms.
Additionally, CMake allows to generate project files for like MSVC,
KDevelop, etc.
This heavily reduces the lines of code we need to support multiple
platforms from a project perspective.
Addtiionally, this heavily improves our detection of libraries, etc.
2019-04-07 09:57:55 +00:00
|
|
|
link_package(Allegro)
|
|
|
|
link_package(FREETYPE TARGET Freetype::Freetype)
|
|
|
|
link_package(Fontconfig TARGET Fontconfig::Fontconfig)
|
|
|
|
link_package(ICU_lx)
|
|
|
|
link_package(ICU_i18n)
|
|
|
|
endif (NOT OPTION_DEDICATED)
|
|
|
|
|
|
|
|
if (APPLE)
|
|
|
|
link_package(Iconv TARGET Iconv::Iconv)
|
|
|
|
|
|
|
|
target_link_libraries(openttd
|
|
|
|
${AUDIOTOOLBOX_LIBRARY}
|
|
|
|
${AUDIOUNIT_LIBRARY}
|
|
|
|
${COCOA_LIBRARY}
|
|
|
|
)
|
|
|
|
|
|
|
|
add_definitions(
|
|
|
|
-DWITH_COCOA
|
|
|
|
-DENABLE_COCOA_QUARTZ
|
|
|
|
)
|
|
|
|
endif (APPLE)
|
|
|
|
|
|
|
|
if (NOT PERSONAL_DIR STREQUAL "(not set)")
|
|
|
|
add_definitions(
|
|
|
|
-DWITH_PERSONAL_DIR
|
|
|
|
-DPERSONAL_DIR="${PERSONAL_DIR}"
|
|
|
|
)
|
|
|
|
endif (NOT PERSONAL_DIR STREQUAL "(not set)")
|
|
|
|
|
|
|
|
if (NOT SHARED_DIR STREQUAL "(not set)")
|
|
|
|
add_definitions(
|
|
|
|
-DWITH_SHARED_DIR
|
|
|
|
-DSHARED_DIR="${SHARED_DIR}"
|
|
|
|
)
|
|
|
|
endif (NOT SHARED_DIR STREQUAL "(not set)")
|
|
|
|
|
|
|
|
if (NOT GLOBAL_DIR STREQUAL "(not set)")
|
|
|
|
add_definitions(
|
|
|
|
-DGLOBAL_DATA_DIR="${GLOBAL_DIR}"
|
|
|
|
)
|
|
|
|
endif (NOT GLOBAL_DIR STREQUAL "(not set)")
|
|
|
|
|
|
|
|
link_package(SSE)
|
|
|
|
|
|
|
|
add_definitions_based_on_options()
|
|
|
|
|
|
|
|
if (WIN32)
|
|
|
|
add_definitions(
|
|
|
|
-DUNICODE
|
|
|
|
-D_UNICODE
|
|
|
|
-DWITH_UNISCRIBE
|
|
|
|
)
|
|
|
|
|
|
|
|
target_link_libraries(openttd
|
|
|
|
ws2_32
|
|
|
|
winmm
|
|
|
|
imm32
|
|
|
|
)
|
|
|
|
endif (WIN32)
|
|
|
|
|
|
|
|
if (CMAKE_SIZEOF_VOID_P EQUAL 8)
|
|
|
|
add_definitions(-D_SQ64)
|
|
|
|
endif (CMAKE_SIZEOF_VOID_P EQUAL 8)
|
|
|
|
|
|
|
|
include(CreateRegression)
|
|
|
|
create_regression()
|
2019-04-07 10:00:36 +00:00
|
|
|
|
|
|
|
include(InstallAndPackage)
|