2012-09-29 15:19:23 +00:00
##
# Main CMake project file
# Contains global options and definitions
##
2012-04-14 23:02:51 +00:00
2021-09-04 18:50:10 +00:00
cmake_minimum_required ( VERSION 3.16 )
2012-04-14 23:02:51 +00:00
2012-06-25 17:59:17 +00:00
project ( colobot C CXX )
2012-04-14 23:02:51 +00:00
2021-09-04 20:27:06 +00:00
set ( CMAKE_CXX_STANDARD 17 )
2020-07-11 15:20:41 +00:00
set ( CMAKE_CXX_STANDARD_REQUIRED YES )
set ( CMAKE_CXX_EXTENSIONS NO )
2012-12-27 16:10:45 +00:00
##
# Project version
##
set ( COLOBOT_VERSION_CODENAME "Gold" )
set ( COLOBOT_VERSION_MAJOR 0 )
2021-08-21 20:57:34 +00:00
set ( COLOBOT_VERSION_MINOR 2 )
set ( COLOBOT_VERSION_REVISION 0 )
2012-12-27 16:10:45 +00:00
2013-06-24 19:31:01 +00:00
# Used on official releases
2019-02-23 19:01:33 +00:00
#set(COLOBOT_VERSION_RELEASE_CODENAME "-alpha")
2013-06-24 19:31:01 +00:00
# Used on unreleased, development builds
2019-02-23 19:01:33 +00:00
set ( COLOBOT_VERSION_UNRELEASED "+alpha" )
2012-12-27 16:10:45 +00:00
# Append git characteristics to version
2013-12-27 10:15:36 +00:00
if ( DEFINED COLOBOT_VERSION_UNRELEASED )
if ( EXISTS "${CMAKE_SOURCE_DIR}/.git" )
find_package ( Git )
execute_process ( COMMAND ${ GIT_EXECUTABLE } rev-parse --abbrev-ref HEAD
2014-06-25 20:49:16 +00:00
W O R K I N G _ D I R E C T O R Y " $ { C M A K E _ S O U R C E _ D I R } "
2013-12-27 10:15:36 +00:00
O U T P U T _ V A R I A B L E G I T _ B R A N C H
O U T P U T _ S T R I P _ T R A I L I N G _ W H I T E S P A C E )
execute_process ( COMMAND ${ GIT_EXECUTABLE } rev-parse --short HEAD
2014-06-25 20:49:16 +00:00
W O R K I N G _ D I R E C T O R Y " $ { C M A K E _ S O U R C E _ D I R } "
2013-12-27 10:15:36 +00:00
O U T P U T _ V A R I A B L E G I T _ R E V I S I O N
O U T P U T _ S T R I P _ T R A I L I N G _ W H I T E S P A C E )
set ( COLOBOT_VERSION_UNRELEASED "${COLOBOT_VERSION_UNRELEASED}-git-${GIT_BRANCH}~r${GIT_REVISION}" )
set ( COLOBOT_VERSION_DISPLAY "git-${GIT_BRANCH}~r${GIT_REVISION}" )
else ( )
set ( COLOBOT_VERSION_DISPLAY "${COLOBOT_VERSION_CODENAME}-${COLOBOT_VERSION_UNRELEASED}" )
endif ( )
else ( )
set ( COLOBOT_VERSION_DISPLAY "${COLOBOT_VERSION_MAJOR}.${COLOBOT_VERSION_MINOR}.${COLOBOT_VERSION_REVISION}${COLOBOT_VERSION_RELEASE_CODENAME}" )
2012-12-27 16:10:45 +00:00
endif ( )
2013-06-24 19:31:01 +00:00
set ( COLOBOT_VERSION_FULL "${COLOBOT_VERSION_MAJOR}.${COLOBOT_VERSION_MINOR}.${COLOBOT_VERSION_REVISION}${COLOBOT_VERSION_UNRELEASED}${COLOBOT_VERSION_RELEASE_CODENAME}" )
2012-12-27 16:10:45 +00:00
message ( STATUS "Building Colobot \" ${ COLOBOT_VERSION_CODENAME } \" ( ${ COLOBOT_VERSION_FULL } ) " )
2015-08-15 15:07:21 +00:00
set ( BUILD_NUMBER 0 )
if ( NOT "$ENV{BUILD_NUMBER}" STREQUAL "" )
set ( BUILD_NUMBER "$ENV{BUILD_NUMBER}" )
message ( STATUS "CI build #${BUILD_NUMBER}" )
endif ( )
2012-09-29 15:19:23 +00:00
2013-10-23 12:22:20 +00:00
##
# Platform detection and some related checks
##
if ( "${CMAKE_SYSTEM_NAME}" MATCHES "Windows" )
message ( STATUS "Build for Windows system" )
set ( PLATFORM_WINDOWS 1 )
2013-11-27 17:53:28 +00:00
set ( PLATFORM_GNU 0 )
2013-10-23 12:22:20 +00:00
set ( PLATFORM_LINUX 0 )
set ( PLATFORM_MACOSX 0 )
2019-03-09 18:04:00 +00:00
set ( PLATFORM_FREEBSD 0 )
2013-10-23 12:22:20 +00:00
set ( PLATFORM_OTHER 0 )
2013-11-20 09:39:06 +00:00
# Platform-dependent implementation of system.h
set ( SYSTEM_CPP_MODULE "system_windows.cpp" )
2016-05-02 10:14:18 +00:00
set ( SYSTEM_H_MODULE "system_windows.h" )
2013-10-23 12:22:20 +00:00
elseif ( "${CMAKE_SYSTEM_NAME}" MATCHES "Linux" )
message ( STATUS "Build for Linux system" )
set ( PLATFORM_WINDOWS 0 )
set ( PLATFORM_LINUX 1 )
2013-11-27 17:53:28 +00:00
set ( PLATFORM_GNU 1 )
2013-10-23 12:22:20 +00:00
set ( PLATFORM_MACOSX 0 )
2019-03-09 18:04:00 +00:00
set ( PLATFORM_FREEBSD 0 )
2013-10-23 12:22:20 +00:00
set ( PLATFORM_OTHER 0 )
2013-11-20 09:39:06 +00:00
# Platform-dependent implementation of system.h
set ( SYSTEM_CPP_MODULE "system_linux.cpp" )
2016-05-02 10:14:18 +00:00
set ( SYSTEM_H_MODULE "system_linux.h" )
2013-11-27 17:53:28 +00:00
elseif ( "${CMAKE_SYSTEM_NAME}" MATCHES "kFreeBSD" OR "${CMAKE_SYSTEM_NAME}" STREQUAL "GNU" )
message ( STATUS "Build for kFreeBSD system" )
set ( PLATFORM_WINDOWS 0 )
set ( PLATFORM_LINUX 0 )
set ( PLATFORM_GNU 1 )
set ( PLATFORM_MACOSX 0 )
2019-03-09 18:04:00 +00:00
set ( PLATFORM_FREEBSD 0 )
2013-11-27 17:53:28 +00:00
set ( PLATFORM_OTHER 0 )
# Platform-dependent implementation of system.h
set ( SYSTEM_CPP_MODULE "system_other.cpp" )
2016-05-02 10:14:18 +00:00
set ( SYSTEM_H_MODULE "system_other.h" )
2013-10-23 12:22:20 +00:00
elseif ( "${CMAKE_SYSTEM_NAME}" MATCHES "Darwin" )
message ( STATUS "Build for Mac OSX system" )
set ( PLATFORM_WINDOWS 0 )
set ( PLATFORM_LINUX 0 )
2013-11-27 17:53:28 +00:00
set ( PLATFORM_GNU 0 )
2013-10-23 12:22:20 +00:00
set ( PLATFORM_MACOSX 1 )
set ( PLATFORM_OTHER 0 )
2019-03-09 18:04:00 +00:00
set ( PLATFORM_FREEBSD 0 )
2015-04-27 16:03:06 +00:00
2013-11-20 09:39:06 +00:00
# Platform-dependent implementation of system.h
set ( SYSTEM_CPP_MODULE "system_macosx.cpp" )
2016-05-02 10:14:18 +00:00
set ( SYSTEM_H_MODULE "system_macosx.h" )
2016-04-02 23:34:08 +00:00
# To avoid CMake warning
set ( CMAKE_MACOSX_RPATH 1 )
2019-03-09 18:04:00 +00:00
elseif ( "${CMAKE_SYSTEM_NAME}" MATCHES "FreeBSD" )
message ( STATUS "Build for FreeBSD system" )
set ( PLATFORM_WINDOWS 0 )
set ( PLATFORM_LINUX 0 )
set ( PLATFORM_GNU 0 )
set ( PLATFORM_MACOSX 0 )
set ( PLATFORM_FREEBSD 1 )
set ( PLATFORM_OTHER 0 )
# Platform-dependent implementation of system.h
# On FreeBSD we can use *_other
set ( SYSTEM_CPP_MODULE "system_other.cpp" )
set ( SYSTEM_H_MODULE "system_other.h" )
# To avoid CMake warning
set ( CMAKE_MACOSX_RPATH 1 )
2013-10-23 12:22:20 +00:00
else ( )
message ( STATUS "Build for other system" )
set ( PLATFORM_WINDOWS 0 )
set ( PLATFORM_LINUX 0 )
2013-11-27 17:53:28 +00:00
set ( PLATFORM_GNU 0 )
2013-10-23 12:22:20 +00:00
set ( PLATFORM_MACOSX 0 )
2019-03-09 18:04:00 +00:00
set ( PLATFORM_FREEBSD 0 )
2013-10-23 12:22:20 +00:00
set ( PLATFORM_OTHER 1 )
2013-11-20 09:39:06 +00:00
# Platform-dependent implementation of system.h
set ( SYSTEM_CPP_MODULE "system_other.cpp" )
2016-05-02 10:14:18 +00:00
set ( SYSTEM_H_MODULE "system_other.h" )
2013-10-23 12:22:20 +00:00
endif ( )
2012-09-29 15:19:23 +00:00
##
# Build options
##
2013-06-21 23:11:37 +00:00
# Build targets should be placed in the root build directory
set ( CMAKE_RUNTIME_OUTPUT_DIRECTORY ${ CMAKE_CURRENT_BINARY_DIR } )
# Include cmake directory with some additional scripts
2013-06-24 11:07:33 +00:00
set ( CMAKE_MODULE_PATH "${colobot_SOURCE_DIR}/cmake" ${ CMAKE_MODULE_PATH } )
2013-06-21 23:11:37 +00:00
2013-01-08 21:12:09 +00:00
# Compiler detection
2015-04-27 16:03:06 +00:00
if ( CMAKE_CXX_COMPILER_ID MATCHES "GNU" )
2015-06-25 22:24:32 +00:00
if ( CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.7 )
message ( FATAL_ERROR "${PROJECT_NAME} requires GCC 4.7 or greater." )
2013-01-08 21:12:09 +00:00
endif ( )
2015-06-25 22:24:32 +00:00
message ( STATUS "Detected GCC version 4.7+" )
2021-12-05 10:51:28 +00:00
set ( NORMAL_CXX_FLAGS "-Wall -Wold-style-cast -pedantic-errors -Wmissing-declarations" )
2017-05-23 17:02:17 +00:00
set ( NORMAL_CXX_FLAGS "${NORMAL_CXX_FLAGS} -Wno-error=deprecated-declarations" ) # updated version of physfs is not available on some platforms so we keep using deprecated functions, see #958
2018-04-19 10:51:41 +00:00
if ( NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 5.0 )
set ( NORMAL_CXX_FLAGS "${NORMAL_CXX_FLAGS} -Wsuggest-override" )
endif ( )
2015-04-27 13:59:23 +00:00
set ( RELEASE_CXX_FLAGS "-O2" )
set ( DEBUG_CXX_FLAGS "-g -O0" )
set ( TEST_CXX_FLAGS "-pthread" )
2015-08-15 16:25:57 +00:00
add_definitions ( -DNOEXCEPT=noexcept -DHAVE_DEMANGLE )
2015-04-27 16:03:06 +00:00
elseif ( CMAKE_CXX_COMPILER_ID MATCHES "Clang" )
2015-06-25 22:24:32 +00:00
if ( CMAKE_CXX_COMPILER_VERSION VERSION_LESS 3.1 )
message ( FATAL_ERROR "${PROJECT_NAME} requires Clang 3.1 or greater." )
endif ( )
message ( STATUS "Detected Clang version 3.1+" )
2019-03-09 18:04:00 +00:00
if ( ${ PLATFORM_FREEBSD } )
set ( CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fuse-ld=bfd" )
endif ( )
2021-12-05 10:51:28 +00:00
set ( NORMAL_CXX_FLAGS "-Wall -Wold-style-cast -pedantic-errors -Wmissing-prototypes" )
2017-05-23 17:02:17 +00:00
set ( NORMAL_CXX_FLAGS "${NORMAL_CXX_FLAGS} -Wno-error=deprecated-declarations" ) # updated version of physfs is not available on some platforms so we keep using deprecated functions, see #958
2015-04-27 13:59:23 +00:00
set ( RELEASE_CXX_FLAGS "-O2" )
set ( DEBUG_CXX_FLAGS "-g -O0" )
set ( TEST_CXX_FLAGS "-pthread" )
2015-08-15 16:25:57 +00:00
add_definitions ( -DNOEXCEPT=noexcept -DHAVE_DEMANGLE )
2015-04-27 16:03:06 +00:00
elseif ( CMAKE_CXX_COMPILER_ID MATCHES "MSVC" )
message ( STATUS "Detected MSVC compiler" )
2015-06-25 22:24:32 +00:00
2020-07-14 12:26:37 +00:00
# Disable some useless warnings
set ( NORMAL_CXX_FLAGS "/wd\" 4244\ " /wd\" 4309\ " /wd\" 4800\ " /wd\" 4996\ " /wd\" 4351\ "" )
2020-07-14 18:11:09 +00:00
if ( USE_STATIC_RUNTIME )
2020-07-10 16:49:54 +00:00
set ( CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>" )
else ( )
2021-09-04 18:29:52 +00:00
set ( CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>DLL" )
2018-06-04 07:17:51 +00:00
endif ( )
2015-04-27 13:59:23 +00:00
set ( TEST_CXX_FLAGS "" )
2015-08-25 12:01:10 +00:00
add_definitions ( -DNOEXCEPT= -DHAS_MSVC_EXCEPTION_BUG )
2016-08-24 16:18:33 +00:00
2020-07-14 12:26:37 +00:00
# Increase the stack size to 8 MB (the default is 1 MB), needed for CBOT
set ( CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /STACK:8388608" )
2016-08-24 16:18:33 +00:00
# Needed for Debug information (it's set to "No" by default for some reason)
2020-04-03 18:18:14 +00:00
set ( CMAKE_EXE_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS} /DEBUG /NODEFAULTLIB:MSVCRTD /NODEFAULTLIB:LIBCMT" )
2018-06-04 07:17:51 +00:00
set ( CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO "${CMAKE_EXE_LINKER_FLAGS} /DEBUG" )
2013-01-08 21:12:09 +00:00
else ( )
2015-04-27 16:03:06 +00:00
message ( FATAL_ERROR "Your C++ compiler doesn't seem to be supported." )
2013-01-08 21:12:09 +00:00
endif ( )
2012-09-29 15:19:23 +00:00
2013-03-27 19:53:28 +00:00
2013-01-10 08:48:15 +00:00
# Global compile flags
# These are specific to GCC/MinGW/clang; for other compilers, change as necessary
2013-02-03 19:03:36 +00:00
# The flags are used throughout src/ and test/ subdirs
2013-03-27 19:53:28 +00:00
# Special flags for boost
2015-04-27 13:59:23 +00:00
add_definitions ( -DBOOST_NO_SCOPED_ENUMS -DBOOST_NO_CXX11_SCOPED_ENUMS )
2013-03-27 19:53:28 +00:00
2015-06-25 22:24:32 +00:00
set ( COLOBOT_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${NORMAL_CXX_FLAGS}" )
2015-04-27 13:59:23 +00:00
set ( COLOBOT_CXX_FLAGS_RELEASE "${RELEASE_CXX_FLAGS}" )
set ( COLOBOT_CXX_FLAGS_DEBUG "${DEBUG_CXX_FLAGS}" )
2013-01-10 08:48:15 +00:00
2013-12-20 19:19:21 +00:00
# Flags for gtest
2015-04-27 13:59:23 +00:00
set ( COLOBOT_GTEST_CXX_FLAGS "${TEST_CXX_FLAGS}" )
2013-12-20 19:19:21 +00:00
2013-03-22 17:19:53 +00:00
2012-09-29 15:19:23 +00:00
# Asserts can be enabled/disabled regardless of build type
option ( ASSERTS "Enable assert()s" ON )
2013-06-21 23:11:37 +00:00
# Development build can be enabled/disabled regardless of build type
option ( DEV_BUILD "Enable development build (enables some debugging tools, local setting paths, etc.)" OFF )
2015-12-19 21:10:15 +00:00
# Official build - changes text on the crash screen
# PLEASE DO NOT USE ON UNOFFICIAL BUILDS. Thanks.
2018-07-25 19:34:39 +00:00
option ( OFFICIAL_COLOBOT_BUILD "Official build (changes crash screen text)" OFF )
2015-12-19 21:10:15 +00:00
2020-07-11 17:12:45 +00:00
# Hide console on Windows (useful for release builds)
option ( HIDE_CONSOLE "Hide console" OFF )
2020-04-05 11:24:45 +00:00
# Hardcode relative paths instead of absolute paths
option ( USE_RELATIVE_PATHS "Generate relative paths from absolute paths" OFF )
# Portable build - load all data from the base directory
2014-10-18 18:00:30 +00:00
option ( PORTABLE "Portable build" OFF )
2018-05-16 11:28:06 +00:00
# Portable saves - suitable for e.g. putting the whole game on external storage and moving your saves with it
option ( PORTABLE_SAVES "Portable saves" OFF )
2012-09-29 15:19:23 +00:00
# Building tests can be enabled/disabled
2013-06-21 23:11:37 +00:00
option ( TESTS "Build tests" OFF )
# Building tool programs can be enabled/disabled
option ( TOOLS "Build tool programs" OFF )
2012-09-29 15:19:23 +00:00
2013-03-22 17:19:53 +00:00
# Generate desktop files, manpage, etc.
2013-03-24 21:24:04 +00:00
option ( DESKTOP "Generate desktop files, manpages, etc" ON )
2013-03-22 17:19:53 +00:00
2012-12-19 23:23:12 +00:00
# Doxygen docs are optional for installation
option ( INSTALL_DOCS "Install Doxygen-generated documentation" OFF )
2013-06-22 20:32:20 +00:00
# Build OpenAL sound support
option ( OPENAL_SOUND "Build OpenAL sound support" ON )
2012-09-29 15:19:23 +00:00
2020-07-14 18:11:09 +00:00
# Link runtime library statically (currently only works for MSVC)
option ( USE_STATIC_RUNTIME "Link the runtime library statically" OFF )
2020-07-10 16:49:54 +00:00
# CBot can also be a static library
2020-07-14 18:11:09 +00:00
option ( CBOT_STATIC "Build CBot as static libary" OFF )
2020-07-10 16:49:54 +00:00
2015-04-27 13:59:23 +00:00
# This is useful in case you want to use static boost libraries
2020-07-14 18:11:09 +00:00
option ( BOOST_STATIC "Link with static boost libraries" OFF )
2013-06-22 20:32:20 +00:00
# This is useful on Windows, if linking against standard GLEW dll fails
2020-07-14 18:11:09 +00:00
option ( GLEW_STATIC "Link statically with GLEW" OFF )
2020-07-10 16:49:54 +00:00
# Link statically with LibSndFile
2020-07-14 18:11:09 +00:00
option ( SNDFILE_STATIC "Link statically with LibSndFile" OFF )
2013-01-05 22:03:06 +00:00
2015-05-12 22:52:18 +00:00
# Sometimes helpful if there is a different version of gtest installed on system vs bundled
2013-10-24 19:32:18 +00:00
option ( FORCE_BUNDLED_GTEST "Force the use of bundled gtest" OFF )
2013-06-24 11:28:18 +00:00
2015-07-19 16:11:12 +00:00
# This is for use with colobot-lint tool
option ( COLOBOT_LINT_BUILD "Generate some additional CMake targets for use with colobot-lint" OFF )
2013-06-24 11:28:18 +00:00
# Default build type if not given is debug
2015-07-24 20:56:02 +00:00
if ( NOT CMAKE_BUILD_TYPE )
2013-06-24 11:28:18 +00:00
message ( STATUS "Build type not specified - assuming debug" )
2015-07-24 20:56:02 +00:00
set ( CMAKE_BUILD_TYPE Debug CACHE STRING "Choose the type of build, options are: Debug Release RelWithDebInfo MinSizeRel." FORCE )
2013-06-24 11:28:18 +00:00
endif ( )
# Warn about development build
if ( DEV_BUILD )
2015-08-15 15:07:21 +00:00
message ( STATUS "Building with development extensions" )
2013-06-24 11:28:18 +00:00
endif ( )
2020-07-14 18:11:09 +00:00
##
# Additional settings for MSYS
##
include ( "${colobot_SOURCE_DIR}/cmake/msys.cmake" )
##
# Additional functions for colobot-lint
##
include ( "${colobot_SOURCE_DIR}/cmake/colobot-lint.cmake" )
2013-06-24 11:28:18 +00:00
2012-09-29 15:19:23 +00:00
##
2013-03-22 17:19:53 +00:00
# Searching for packages
2012-09-29 15:19:23 +00:00
##
2012-07-28 21:36:12 +00:00
find_package ( OpenGL 1.4 REQUIRED )
2015-09-24 19:09:46 +00:00
find_package ( SDL2 REQUIRED )
find_package ( SDL2_image REQUIRED )
find_package ( SDL2_ttf REQUIRED )
2012-07-28 21:36:12 +00:00
find_package ( PNG 1.2 REQUIRED )
2012-12-19 23:23:12 +00:00
find_package ( Gettext REQUIRED )
2014-06-20 21:41:38 +00:00
find_package ( PhysFS REQUIRED )
2021-09-05 14:31:57 +00:00
find_package ( glm CONFIG REQUIRED )
2012-06-25 17:59:17 +00:00
2021-12-14 22:42:14 +00:00
# Add target alias glm::glm for older versions of the library
if ( NOT TARGET glm::glm )
add_library ( glm::glm ALIAS glm )
endif ( )
2022-02-26 20:12:40 +00:00
add_subdirectory ( lib/json )
find_package ( nlohmann_json CONFIG REQUIRED )
2013-06-22 20:32:20 +00:00
set ( Boost_USE_STATIC_LIBS ${ BOOST_STATIC } )
2013-06-16 19:39:21 +00:00
set ( Boost_USE_MULTITHREADED ON )
2020-07-14 18:11:09 +00:00
set ( Boost_USE_STATIC_RUNTIME ${ USE_STATIC_RUNTIME } )
2012-09-20 21:04:37 +00:00
set ( Boost_ADDITIONALVERSION "1.51" "1.51.0" )
2012-09-26 22:30:47 +00:00
find_package ( Boost COMPONENTS system filesystem regex REQUIRED )
2012-09-20 21:04:37 +00:00
2020-07-10 16:49:54 +00:00
set ( GLEW_USE_STATIC_LIBS ${ GLEW_STATIC } )
2013-01-05 22:03:06 +00:00
find_package ( GLEW REQUIRED )
2013-06-24 11:28:18 +00:00
if ( OPENAL_SOUND )
2013-03-22 17:19:53 +00:00
find_package ( OpenAL REQUIRED )
endif ( )
2020-07-11 17:12:45 +00:00
find_package ( SndFile REQUIRED )
2013-03-22 17:19:53 +00:00
2012-04-14 23:02:51 +00:00
2013-06-24 11:28:18 +00:00
if ( NOT ASSERTS )
2012-09-29 15:19:23 +00:00
add_definitions ( -DNDEBUG )
endif ( )
2013-06-24 11:28:18 +00:00
if ( TESTS )
2013-02-16 21:37:43 +00:00
add_definitions ( -DTESTS -DTEST_VIRTUAL=virtual )
2012-10-11 21:09:29 +00:00
else ( )
2012-12-29 13:35:14 +00:00
add_definitions ( -DTEST_VIRTUAL= )
2012-09-29 15:19:23 +00:00
endif ( )
2012-04-14 23:02:51 +00:00
2013-06-26 18:40:11 +00:00
if ( DEV_BUILD )
2013-06-27 17:43:06 +00:00
add_definitions ( -DDEV_BUILD )
2013-06-26 18:40:11 +00:00
endif ( )
2012-09-08 01:05:12 +00:00
2015-07-19 16:11:12 +00:00
2015-04-27 16:12:31 +00:00
##
# MSVC specific settings
##
set ( WINGETOPT 0 )
2020-07-10 16:49:54 +00:00
if ( MSVC )
2015-04-27 16:12:31 +00:00
message ( STATUS "Adding MSVC-specific options" )
set ( WINGETOPT 1 ) # use wingetopt library
endif ( )
2013-06-24 11:07:33 +00:00
##
# Localename
##
add_subdirectory ( lib/localename )
2015-04-27 16:12:31 +00:00
##
# Wingetopt
##
if ( WINGETOPT )
add_subdirectory ( lib/wingetopt )
endif ( )
2012-12-19 23:23:12 +00:00
##
# Doxygen docs
##
find_package ( Doxygen )
if ( DOXYGEN_FOUND AND DOXYGEN_DOT_FOUND )
configure_file ( ${ CMAKE_CURRENT_SOURCE_DIR } /Doxyfile.in ${ CMAKE_CURRENT_BINARY_DIR } /Doxyfile @ONLY )
add_custom_target ( doc
$ { D O X Y G E N _ E X E C U T A B L E } $ { C M A K E _ C U R R E N T _ B I N A R Y _ D I R } / D o x y f i l e
W O R K I N G _ D I R E C T O R Y $ { C M A K E _ C U R R E N T _ B I N A R Y _ D I R }
C O M M E N T " G e n e r a t i n g A P I d o c u m e n t a t i o n w i t h D o x y g e n " V E R B A T I M )
endif ( )
2012-09-29 15:19:23 +00:00
##
# Targets
##
2012-09-08 01:05:12 +00:00
2012-12-19 23:23:12 +00:00
# Installation paths defined before compiling sources
2021-09-04 19:08:04 +00:00
if ( PORTABLE )
2020-04-05 12:11:08 +00:00
set ( COLOBOT_INSTALL_BIN_DIR ${ CMAKE_INSTALL_PREFIX } / CACHE PATH "Colobot binary directory" )
set ( COLOBOT_INSTALL_LIB_DIR ${ CMAKE_INSTALL_PREFIX } / CACHE PATH "Colobot libraries directory" )
set ( COLOBOT_INSTALL_DATA_DIR ${ CMAKE_INSTALL_PREFIX } /data CACHE PATH "Colobot shared data directory" )
set ( COLOBOT_INSTALL_I18N_DIR ${ CMAKE_INSTALL_PREFIX } /lang CACHE PATH "Colobot translations directory" )
set ( COLOBOT_INSTALL_DOC_DIR ${ CMAKE_INSTALL_PREFIX } /doc CACHE PATH "Colobot documentation directory" )
2020-04-05 11:24:45 +00:00
set ( USE_RELATIVE_PATHS ON )
2018-05-16 11:28:06 +00:00
elseif ( PLATFORM_WINDOWS )
set ( COLOBOT_INSTALL_BIN_DIR ${ CMAKE_INSTALL_PREFIX } / CACHE PATH "Colobot binary directory" )
set ( COLOBOT_INSTALL_LIB_DIR ${ CMAKE_INSTALL_PREFIX } / CACHE PATH "Colobot libraries directory" )
set ( COLOBOT_INSTALL_DATA_DIR ${ CMAKE_INSTALL_PREFIX } /data CACHE PATH "Colobot shared data directory" )
set ( COLOBOT_INSTALL_I18N_DIR ${ CMAKE_INSTALL_PREFIX } /lang CACHE PATH "Colobot translations directory" )
set ( COLOBOT_INSTALL_DOC_DIR ${ CMAKE_INSTALL_PREFIX } /doc CACHE PATH "Colobot documentation directory" )
2013-10-31 10:56:32 +00:00
elseif ( PLATFORM_MACOSX )
2013-11-08 09:06:06 +00:00
set ( COLOBOT_INSTALL_BIN_DIR ../MacOS CACHE STRING "Colobot binary directory" )
set ( COLOBOT_INSTALL_LIB_DIR ../MacOS CACHE STRING "Colobot libraries directory" )
set ( COLOBOT_INSTALL_DATA_DIR . CACHE STRING "Colobot shared data directory" )
set ( COLOBOT_INSTALL_I18N_DIR i18n CACHE SRING "Colobot translations directory" )
set ( COLOBOT_INSTALL_DOC_DIR doc CACHE STRING "Colobot documentation directory" )
2013-03-22 21:24:35 +00:00
else ( )
set ( COLOBOT_INSTALL_BIN_DIR ${ CMAKE_INSTALL_PREFIX } /games CACHE PATH "Colobot binary directory" )
set ( COLOBOT_INSTALL_LIB_DIR ${ CMAKE_INSTALL_PREFIX } /lib/colobot CACHE PATH "Colobot libraries directory" )
set ( COLOBOT_INSTALL_DATA_DIR ${ CMAKE_INSTALL_PREFIX } /share/games/colobot CACHE PATH "Colobot shared data directory" )
set ( COLOBOT_INSTALL_I18N_DIR ${ CMAKE_INSTALL_PREFIX } /share/locale CACHE PATH "Colobot translations directory" )
set ( COLOBOT_INSTALL_DOC_DIR ${ CMAKE_INSTALL_PREFIX } /share/doc/colobot CACHE PATH "Colobot documentation directory" )
endif ( )
2012-12-17 09:11:56 +00:00
2020-04-05 11:24:45 +00:00
# Generate relative paths from absolute paths
if ( USE_RELATIVE_PATHS )
message ( STATUS "Generating relative paths" )
file ( RELATIVE_PATH COLOBOT_DATA_DIR ${ COLOBOT_INSTALL_BIN_DIR } ${ COLOBOT_INSTALL_DATA_DIR } )
file ( RELATIVE_PATH COLOBOT_I18N_DIR ${ COLOBOT_INSTALL_BIN_DIR } ${ COLOBOT_INSTALL_I18N_DIR } )
add_definitions ( -DUSE_RELATIVE_PATHS )
else ( )
set ( COLOBOT_DATA_DIR ${ COLOBOT_INSTALL_DATA_DIR } )
set ( COLOBOT_I18N_DIR ${ COLOBOT_INSTALL_I18N_DIR } )
endif ( )
2012-06-25 17:59:17 +00:00
# Subdirectory with sources
2013-06-21 23:11:37 +00:00
add_subdirectory ( src )
add_subdirectory ( po )
2013-06-24 11:28:18 +00:00
if ( DESKTOP )
2013-10-29 13:30:58 +00:00
add_subdirectory ( desktop )
2013-06-21 23:11:37 +00:00
endif ( )
2012-10-05 20:07:58 +00:00
2014-08-12 18:03:56 +00:00
if ( TESTS )
# Google Test library
2021-12-08 18:25:36 +00:00
find_package ( GTest 1.11.0 QUIET )
2020-07-11 10:16:20 +00:00
if ( NOT(FORCE_BUNDLED_GTEST ) A N D G T E S T _ F O U N D )
message ( STATUS "Using system gtest library in ${GTEST_BOTH_LIBRARIES}" )
elseif ( EXISTS "${colobot_SOURCE_DIR}/lib/googletest/googletest/CMakeLists.txt" )
message ( STATUS "Using gtest git submodule" )
2021-12-08 18:25:36 +00:00
set ( GOOGLETEST_VERSION "1.11.0" )
2020-07-11 10:16:20 +00:00
add_subdirectory ( "${colobot_SOURCE_DIR}/lib/googletest/googletest" "lib/googletest/googletest" )
# Add aliases so target names are compatible with the find_package above
add_library ( GTest::GTest ALIAS gtest )
add_library ( GTest::Main ALIAS gtest_main )
2020-07-11 10:26:35 +00:00
else ( )
message ( FATAL_ERROR "Could not find gtest, cannot enable testing" )
2014-08-12 18:03:56 +00:00
endif ( )
2015-05-12 22:52:18 +00:00
# Hippomocks library
2020-07-10 16:49:54 +00:00
add_subdirectory ( ${ colobot_SOURCE_DIR } /lib/hippomocks )
2014-08-12 18:03:56 +00:00
# Tests targets
enable_testing ( )
2020-07-11 10:16:20 +00:00
include ( GoogleTest )
2014-08-12 18:03:56 +00:00
add_subdirectory ( test )
endif ( )
2012-12-17 17:38:36 +00:00
2012-12-19 23:23:12 +00:00
##
# Installation
##
2012-12-17 17:38:36 +00:00
2013-01-02 13:23:17 +00:00
# Data: check if the submodule handles its own installation
if ( EXISTS "${CMAKE_SOURCE_DIR}/data/CMakeLists.txt" )
2013-02-03 19:03:36 +00:00
message ( STATUS "Data directory will install itself." )
add_subdirectory ( data )
2013-01-02 13:23:17 +00:00
else ( )
2013-02-03 19:03:36 +00:00
message ( WARNING "Data directory is not available; make sure colobot-data is installed in ${COLOBOT_INSTALL_DATA_DIR}." )
2013-01-02 13:23:17 +00:00
endif ( )
2012-12-19 23:23:12 +00:00
# Documentation
if ( INSTALL_DOCS AND DOXYGEN_FOUND AND DOXYGEN_DOT_FOUND )
install ( DIRECTORY ${ CMAKE_CURRENT_BINARY_DIR } /doc/ DESTINATION ${ COLOBOT_INSTALL_DOC_DIR } OPTIONAL )
endif ( )