2016-07-21 05:46:31 -04:00
# This is the top-level CMakeLists.txt file for the Cuberite project
#
# Use CMake to generate the build files for your platform
#
# This script supports some configuration through CMake arguments (-Dparam=val syntax):
2016-07-30 09:22:18 -04:00
# BUILD_TOOLS=1 sets up additional executables to be built along with the server (ProtoProxy, GrownBiomeGenVisualiser, MCADefrag)
# BUILD_UNSTABLE_TOOLS=1 sets up yet more executables to be built, these can be broken and generally are obsolete (GeneratorPerformanceTest)
# NO_NATIVE_OPTIMIZATION=1 disables CPU-specific optimisations for the current machine, allows use on other CPUs of the same platform
# DISABLE_SYSTEM_LUA=1 disables the use of system Lua interpreter; the tolua executable will be built and used instead. Incompatible with cross-compiling
# SELF_TEST=1 enables testing code to be built
2016-07-21 05:46:31 -04:00
2014-09-06 11:30:04 -04:00
cmake_minimum_required ( VERSION 2.8.7 )
2013-12-10 13:41:43 -05:00
2016-07-17 10:42:38 -04:00
if ( POLICY CMP0054 )
cmake_policy ( SET CMP0054 NEW )
endif ( )
2013-12-28 16:46:23 -05:00
# Without this, the MSVC variable isn't defined for MSVC builds ( http://www.cmake.org/pipermail/cmake/2011-November/047130.html )
enable_language ( CXX C )
2015-06-03 04:40:01 -04:00
# Enable the support for solution folders in MSVC
if ( MSVC )
set_property ( GLOBAL PROPERTY USE_FOLDERS ON )
endif ( )
2014-03-10 16:52:13 -04:00
# These env variables are used for configuring Travis CI builds.
2015-08-26 04:58:51 -04:00
if ( DEFINED ENV{TRAVIS_CUBERITE_BUILD_TYPE} )
message ( "Setting build type to $ENV{TRAVIS_CUBERITE_BUILD_TYPE}" )
set ( CMAKE_BUILD_TYPE $ENV{ TRAVIS_CUBERITE_BUILD_TYPE } )
2014-03-07 15:16:16 -05:00
endif ( )
2016-01-01 15:05:09 -05:00
if ( DEFINED ENV{TRAVIS_CUBERITE_FORCE32} )
set ( FORCE32 $ENV{ TRAVIS_CUBERITE_FORCE32 } )
2014-03-07 15:16:16 -05:00
endif ( )
2014-05-10 08:03:36 -04:00
if ( DEFINED ENV{TRAVIS_BUILD_WITH_COVERAGE} )
set ( BUILD_WITH_COVERAGE $ENV{ TRAVIS_BUILD_WITH_COVERAGE } )
endif ( )
2015-08-26 04:58:51 -04:00
if ( DEFINED ENV{CUBERITE_BUILD_ID} )
2015-06-05 04:19:58 -04:00
# The build info is defined by the build system (Travis / Jenkins)
2015-08-26 04:58:51 -04:00
set ( BUILD_ID $ENV{ CUBERITE_BUILD_ID } )
set ( BUILD_SERIES_NAME $ENV{ CUBERITE_BUILD_SERIES_NAME } )
set ( BUILD_DATETIME $ENV{ CUBERITE_BUILD_DATETIME } )
if ( DEFINED ENV{CUBERITE_BUILD_COMMIT_ID} )
set ( BUILD_COMMIT_ID $ENV{ CUBERITE_BUILD_COMMIT_ID } )
2014-09-10 11:07:00 -04:00
else ( )
message ( "Commit id not set, attempting to determine id from git" )
execute_process (
C O M M A N D g i t r e v - p a r s e H E A D
2015-10-09 05:15:40 -04:00
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 _ L I S T _ D I R }
2014-09-10 11:07:00 -04:00
R E S U L T _ V A R I A B L E G I T _ E X E C U T E D
2015-06-05 04:19:58 -04:00
O U T P U T _ V A R I A B L E B U I L D _ C O M M I T _ I D
)
string ( STRIP ${ BUILD_COMMIT_ID } BUILD_COMMIT_ID )
2014-09-10 11:07:00 -04:00
if ( NOT ( GIT_EXECUTED EQUAL 0 ) )
message ( FATAL_ERROR "Could not identifiy git commit id" )
endif ( )
endif ( )
2015-06-05 04:19:58 -04:00
else ( )
# This is a local build, stuff in some basic info:
set ( BUILD_ID "Unknown" )
set ( BUILD_SERIES_NAME "local build" )
execute_process (
C O M M A N D g i t r e v - p a r s e H E A D
2015-10-09 05:15:40 -04:00
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 _ L I S T _ D I R }
2015-06-05 04:19:58 -04:00
R E S U L T _ V A R I A B L E G I T _ E X E C U T E D
O U T P U T _ V A R I A B L E B U I L D _ C O M M I T _ I D
)
2015-06-05 07:37:36 -04:00
if ( NOT(GIT_EXECUTED EQUAL 0 ) )
set ( BUILD_COMMIT_ID "Unknown" )
endif ( )
2015-06-05 04:19:58 -04:00
string ( STRIP ${ BUILD_COMMIT_ID } BUILD_COMMIT_ID )
execute_process (
C O M M A N D g i t l o g - 1 - - d a t e = i s o - - p r e t t y = f o r m a t : % a i
2015-10-09 05:15:40 -04:00
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 _ L I S T _ D I R }
2015-06-05 07:37:36 -04:00
R E S U L T _ V A R I A B L E G I T _ E X E C U T E D
2015-06-05 04:19:58 -04:00
O U T P U T _ V A R I A B L E B U I L D _ D A T E T I M E
)
2015-06-05 07:37:36 -04:00
if ( NOT(GIT_EXECUTED EQUAL 0 ) )
set ( BUILD_DATETIME "Unknown" )
endif ( )
2015-06-05 04:19:58 -04:00
string ( STRIP ${ BUILD_DATETIME } BUILD_DATETIME )
# The BUILD_COMMIT_ID and BUILD_DATETIME aren't updated on each repo pull
# They are only updated when cmake re-configures the project
# Therefore mark them as "approx: "
set ( BUILD_COMMIT_ID "approx: ${BUILD_COMMIT_ID}" )
set ( BUILD_DATETIME "approx: ${BUILD_DATETIME}" )
2014-09-10 11:07:00 -04:00
endif ( )
2014-11-02 02:09:22 -05:00
# We need C++11 features, Visual Studio has those from VS2012, but it needs a new platform toolset for those; VS2013 supports them natively:
# Adapted from http://binglongx.wordpress.com/2013/06/28/set-non-default-platform-toolset-in-cmake/
if ( MSVC OR MSVC_IDE )
2015-08-26 04:58:51 -04:00
if ( MSVC_VERSION LESS 1700 ) # VC10- / VS2010-
message ( FATAL_ERROR "The project requires C++11 features. "
2016-11-07 17:15:07 -05:00
" Y o u n e e d a t l e a s t V i s u a l S t u d i o 11 ( Microsoft Visual Studio 2012 ) , "
" w i t h M i c r o s o f t V i s u a l C + + C o m p i l e r N o v 2 0 1 2 CTP ( v120_CTP_Nov2012 ) . " )
2015-08-26 04:58:51 -04:00
elseif ( MSVC_VERSION EQUAL 1700 ) # VC11 / VS2012
message ( "VC11: using Microsoft Visual Studio 2012 "
2016-11-07 17:15:07 -05:00
" w i t h M i c r o s o f t V i s u a l C + + C o m p i l e r N o v 2 0 1 2 CTP ( v120_CTP_Nov2012 ) " )
2015-08-26 04:58:51 -04:00
set ( CMAKE_GENERATOR_TOOLSET "v120_CTP_Nov2012" CACHE STRING "Platform Toolset" FORCE )
else ( ) # VC12+, assuming C++11 supported.
endif ( )
2017-03-10 02:45:11 -05:00
else ( ) # GCC or Clang, so get compiler version directly since CMAKE_CXX_COMPILER_VERSION is only available in CMake 2.8.8 and later
execute_process ( COMMAND ${ CMAKE_CXX_COMPILER } -dumpversion OUTPUT_VARIABLE DUMPED_COMPILER_VERSION OUTPUT_STRIP_TRAILING_WHITESPACE )
# Check for gcc version 4.8 or greater
if ( "${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU" AND DUMPED_COMPILER_VERSION VERSION_LESS "4.8" )
message ( FATAL_ERROR "You have ${CMAKE_CXX_COMPILER_ID} version ${DUMPED_COMPILER_VERSION}, but at least 4.8 is needed" )
endif ( )
# Check for clang version 3.4 or greater
if ( "${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang" AND DUMPED_COMPILER_VERSION VERSION_LESS "3.4" )
message ( FATAL_ERROR "You have ${CMAKE_CXX_COMPILER_ID} version ${DUMPED_COMPILER_VERSION}, but at least 3.4 is needed" )
endif ( )
2014-11-02 02:09:22 -05:00
endif ( )
2015-05-23 09:36:45 -04:00
set ( BUILD_TOOLS OFF CACHE BOOL "" )
set ( SELF_TEST OFF CACHE BOOL "" )
2016-11-07 17:15:07 -05:00
# Check whether Lua can be used:
2016-07-21 05:46:31 -04:00
if ( NOT(DISABLE_SYSTEM_LUA ) )
include ( CheckLua.cmake )
2016-11-07 17:15:07 -05:00
if ( HAS_LUA_INTERPRETER )
message ( STATUS "Lua has been found in your system and will be used for the build." )
2016-07-21 05:46:31 -04:00
set ( USE_SYSTEM_LUA 1 )
else ( )
2016-11-07 17:15:07 -05:00
message ( STATUS "Lua has NOT been found in your system, the build will use its own Lua implementation." )
2016-07-21 05:46:31 -04:00
unset ( USE_SYSTEM_LUA )
endif ( )
2016-07-17 10:23:29 -04:00
else ( )
2016-07-21 05:46:31 -04:00
message ( STATUS "System Lua is disabled via CMake command-line parameters. The build will use its own Lua implementation." )
2016-07-17 10:23:29 -04:00
endif ( )
2014-02-16 08:55:37 -05:00
# This has to be done before any flags have been set up.
2014-02-16 06:37:31 -05:00
if ( ${ BUILD_TOOLS } )
2015-05-03 04:01:19 -04:00
message ( "Building tools" )
2016-03-12 04:49:41 -05:00
add_subdirectory ( Tools/GrownBiomeGenVisualiser/ )
2014-02-16 06:37:31 -05:00
add_subdirectory ( Tools/MCADefrag/ )
2016-11-15 01:38:00 -05:00
add_subdirectory ( Tools/NoiseSpeedTest/ )
2014-02-16 07:30:45 -05:00
add_subdirectory ( Tools/ProtoProxy/ )
2014-02-16 06:37:31 -05:00
endif ( )
if ( ${ BUILD_UNSTABLE_TOOLS } )
2015-05-03 04:01:19 -04:00
message ( "Building unstable tools" )
2014-02-16 06:37:31 -05:00
add_subdirectory ( Tools/GeneratorPerformanceTest/ )
endif ( )
2014-02-15 18:17:58 -05:00
include ( SetFlags.cmake )
set_flags ( )
set_lib_flags ( )
enable_profile ( )
2014-01-14 05:05:57 -05:00
2013-12-27 06:01:45 -05:00
# Under Windows, we need Lua as DLL; on *nix we need it linked statically:
if ( WIN32 )
add_definitions ( -DLUA_BUILD_AS_DLL )
endif ( )
# The Expat library is linked in statically, make the source files aware of that:
2013-12-27 05:51:08 -05:00
add_definitions ( -DXML_STATIC )
2013-12-21 08:45:27 -05:00
2015-05-07 16:35:02 -04:00
# Let Lua use additional checks on its C API. This is only compiled into Debug builds:
add_definitions ( -DLUA_USE_APICHECK )
2014-02-05 13:10:45 -05:00
# Self Test Mode enables extra checks at startup
if ( ${ SELF_TEST } )
add_definitions ( -DSELF_TEST )
endif ( )
2013-12-28 16:46:23 -05:00
2016-02-20 05:50:52 -05:00
# Build all dependent libraries as static:
SET ( CMAKE_BUILD_STATIC_LIBRARIES ON )
2016-11-07 17:15:07 -05:00
####
2014-01-14 05:05:57 -05:00
2014-02-15 18:17:58 -05:00
2015-08-26 04:58:51 -04:00
project ( Cuberite )
2013-12-28 16:46:23 -05:00
2014-07-28 13:59:53 -04:00
# Set options for SQLiteCpp, disable all their tests and lints:
set ( SQLITECPP_RUN_CPPLINT OFF CACHE BOOL "Run cpplint.py tool for Google C++ StyleGuide." FORCE )
set ( SQLITECPP_RUN_CPPCHECK OFF CACHE BOOL "Run cppcheck C++ static analysis tool." FORCE )
set ( SQLITECPP_RUN_DOXYGEN OFF CACHE BOOL "Run Doxygen C++ documentation tool." FORCE )
set ( SQLITECPP_BUILD_EXAMPLES OFF CACHE BOOL "Build examples." FORCE )
set ( SQLITECPP_BUILD_TESTS OFF CACHE BOOL "Build and run tests." FORCE )
set ( SQLITECPP_INTERNAL_SQLITE OFF CACHE BOOL "Add the internal SQLite3 source to the project." FORCE )
2015-06-06 08:22:56 -04:00
set ( SQLITE_ENABLE_COLUMN_METADATA OFF CACHE BOOL "" FORCE )
2014-07-28 13:59:53 -04:00
2015-01-05 16:14:48 -05:00
# Set options for LibEvent, disable all their tests and benchmarks:
set ( EVENT__DISABLE_OPENSSL YES CACHE BOOL "Disable OpenSSL in LibEvent" FORCE )
set ( EVENT__DISABLE_BENCHMARK YES CACHE BOOL "Disable LibEvent benchmarks" FORCE )
set ( EVENT__DISABLE_TESTS YES CACHE BOOL "Disable LibEvent tests" FORCE )
set ( EVENT__DISABLE_REGRESS YES CACHE BOOL "Disable LibEvent regression tests" FORCE )
set ( EVENT__DISABLE_SAMPLES YES CACHE BOOL "Disable LibEvent samples" FORCE )
2015-05-08 20:22:33 -04:00
# Set options for JsonCPP, disabling all of their tests
2015-07-09 18:43:23 -04:00
# Additionally, their library is output to a strange location; make sure the linker knows where to find it
2015-05-08 20:22:33 -04:00
set ( JSONCPP_WITH_TESTS OFF CACHE BOOL "Compile and (for jsoncpp_check) run JsonCpp test executables" )
set ( JSONCPP_WITH_POST_BUILD_UNITTEST OFF CACHE BOOL "Automatically run unit-tests as a post build step" )
set ( JSONCPP_WITH_PKGCONFIG_SUPPORT OFF CACHE BOOL "Generate and install .pc files" )
2015-07-09 18:43:23 -04:00
link_directories ( lib/jsoncpp/src/lib_json )
2015-05-08 20:22:33 -04:00
2015-01-09 14:38:25 -05:00
# Check that the libraries are present:
2016-11-07 17:15:07 -05:00
if ( NOT EXISTS ${ PROJECT_SOURCE_DIR } /lib/SQLiteCpp/CMakeLists.txt )
2015-01-09 14:38:25 -05:00
message ( FATAL_ERROR "SQLiteCpp is missing in folder lib/SQLiteCpp. Have you initialized the submodules / downloaded the extra libraries?" )
endif ( )
2016-11-07 17:15:07 -05:00
if ( NOT EXISTS ${ PROJECT_SOURCE_DIR } /lib/polarssl/CMakeLists.txt )
2015-01-09 14:38:25 -05:00
message ( FATAL_ERROR "PolarSSL is missing in folder lib/polarssl. Have you initialized the submodules / downloaded the extra libraries?" )
endif ( )
2016-11-07 17:15:07 -05:00
if ( NOT EXISTS ${ PROJECT_SOURCE_DIR } /lib/libevent/CMakeLists.txt )
2015-01-05 16:14:48 -05:00
message ( FATAL_ERROR "LibEvent is missing in folder lib/libevent. Have you initialized and updated the submodules / downloaded the extra libraries?" )
endif ( )
2016-11-07 17:15:07 -05:00
if ( NOT EXISTS ${ PROJECT_SOURCE_DIR } /lib/jsoncpp/CMakeLists.txt )
2015-08-10 03:55:35 -04:00
message ( FATAL_ERROR "JsonCPP is missing in folder lib/jsoncpp. Have you initialized and updated the submodules / downloaded the extra libraries?" )
endif ( )
2016-11-07 17:15:07 -05:00
if ( NOT EXISTS ${ PROJECT_SOURCE_DIR } /lib/cmake-coverage/CodeCoverage.cmake )
2015-11-04 16:32:11 -05:00
message ( FATAL_ERROR "cmake-coverage is missing in folder lib/cmake-coverage. Have you initialized and updated the submodules / downloaded the extra libraries?" )
endif ( )
2016-11-07 17:15:07 -05:00
if ( NOT EXISTS ${ PROJECT_SOURCE_DIR } /lib/expat/CMakeLists.txt )
2015-11-04 16:32:11 -05:00
message ( FATAL_ERROR "expat is missing in folder lib/expat. Have you initialized and updated the submodules / downloaded the extra libraries?" )
endif ( )
2016-11-07 17:15:07 -05:00
if ( NOT EXISTS ${ PROJECT_SOURCE_DIR } /lib/lua/CMakeLists.txt )
2015-11-04 16:32:11 -05:00
message ( FATAL_ERROR "lua is missing in folder lib/lua. Have you initialized and updated the submodules / downloaded the extra libraries?" )
endif ( )
2016-11-07 17:15:07 -05:00
if ( NOT EXISTS ${ PROJECT_SOURCE_DIR } /lib/luaexpat/CMakeLists.txt )
2015-11-04 16:32:11 -05:00
message ( FATAL_ERROR "luaexpat is missing in folder lib/luaexpat. Have you initialized and updated the submodules / downloaded the extra libraries?" )
endif ( )
2016-11-07 17:15:07 -05:00
if ( NOT EXISTS ${ PROJECT_SOURCE_DIR } /lib/luaproxy/CMakeLists.txt )
2015-11-04 16:32:11 -05:00
message ( FATAL_ERROR "luaproxy is missing in folder lib/luaproxy. Have you initialized and updated the submodules / downloaded the extra libraries?" )
endif ( )
2016-11-07 17:15:07 -05:00
if ( NOT EXISTS ${ PROJECT_SOURCE_DIR } /lib/sqlite/CMakeLists.txt )
2015-11-04 16:32:11 -05:00
message ( FATAL_ERROR "sqlite is missing in folder lib/sqlite. Have you initialized and updated the submodules / downloaded the extra libraries?" )
endif ( )
2016-11-07 17:15:07 -05:00
if ( NOT EXISTS ${ PROJECT_SOURCE_DIR } /lib/tolua++/CMakeLists.txt )
2015-11-04 16:32:11 -05:00
message ( FATAL_ERROR "tolua++ is missing in folder lib/tolua++. Have you initialized and updated the submodules / downloaded the extra libraries?" )
endif ( )
2016-11-07 17:15:07 -05:00
if ( NOT EXISTS ${ PROJECT_SOURCE_DIR } /lib/zlib/CMakeLists.txt )
2015-11-04 16:32:11 -05:00
message ( FATAL_ERROR "zlib is missing in folder lib/zlib. Have you initialized and updated the submodules / downloaded the extra libraries?" )
endif ( )
2015-01-09 14:38:25 -05:00
2013-12-28 10:03:57 -05:00
# Include all the libraries:
2013-12-10 16:39:20 -05:00
add_subdirectory ( lib/jsoncpp/ )
2013-12-10 18:26:55 -05:00
add_subdirectory ( lib/zlib/ )
2013-12-18 18:14:11 -05:00
add_subdirectory ( lib/lua/ )
2017-05-04 09:01:15 -04:00
add_subdirectory ( lib/tolua++/ EXCLUDE_FROM_ALL )
2013-12-18 19:28:48 -05:00
add_subdirectory ( lib/sqlite/ )
2014-07-28 13:59:53 -04:00
add_subdirectory ( lib/SQLiteCpp/ )
2013-12-18 19:52:52 -05:00
add_subdirectory ( lib/expat/ )
add_subdirectory ( lib/luaexpat/ )
2015-06-03 04:42:31 -04:00
add_subdirectory ( lib/libevent/ EXCLUDE_FROM_ALL )
2013-12-10 16:39:20 -05:00
2014-07-28 14:16:24 -04:00
# Add proper include directories so that SQLiteCpp can find SQLite3:
get_property ( SQLITECPP_INCLUDES DIRECTORY "lib/SQLiteCpp/" PROPERTY INCLUDE_DIRECTORIES )
set ( SQLITECPP_INCLUDES "${SQLITECPP_INCLUDES}" "${CMAKE_CURRENT_SOURCE_DIR}/lib/sqlite/" )
set_property ( DIRECTORY lib/SQLiteCpp/ PROPERTY INCLUDE_DIRECTORIES "${SQLITECPP_INCLUDES}" )
2014-07-28 16:06:47 -04:00
set_property ( TARGET SQLiteCpp PROPERTY INCLUDE_DIRECTORIES "${SQLITECPP_INCLUDES}" )
2014-07-28 14:16:24 -04:00
2015-01-13 08:44:03 -05:00
# Add proper includes for LibEvent's event-config.h header:
include_directories ( SYSTEM ${ LIBEVENT_INCLUDE_DIRS } )
2015-07-09 18:43:23 -04:00
# Prettify jsoncpp_lib_static name in VS solution explorer
set_property ( TARGET jsoncpp_lib_static PROPERTY PROJECT_LABEL "jsoncpp" )
2014-06-24 08:48:18 -04:00
if ( WIN32 )
add_subdirectory ( lib/luaproxy/ )
endif ( )
2014-01-22 16:19:33 -05:00
# We use EXCLUDE_FROM_ALL so that only the explicit dependencies are used
# (PolarSSL also has test and example programs in their CMakeLists.txt, we don't want those)
2015-01-11 04:43:02 -05:00
include ( lib/polarssl.cmake EXCLUDE_FROM_ALL )
2014-01-22 16:19:33 -05:00
2014-02-15 18:17:58 -05:00
set_exe_flags ( )
2013-12-27 05:51:08 -05:00
2016-11-07 17:15:07 -05:00
add_subdirectory ( src )
2013-12-10 13:41:43 -05:00
2014-04-27 15:25:03 -04:00
if ( ${ SELF_TEST } )
2015-01-11 04:43:02 -05:00
message ( "Tests enabled" )
2014-04-27 15:25:03 -04:00
enable_testing ( )
2016-11-07 17:15:07 -05:00
add_subdirectory ( tests )
2014-04-27 15:25:03 -04:00
endif ( )
2015-06-18 17:30:41 -04:00
# Put projects into solution folders in MSVC:
2015-06-03 04:40:01 -04:00
if ( MSVC )
2015-06-18 17:30:41 -04:00
set_target_properties (
e v e n t _ c o r e
e v e n t _ e x t r a
e x p a t
2015-07-09 18:43:23 -04:00
j s o n c p p _ l i b _ s t a t i c
2015-06-18 17:30:41 -04:00
l u a
l u a e x p a t
m b e d t l s
s q l i t e
S Q L i t e C p p
t o l u a l i b
z l i b
P R O P E R T I E S F O L D E R L i b
)
set_target_properties (
l u a p r o x y
P R O P E R T I E S F O L D E R S u p p o r t
)
if ( ${ BUILD_TOOLS } )
set_target_properties (
M C A D e f r a g
P r o t o P r o x y
P R O P E R T I E S F O L D E R T o o l s
)
2015-06-03 04:40:01 -04:00
endif ( )
endif ( )