2019-01-26 18:41:56 +01:00
|
|
|
cmake_minimum_required(VERSION 3.9)
|
2019-03-02 09:48:04 +01:00
|
|
|
project(libopenrct2 CXX)
|
|
|
|
|
2017-03-24 20:02:23 +01:00
|
|
|
if (CMAKE_BINARY_DIR STREQUAL CMAKE_SOURCE_DIR)
|
|
|
|
message(FATAL_ERROR "Building in-source is not supported! Create a build dir and remove ${CMAKE_SOURCE_DIR}/CMakeCache.txt")
|
2017-03-25 02:40:16 +01:00
|
|
|
endif ()
|
2017-03-24 20:02:23 +01:00
|
|
|
|
2019-03-02 09:48:04 +01:00
|
|
|
file(GLOB_RECURSE OPENRCT2_CORE_SOURCES "${CMAKE_CURRENT_LIST_DIR}/*.cpp")
|
|
|
|
file(GLOB_RECURSE OPENRCT2_CORE_HEADERS "${CMAKE_CURRENT_LIST_DIR}/*.h"
|
|
|
|
"${CMAKE_CURRENT_LIST_DIR}/*.hpp")
|
2017-03-25 02:40:16 +01:00
|
|
|
if (APPLE)
|
2019-03-02 09:48:04 +01:00
|
|
|
file(GLOB_RECURSE OPENRCT2_CORE_MM_SOURCES "${CMAKE_CURRENT_LIST_DIR}/*.mm")
|
|
|
|
set_source_files_properties(${OPENRCT2_CORE_MM_SOURCES} PROPERTIES COMPILE_FLAGS "-x objective-c++ -fmodules")
|
2017-03-25 02:40:16 +01:00
|
|
|
endif ()
|
|
|
|
|
2019-03-02 09:48:04 +01:00
|
|
|
add_library(${PROJECT_NAME} ${OPENRCT2_CORE_SOURCES} ${OPENRCT2_CORE_MM_SOURCES} ${RCT2_SECTIONS})
|
|
|
|
set_target_properties(${PROJECT_NAME} PROPERTIES PREFIX "")
|
|
|
|
SET_CHECK_CXX_FLAGS(${PROJECT_NAME})
|
2017-03-25 02:40:16 +01:00
|
|
|
|
2020-01-28 14:31:03 +01:00
|
|
|
# GCC / Clang likes us to pass the -lstdc++fs flag to link C++17 filesystem implementation.
|
|
|
|
if (NOT MINGW)
|
|
|
|
if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
|
|
|
|
target_link_libraries(${PROJECT_NAME} stdc++fs)
|
|
|
|
endif()
|
2020-01-09 19:57:28 +01:00
|
|
|
endif()
|
|
|
|
|
2019-03-02 09:23:13 +01:00
|
|
|
if (NOT DISABLE_NETWORK OR NOT DISABLE_HTTP)
|
2020-02-05 22:28:59 +01:00
|
|
|
if (WIN32)
|
|
|
|
target_link_libraries(${PROJECT_NAME} bcrypt)
|
2019-03-02 09:23:13 +01:00
|
|
|
else ()
|
2020-02-05 22:28:59 +01:00
|
|
|
if (APPLE)
|
|
|
|
# Needed for linking with non-broken OpenSSL on Apple platforms
|
|
|
|
set(ENV{PKG_CONFIG_PATH} "$ENV{PKG_CONFIG_PATH}:/usr/local/opt/openssl/lib/pkgconfig")
|
|
|
|
endif ()
|
|
|
|
|
|
|
|
find_package(OpenSSL 1.0.0 REQUIRED)
|
|
|
|
|
|
|
|
target_include_directories(${PROJECT_NAME} PUBLIC ${OPENSSL_INCLUDE_DIR})
|
|
|
|
|
|
|
|
if(STATIC)
|
|
|
|
target_link_libraries(${PROJECT_NAME} ${SSL_STATIC_LIBRARIES})
|
|
|
|
else ()
|
|
|
|
target_link_libraries(${PROJECT_NAME} ${OPENSSL_LIBRARIES})
|
|
|
|
endif()
|
2019-03-02 09:23:13 +01:00
|
|
|
endif()
|
2019-03-02 09:20:25 +01:00
|
|
|
endif ()
|
|
|
|
|
|
|
|
if (NOT DISABLE_NETWORK AND WIN32)
|
2019-03-02 09:48:04 +01:00
|
|
|
target_link_libraries(${PROJECT_NAME} ws2_32 crypt32 wldap32 version winmm imm32 advapi32 shell32 ole32)
|
2019-03-02 09:20:25 +01:00
|
|
|
endif ()
|
|
|
|
|
2019-03-02 08:55:21 +01:00
|
|
|
if (NOT DISABLE_HTTP)
|
2020-02-04 00:11:38 +01:00
|
|
|
if (WIN32)
|
|
|
|
target_link_libraries(${PROJECT_NAME} winhttp)
|
2018-04-13 20:21:03 +02:00
|
|
|
else ()
|
|
|
|
PKG_CHECK_MODULES(LIBCURL REQUIRED libcurl)
|
2020-02-04 00:11:38 +01:00
|
|
|
|
|
|
|
target_include_directories(${PROJECT_NAME} PRIVATE ${LIBCURL_INCLUDE_DIRS})
|
|
|
|
|
|
|
|
if (STATIC)
|
|
|
|
target_link_libraries(${PROJECT_NAME} ${LIBCURL_STATIC_LIBRARIES})
|
|
|
|
else ()
|
|
|
|
target_link_libraries(${PROJECT_NAME} ${LIBCURL_LIBRARIES})
|
|
|
|
endif ()
|
2019-03-02 08:55:21 +01:00
|
|
|
endif ()
|
2017-03-25 02:40:16 +01:00
|
|
|
endif ()
|
|
|
|
|
|
|
|
if (NOT DISABLE_TTF)
|
2018-04-13 20:21:03 +02:00
|
|
|
if (UNIX AND NOT APPLE AND NOT MSVC)
|
2017-05-29 10:47:52 +02:00
|
|
|
PKG_CHECK_MODULES(FONTCONFIG REQUIRED fontconfig)
|
|
|
|
endif ()
|
2019-03-02 09:48:04 +01:00
|
|
|
|
2018-04-13 20:21:03 +02:00
|
|
|
if (MSVC)
|
|
|
|
find_package(freetype REQUIRED)
|
|
|
|
else ()
|
|
|
|
PKG_CHECK_MODULES(FREETYPE REQUIRED freetype2)
|
|
|
|
endif ()
|
2019-03-02 09:48:04 +01:00
|
|
|
|
|
|
|
target_include_directories(${PROJECT_NAME} PRIVATE ${FREETYPE_INCLUDE_DIRS})
|
|
|
|
|
|
|
|
if (UNIX AND NOT APPLE)
|
|
|
|
target_include_directories(${PROJECT_NAME} PRIVATE ${FONTCONFIG_INCLUDE_DIRS})
|
|
|
|
endif ()
|
2017-03-25 02:40:16 +01:00
|
|
|
endif ()
|
2017-03-24 20:02:23 +01:00
|
|
|
|
2019-11-09 21:20:16 +01:00
|
|
|
if (NOT DISABLE_GOOGLE_BENCHMARK)
|
2020-02-12 22:18:00 +01:00
|
|
|
find_package(benchmark)
|
2019-11-09 21:20:16 +01:00
|
|
|
if (benchmark_FOUND)
|
|
|
|
message("Found Google benchmark, enabling support")
|
|
|
|
set_target_properties(${PROJECT_NAME} PROPERTIES COMPILE_DEFINITIONS USE_BENCHMARK)
|
|
|
|
target_link_libraries(${PROJECT_NAME} benchmark::benchmark)
|
|
|
|
target_include_directories(${PROJECT_NAME} PRIVATE ${benchmark_INCLUDE_DIRS})
|
|
|
|
else ()
|
|
|
|
message("Google benchmark not found, disabling support")
|
|
|
|
endif ()
|
2018-12-15 23:41:38 +01:00
|
|
|
endif ()
|
|
|
|
|
2019-03-02 09:48:04 +01:00
|
|
|
# Third party libraries
|
|
|
|
if (MSVC)
|
2019-10-15 23:14:00 +02:00
|
|
|
find_package(jansson CONFIG REQUIRED)
|
|
|
|
set(JANSSON_LIBRARIES "jansson::jansson")
|
2019-03-02 09:48:04 +01:00
|
|
|
find_package(png 1.6 REQUIRED)
|
|
|
|
find_package(zlib REQUIRED)
|
|
|
|
|
|
|
|
find_path(LIBZIP_INCLUDE_DIRS zip.h)
|
|
|
|
find_library(LIBZIP_LIBRARIES zip)
|
|
|
|
else ()
|
|
|
|
PKG_CHECK_MODULES(JANSSON REQUIRED jansson>=2.5)
|
|
|
|
PKG_CHECK_MODULES(LIBZIP REQUIRED libzip>=1.0)
|
|
|
|
PKG_CHECK_MODULES(ZLIB REQUIRED zlib)
|
|
|
|
|
|
|
|
PKG_CHECK_MODULES(PNG libpng>=1.6)
|
|
|
|
if (NOT PNG_FOUND)
|
|
|
|
PKG_CHECK_MODULES(PNG libpng16)
|
|
|
|
if (NOT PNG_FOUND)
|
|
|
|
PKG_CHECK_MODULES(PNG libpng>=1.2)
|
|
|
|
if (NOT PNG_FOUND)
|
|
|
|
PKG_CHECK_MODULES(PNG REQUIRED libpng12)
|
|
|
|
endif ()
|
|
|
|
endif ()
|
|
|
|
endif ()
|
|
|
|
endif ()
|
|
|
|
|
2017-03-25 02:40:16 +01:00
|
|
|
if (STATIC)
|
2019-03-02 09:48:04 +01:00
|
|
|
target_link_libraries(${PROJECT_NAME} ${JANSSON_STATIC_LIBRARIES}
|
2017-03-25 02:40:16 +01:00
|
|
|
${PNG_STATIC_LIBRARIES}
|
|
|
|
${ZLIB_STATIC_LIBRARIES}
|
2018-05-15 16:37:41 +02:00
|
|
|
${LIBZIP_STATIC_LIBRARIES})
|
2017-03-25 02:40:16 +01:00
|
|
|
else ()
|
2019-03-02 09:48:04 +01:00
|
|
|
target_link_libraries(${PROJECT_NAME} ${JANSSON_LIBRARIES}
|
2017-03-25 02:40:16 +01:00
|
|
|
${PNG_LIBRARIES}
|
|
|
|
${ZLIB_LIBRARIES}
|
2018-05-15 16:37:41 +02:00
|
|
|
${LIBZIP_LIBRARIES})
|
2017-03-25 02:40:16 +01:00
|
|
|
endif ()
|
2017-03-25 00:11:29 +01:00
|
|
|
|
2017-03-25 02:40:16 +01:00
|
|
|
if (UNIX AND NOT ${CMAKE_SYSTEM_NAME} MATCHES "BSD")
|
|
|
|
# Include libdl for dlopen
|
2019-03-02 09:48:04 +01:00
|
|
|
target_link_libraries(${PROJECT_NAME} dl)
|
2017-03-25 02:40:16 +01:00
|
|
|
endif ()
|
|
|
|
|
2019-03-02 08:55:21 +01:00
|
|
|
set(THREADS_PREFER_PTHREAD_FLAG ON)
|
|
|
|
find_package(Threads REQUIRED)
|
2019-03-02 09:48:04 +01:00
|
|
|
target_link_libraries(${PROJECT_NAME} Threads::Threads)
|
2019-03-02 08:55:21 +01:00
|
|
|
|
2018-05-15 16:37:41 +02:00
|
|
|
if (NOT MINGW AND NOT MSVC)
|
|
|
|
# For unicode code page conversion.
|
|
|
|
find_package(ICU 59.0 REQUIRED COMPONENTS uc)
|
2019-03-02 09:48:04 +01:00
|
|
|
|
|
|
|
target_include_directories(${PROJECT_NAME} SYSTEM PRIVATE ${ICU_INCLUDE_DIRS})
|
|
|
|
|
2018-05-15 16:37:41 +02:00
|
|
|
if (STATIC)
|
2019-03-02 09:48:04 +01:00
|
|
|
target_link_libraries(${PROJECT_NAME} ${ICU_STATIC_LIBRARIES})
|
2018-05-15 16:37:41 +02:00
|
|
|
else ()
|
2019-03-02 09:48:04 +01:00
|
|
|
target_link_libraries(${PROJECT_NAME} ${ICU_LIBRARIES})
|
2018-05-15 16:37:41 +02:00
|
|
|
endif ()
|
|
|
|
endif ()
|
|
|
|
|
2018-04-13 00:07:18 +02:00
|
|
|
if (NOT APPLE AND NOT MINGW AND NOT MSVC)
|
2018-02-11 21:25:42 +01:00
|
|
|
# This is ugly hack to work around https://bugs.launchpad.net/ubuntu/+source/gcc-5/+bug/1568899.
|
|
|
|
# Once C++17 is enabled (and thus old compilers are no longer supported, this needs to be gone.
|
|
|
|
# We cannot simply detect the _compiler_ version, as the bug exists with the C++ _library_
|
2019-03-02 09:48:04 +01:00
|
|
|
target_link_libraries(${PROJECT_NAME} gcc_s gcc)
|
2018-02-11 21:25:42 +01:00
|
|
|
endif ()
|
2017-03-25 02:40:16 +01:00
|
|
|
|
|
|
|
if (NOT DISABLE_TTF)
|
|
|
|
if (STATIC)
|
2019-03-02 09:48:04 +01:00
|
|
|
target_link_libraries(${PROJECT_NAME} ${FREETYPE_STATIC_LIBRARIES})
|
|
|
|
|
2017-03-25 02:40:16 +01:00
|
|
|
if (UNIX AND NOT APPLE)
|
2019-03-02 09:48:04 +01:00
|
|
|
target_link_libraries(${PROJECT_NAME} ${FONTCONFIG_STATIC_LIBRARIES})
|
2017-03-25 02:40:16 +01:00
|
|
|
endif ()
|
|
|
|
else ()
|
2019-03-02 09:48:04 +01:00
|
|
|
target_link_libraries(${PROJECT_NAME} ${FREETYPE_LIBRARIES})
|
|
|
|
|
2017-03-25 02:40:16 +01:00
|
|
|
if (UNIX AND NOT APPLE)
|
2019-03-02 09:48:04 +01:00
|
|
|
target_link_libraries(${PROJECT_NAME} ${FONTCONFIG_LIBRARIES})
|
2017-03-25 02:40:16 +01:00
|
|
|
endif ()
|
|
|
|
endif ()
|
|
|
|
endif ()
|
2017-03-25 00:11:29 +01:00
|
|
|
|
2017-11-12 22:11:39 +01:00
|
|
|
if (HAVE_DISCORD_RPC)
|
|
|
|
target_link_libraries(libopenrct2 discord-rpc)
|
|
|
|
endif()
|
|
|
|
|
2017-03-24 21:52:07 +01:00
|
|
|
# Includes
|
2019-03-02 09:48:04 +01:00
|
|
|
target_include_directories(${PROJECT_NAME} PRIVATE ${LIBZIP_INCLUDE_DIRS})
|
|
|
|
target_include_directories(${PROJECT_NAME} PUBLIC ${JANSSON_INCLUDE_DIRS})
|
|
|
|
target_include_directories(${PROJECT_NAME} PRIVATE ${PNG_INCLUDE_DIRS}
|
2017-03-25 02:40:16 +01:00
|
|
|
${ZLIB_INCLUDE_DIRS})
|
2017-03-24 20:02:23 +01:00
|
|
|
|
2017-10-16 21:22:23 +02:00
|
|
|
# To avoid unnecessary rebuilds set the current branch and
|
|
|
|
# short sha1 only for the two files that use these
|
|
|
|
# definitions: Version.cpp and Crash/Platform.cpp
|
2018-06-14 15:31:31 +02:00
|
|
|
set_property(SOURCE ${CMAKE_CURRENT_LIST_DIR}/Version.cpp ${CMAKE_CURRENT_LIST_DIR}/Crash/Platform.cpp
|
|
|
|
PROPERTY COMPILE_DEFINITIONS
|
|
|
|
OPENRCT2_VERSION_TAG="${OPENRCT2_VERSION_TAG}")
|
|
|
|
|
|
|
|
if (NOT OPENRCT2_BRANCH STREQUAL "master")
|
|
|
|
set_property(SOURCE ${CMAKE_CURRENT_LIST_DIR}/Version.cpp ${CMAKE_CURRENT_LIST_DIR}/Crash/Platform.cpp
|
|
|
|
APPEND PROPERTY COMPILE_DEFINITIONS
|
|
|
|
OPENRCT2_BRANCH="${OPENRCT2_BRANCH}")
|
|
|
|
endif()
|
|
|
|
|
2017-10-16 21:22:23 +02:00
|
|
|
if (NOT OPENRCT2_COMMIT_SHA1_SHORT STREQUAL "HEAD")
|
2018-06-14 15:31:31 +02:00
|
|
|
set_property(SOURCE ${CMAKE_CURRENT_LIST_DIR}/Version.cpp ${CMAKE_CURRENT_LIST_DIR}/Crash/Platform.cpp
|
|
|
|
APPEND PROPERTY COMPILE_DEFINITIONS
|
|
|
|
OPENRCT2_COMMIT_SHA1_SHORT="${OPENRCT2_COMMIT_SHA1_SHORT}")
|
2017-10-16 21:22:23 +02:00
|
|
|
endif()
|
2017-12-19 23:02:04 +01:00
|
|
|
|
2018-04-13 00:07:18 +02:00
|
|
|
if((X86 OR X86_64) AND NOT MSVC)
|
|
|
|
set_source_files_properties(${CMAKE_CURRENT_LIST_DIR}/drawing/SSE41Drawing.cpp PROPERTIES COMPILE_FLAGS -msse4.1)
|
|
|
|
set_source_files_properties(${CMAKE_CURRENT_LIST_DIR}/drawing/AVX2Drawing.cpp PROPERTIES COMPILE_FLAGS -mavx2)
|
2017-12-19 23:02:04 +01:00
|
|
|
endif()
|
2018-06-03 22:54:01 +02:00
|
|
|
|
|
|
|
# Add headers check to verify all headers carry their dependencies.
|
|
|
|
# Only valid for Clang for now:
|
|
|
|
# - GCC 8 does not support -Wno-pragma-once-outside-header
|
|
|
|
# - Other compilers status unknown
|
|
|
|
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
|
2019-03-02 09:48:04 +01:00
|
|
|
add_library(${PROJECT_NAME}-headers-check OBJECT ${OPENRCT2_CORE_HEADERS})
|
|
|
|
set_target_properties(${PROJECT_NAME}-headers-check PROPERTIES LINKER_LANGUAGE CXX)
|
2018-06-03 22:54:01 +02:00
|
|
|
set_source_files_properties(${OPENRCT2_CORE_HEADERS} PROPERTIES LANGUAGE CXX)
|
|
|
|
add_definitions("-x c++ -Wno-pragma-once-outside-header -Wno-unused-const-variable")
|
2019-03-02 09:48:04 +01:00
|
|
|
get_target_property(LIBOPENRCT2_INCLUDE_DIRS ${PROJECT_NAME} INCLUDE_DIRECTORIES)
|
|
|
|
set_target_properties(${PROJECT_NAME}-headers-check PROPERTIES INCLUDE_DIRECTORIES "${LIBOPENRCT2_INCLUDE_DIRS}")
|
2018-06-03 22:54:01 +02:00
|
|
|
else ()
|
|
|
|
# Dummy target to ease invocation
|
2019-03-02 09:48:04 +01:00
|
|
|
add_custom_target(${PROJECT_NAME}-headers-check)
|
2018-06-03 22:54:01 +02:00
|
|
|
endif ()
|