2009-09-13 18:02:46 -06:00
# main project file. use it from a build sub-folder, see COMPILE for details
2011-03-16 00:35:08 -06:00
2012-03-13 14:16:30 -06:00
## some generic CMake magic
2023-05-23 18:03:36 -06:00
cmake_minimum_required ( VERSION 3.18 FATAL_ERROR )
2020-09-18 23:17:25 -06:00
cmake_policy ( SET CMP0048 NEW )
2023-05-23 18:03:36 -06:00
cmake_policy ( SET CMP0074 NEW )
2012-03-13 14:16:30 -06:00
project ( dfhack )
2023-05-23 18:03:36 -06:00
# set up versioning.
2023-10-01 14:35:29 -06:00
set ( DF_VERSION "50.11" )
2023-10-12 12:48:40 -06:00
set ( DFHACK_RELEASE "r2rc1" )
set ( DFHACK_PRERELEASE TRUE )
2019-07-16 17:33:33 -06:00
2023-05-23 18:03:36 -06:00
set ( DFHACK_VERSION "${DF_VERSION}-${DFHACK_RELEASE}" )
set ( DFHACK_ABI_VERSION 1 )
set ( DFHACK_BUILD_ID "" CACHE STRING "Build ID (should be specified on command line)" )
2020-04-19 10:16:48 -06:00
2019-07-16 20:19:11 -06:00
# Set up build types
if ( CMAKE_CONFIGURATION_TYPES )
set ( CMAKE_CONFIGURATION_TYPES "Release;RelWithDebInfo" CACHE STRING "List of supported configuration types" FORCE )
else ( CMAKE_CONFIGURATION_TYPES )
set ( DFHACK_TYPE_HELP "Choose the type of build, options are: Release and RelWithDebInfo" )
# Prevent cmake C module attempts to overwrite our help string
if ( NOT CMAKE_BUILD_TYPE )
set ( CMAKE_BUILD_TYPE "Release" CACHE STRING "${DFHACK_TYPE_HELP}" )
else ( NOT CMAKE_BUILD_TYPE )
set ( CMAKE_BUILD_TYPE "${CMAKE_BUILD_TYPE}" CACHE STRING "${DFHACK_TYPE_HELP}" )
endif ( NOT CMAKE_BUILD_TYPE )
set_property ( CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Release;RelWithDebInfo" )
endif ( CMAKE_CONFIGURATION_TYPES )
option ( BUILD_DOCS "Choose whether to build the documentation (requires python and Sphinx)." OFF )
2023-08-05 00:59:04 -06:00
option ( BUILD_DOCS_NO_HTML "Don't build the HTML docs, only the in-game docs." OFF )
2019-07-16 20:19:11 -06:00
option ( REMOVE_SYMBOLS_FROM_DF_STUBS "Remove debug symbols from DF stubs. (Reduces libdfhack size to about half but removes a few useful symbols)" ON )
macro ( CHECK_GCC compiler_path )
execute_process ( COMMAND ${ compiler_path } -dumpversion OUTPUT_VARIABLE GCC_VERSION_OUT )
string ( STRIP "${GCC_VERSION_OUT}" GCC_VERSION_OUT )
2023-03-23 18:29:39 -06:00
if ( ${ GCC_VERSION_OUT } VERSION_LESS "10" )
message ( SEND_ERROR "${compiler_path} version ${GCC_VERSION_OUT} cannot be used - use GCC 10 or later" )
# TODO: this may need to be removed when DF linux actually comes out
# TODO: and we can test
2019-07-16 20:19:11 -06:00
# GCC 5 changes ABI name mangling to enable C++11 changes.
# This must be disabled to enable linking against DF.
# http://developerblog.redhat.com/2015/02/05/gcc5-and-the-c11-abi/
add_definitions ( -D_GLIBCXX_USE_CXX11_ABI=0 )
endif ( )
2015-09-26 08:46:29 -06:00
endmacro ( )
if ( UNIX )
2019-07-16 20:19:11 -06:00
if ( CMAKE_COMPILER_IS_GNUCC )
check_gcc ( ${ CMAKE_C_COMPILER } )
else ( )
message ( SEND_ERROR "C compiler is not GCC" )
endif ( )
if ( CMAKE_COMPILER_IS_GNUCXX )
check_gcc ( ${ CMAKE_CXX_COMPILER } )
else ( )
message ( SEND_ERROR "C++ compiler is not GCC" )
endif ( )
2015-09-26 08:46:29 -06:00
endif ( )
if ( WIN32 )
2023-02-21 20:13:57 -07:00
if ( NOT MSVC )
2023-08-10 23:07:20 -06:00
message ( SEND_ERROR "No MSVC found! MSVC 2022 version 1930 to 1937 is required." )
elseif ( ( MSVC_VERSION LESS 1930 ) OR ( MSVC_VERSION GREATER 1937 ) )
message ( SEND_ERROR "MSVC 2022 version 1930 to 1937 is required, Version Found: ${MSVC_VERSION}" )
2019-07-16 20:19:11 -06:00
endif ( )
2015-09-26 08:46:29 -06:00
endif ( )
2023-03-23 18:29:39 -06:00
# Ask for C++-20 standard from compilers
set ( CMAKE_CXX_STANDARD 20 )
2018-06-10 13:55:38 -06:00
# Require the standard support from compilers.
set ( CMAKE_CXX_STANDARD_REQUIRED ON )
# Use only standard c++ to keep code portable
set ( CMAKE_CXX_EXTENSIONS OFF )
2012-04-14 16:27:02 -06:00
if ( MSVC )
2022-11-18 14:29:02 -07:00
# increase warning level and treat warnings as errors
2022-12-11 02:42:25 -07:00
add_compile_options ( "/WX" )
add_compile_options ( "/W3" )
2022-11-18 14:09:50 -07:00
2019-07-16 20:19:11 -06:00
# disable C4819 code-page warning
2022-12-11 02:42:25 -07:00
add_compile_options ( "/wd4819" )
2019-07-16 20:19:11 -06:00
# disable use of POSIX name warnings
add_definitions ( "/D_CRT_NONSTDC_NO_WARNINGS /D_CRT_SECURE_NO_WARNINGS" )
# supress C4503 - VC++ dislikes if a name is too long. If you get
# weird and mysterious linking errors, you can disable this, but you'll have to
# deal with a LOT of compiler noise over it
# see https://msdn.microsoft.com/en-us/library/074af4b6.aspx
2022-12-11 02:42:25 -07:00
add_compile_options ( "/wd4503" )
2019-07-16 20:19:11 -06:00
# suppress C4267 - VC++ complains whenever we implicitly convert an integer to
# a smaller type, and most of the time this is just conversion from 64 to 32 bits
# for things like vector sizes, which are never that big anyway.
2022-12-11 02:42:25 -07:00
add_compile_options ( "/wd4267" )
2020-04-28 17:18:28 -06:00
# MSVC panics if an object file contains more than 65,279 sections. this
# happens quite frequently with code that uses templates, such as vectors.
2022-12-11 02:42:25 -07:00
add_compile_options ( "/bigobj" )
2012-04-14 16:27:02 -06:00
endif ( )
2012-04-14 16:20:59 -06:00
2016-07-31 18:01:47 -06:00
# Automatically detect architecture based on Visual Studio generator
2019-07-16 20:19:11 -06:00
if ( MSVC AND NOT DEFINED DFHACK_BUILD_ARCH )
2022-12-10 19:13:19 -07:00
if ( ( ${ CMAKE_GENERATOR } MATCHES "Win32" ) OR ( ${ CMAKE_GENERATOR } MATCHES "x86" ) )
2019-07-16 20:19:11 -06:00
set ( DFHACK_BUILD_ARCH "32" )
2022-12-10 19:13:19 -07:00
else ( )
set ( DFHACK_BUILD_ARCH "64" )
2019-07-16 20:19:11 -06:00
endif ( )
else ( )
set ( DFHACK_BUILD_ARCH "64" CACHE STRING "Architecture to build ('32' or '64')" )
endif ( )
if ( "${DFHACK_BUILD_ARCH}" STREQUAL "32" )
set ( DFHACK_BUILD_32 1 )
set ( DFHACK_BUILD_64 0 )
set ( DFHACK_SETARCH "i386" )
elseif ( "${DFHACK_BUILD_ARCH}" STREQUAL "64" )
set ( DFHACK_BUILD_32 0 )
set ( DFHACK_BUILD_64 1 )
set ( DFHACK_SETARCH "x86_64" )
add_definitions ( -DDFHACK64 )
else ( )
2023-05-23 18:03:36 -06:00
message ( SEND_ERROR "Invalid build architecture (should be 32 or 64): ${DFHACK_BUILD_ARCH}" )
2019-07-16 20:19:11 -06:00
endif ( )
if ( CMAKE_CROSSCOMPILING )
set ( DFHACK_NATIVE_BUILD_DIR "DFHACK_NATIVE_BUILD_DIR-NOTFOUND" CACHE FILEPATH "Path to a native build directory" )
include ( "${DFHACK_NATIVE_BUILD_DIR}/ImportExecutables.cmake" )
endif ( )
2016-01-08 19:08:26 -07:00
2017-04-30 15:36:42 -06:00
find_package ( Perl REQUIRED )
2012-03-13 07:46:48 -06:00
# set up folder structures for IDE solutions
2023-01-17 08:34:56 -07:00
# checking for msvc express is meaningless now, all available editions of msvc support folder groupings
option ( CMAKE_USE_FOLDERS "Enable folder grouping of projects in IDEs." ON )
2012-03-13 07:46:48 -06:00
2012-03-13 14:05:25 -06:00
if ( CMAKE_USE_FOLDERS )
2019-07-16 20:19:11 -06:00
set_property ( GLOBAL PROPERTY USE_FOLDERS ON )
2012-03-13 14:05:25 -06:00
else ( )
2019-07-16 20:19:11 -06:00
set_property ( GLOBAL PROPERTY USE_FOLDERS OFF )
2012-03-13 14:05:25 -06:00
endif ( )
2019-07-16 20:19:11 -06:00
# macro for setting up IDE folders without nasty if()s everywhere
macro ( IDE_FOLDER target folder )
2012-03-13 07:46:48 -06:00
if ( CMAKE_USE_FOLDERS )
2019-07-16 20:19:11 -06:00
set_property ( TARGET ${ target } PROPERTY FOLDER ${ folder } )
2012-03-13 07:46:48 -06:00
endif ( )
2019-07-16 20:19:11 -06:00
endmacro ( )
2012-03-13 07:46:48 -06:00
2019-07-16 20:19:11 -06:00
set ( CMAKE_MODULE_PATH
$ { d f h a c k _ S O U R C E _ D I R } / C M a k e / M o d u l e s
$ { C M A K E _ M O D U L E _ P A T H }
2011-03-20 10:17:33 -06:00
)
2010-08-16 01:09:33 -06:00
2016-01-26 18:37:27 -07:00
# generates compile_commands.json, used for autocompletion by some editors
2019-07-16 20:19:11 -06:00
set ( CMAKE_EXPORT_COMPILE_COMMANDS ON )
2016-01-26 18:37:27 -07:00
2018-06-13 09:36:57 -06:00
include ( CheckCXXSourceCompiles )
2019-07-16 20:19:11 -06:00
check_cxx_source_compiles ( "
2018-06-13 09:36:57 -06:00
#include <cstdlib>
#include <cuchar>
i n t main ( void ) {
c h a r 3 2 _ t i n = 0 ;
c h a r o u t [ M B _ C U R _ M A X ] ;
s t d : : m b s t a t e _ t s t a t e { } ;
s t d : : c32rtomb ( out, in, &state ) ;
r e t u r n 0 ;
} " H A V E _ C U C H A R 2 )
if ( HAVE_CUCHAR2 )
add_definitions ( "-DHAVE_CUCHAR" )
2018-06-12 11:25:40 -06:00
endif ( )
2011-08-14 00:42:21 -06:00
# mixing the build system with the source code is ugly and stupid. enforce the opposite :)
2022-03-29 11:28:52 -06:00
if ( "${dfhack_SOURCE_DIR}" STREQUAL "${CMAKE_BINARY_DIR}" )
2019-07-16 20:19:11 -06:00
message ( FATAL_ERROR "In-source builds are not allowed." )
2011-03-16 00:35:08 -06:00
endif ( )
2009-09-13 18:02:46 -06:00
2012-03-26 17:37:37 -06:00
# make sure all the necessary submodules have been set up
2021-03-09 22:21:46 -07:00
if ( NOT EXISTS ${ dfhack_SOURCE_DIR } /library/xml/codegen.pl
O R N O T E X I S T S $ { d f h a c k _ S O U R C E _ D I R } / s c r i p t s / C M a k e L i s t s . t x t
O R N O T E X I S T S $ { d f h a c k _ S O U R C E _ D I R } / d e p e n d s / c l s o c k e t / C M a k e L i s t s . t x t
2023-05-23 18:03:36 -06:00
O R N O T E X I S T S $ { d f h a c k _ S O U R C E _ D I R } / d e p e n d s / j s o n c p p - s u b / C M a k e L i s t s . t x t
2021-03-09 22:21:46 -07:00
O R N O T E X I S T S $ { d f h a c k _ S O U R C E _ D I R } / d e p e n d s / l i b e x p a t / e x p a t / C M a k e L i s t s . t x t
O R N O T E X I S T S $ { d f h a c k _ S O U R C E _ D I R } / d e p e n d s / l i b z i p / C M a k e L i s t s . t x t
O R N O T E X I S T S $ { d f h a c k _ S O U R C E _ D I R } / d e p e n d s / x l s x i o / C M a k e L i s t s . t x t
2023-05-23 18:03:36 -06:00
O R N O T E X I S T S $ { d f h a c k _ S O U R C E _ D I R } / d e p e n d s / g o o g l e t e s t / C M a k e L i s t s . t x t
2021-03-09 22:21:46 -07:00
O R N O T E X I S T S $ { d f h a c k _ S O U R C E _ D I R } / d e p e n d s / l u a c o v / s r c
)
2023-05-23 18:03:36 -06:00
message ( SEND_ERROR "One or more required submodules could not be found! Run 'git submodule update --init' from the root DFHack directory. (See the section 'Getting the Code' in docs/dev/compile/Compile.rst)" )
2012-03-26 17:37:37 -06:00
endif ( )
2023-05-23 18:03:36 -06:00
# dfhack data goes here:
set ( DFHACK_DATA_DESTINATION hack )
2018-07-11 09:47:55 -06:00
2011-06-19 17:12:07 -06:00
## where to install things (after the build is done, classic 'make install' or package structure)
# the dfhack libraries will be installed here:
2019-07-16 20:19:11 -06:00
if ( UNIX )
2011-08-14 00:42:21 -06:00
# put the lib into DF/hack
2023-05-23 18:03:36 -06:00
set ( DFHACK_LIBRARY_DESTINATION ${ DFHACK_DATA_DESTINATION } )
2019-07-16 20:19:11 -06:00
else ( )
2011-08-14 00:42:21 -06:00
# windows is crap, therefore we can't do nice things with it. leave the libs on a nasty pile...
2019-07-16 20:19:11 -06:00
set ( DFHACK_LIBRARY_DESTINATION . )
endif ( )
2011-08-14 00:42:21 -06:00
# external tools will be installed here:
2019-07-16 20:19:11 -06:00
set ( DFHACK_BINARY_DESTINATION . )
2011-08-14 00:42:21 -06:00
# plugin libs go here:
2023-05-23 18:03:36 -06:00
set ( DFHACK_PLUGIN_DESTINATION ${ DFHACK_DATA_DESTINATION } /plugins )
2012-03-31 05:40:54 -06:00
# dfhack lua files go here:
2023-05-23 18:03:36 -06:00
set ( DFHACK_LUA_DESTINATION ${ DFHACK_DATA_DESTINATION } /lua )
2011-08-14 00:42:21 -06:00
# user documentation goes here:
2023-05-23 18:03:36 -06:00
set ( DFHACK_USERDOC_DESTINATION ${ DFHACK_DATA_DESTINATION } )
2019-07-16 20:19:11 -06:00
# some options for the user/developer to play with
2023-05-23 18:03:36 -06:00
option ( BUILD_LIBRARY "Build the DFHack library." ON )
option ( BUILD_PLUGINS "Build the DFHack plugins." ON )
2023-07-28 20:12:58 -06:00
option ( INSTALL_SCRIPTS "Install DFHack scripts." ON )
2023-07-29 01:34:56 -06:00
option ( INSTALL_DATA_FILES "Install DFHack platform independent files." ON )
2019-07-16 20:19:11 -06:00
set ( CMAKE_POSITION_INDEPENDENT_CODE TRUE )
if ( UNIX )
## flags for GCC
# default to hidden symbols
# ensure compatibility with older CPUs
add_definitions ( -DLINUX_BUILD )
2023-08-17 03:33:13 -06:00
set ( GCC_COMMON_FLAGS "-fvisibility=hidden -mtune=generic -Wall -Werror -Wl,--disable-new-dtags" )
2021-09-06 20:56:55 -06:00
set ( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${GCC_COMMON_FLAGS}" )
set ( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${GCC_COMMON_FLAGS}" )
2019-07-16 20:19:11 -06:00
if ( DFHACK_BUILD_64 )
set ( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -m64 -mno-avx" )
set ( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -m64 -mno-avx" )
else ( )
set ( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -m32 -march=i686" )
set ( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -m32 -march=i686" )
endif ( )
string ( REPLACE "-DNDEBUG" "" CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO}" )
2023-05-23 18:03:36 -06:00
set ( CMAKE_INSTALL_RPATH ${ DFHACK_LIBRARY_DESTINATION } )
2019-07-16 20:19:11 -06:00
elseif ( MSVC )
# for msvc, tell it to always use 8-byte pointers to member functions to avoid confusion
set ( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /vmg /vmm /MP" )
set ( CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} /Od" )
string ( REPLACE "/O2" "" CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO}" )
string ( REPLACE "/DNDEBUG" "" CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO}" )
endif ( )
2011-11-06 13:16:16 -07:00
2012-03-13 07:46:48 -06:00
# use shared libraries for protobuf
2019-07-16 20:19:11 -06:00
add_definitions ( -DPROTOBUF_USE_DLLS )
add_definitions ( -DLUA_BUILD_AS_DLL )
2012-03-13 07:46:48 -06:00
2012-05-24 09:31:20 -06:00
if ( APPLE )
2012-11-16 14:33:36 -07:00
add_definitions ( -D_DARWIN )
2015-04-18 09:40:20 -06:00
set ( CMAKE_MACOSX_RPATH 1 )
2012-05-24 09:31:20 -06:00
elseif ( UNIX )
2012-03-14 09:57:29 -06:00
add_definitions ( -D_LINUX )
elseif ( WIN32 )
add_definitions ( -DWIN32 )
endif ( )
2023-05-23 18:03:36 -06:00
#### dependencies ####
# fix for pyenv: default to `python3` before `python3.x`
set ( Python_FIND_UNVERSIONED_NAMES FIRST )
2012-03-13 07:46:48 -06:00
2016-08-08 14:49:22 -06:00
include ( CMake/DownloadFile.cmake )
2016-07-27 19:08:24 -06:00
if ( WIN32 )
2023-05-23 18:15:47 -06:00
set ( ZLIB_FILE zlib.lib )
2023-05-24 04:04:33 -06:00
set ( ZLIB_PATH ${ dfhack_SOURCE_DIR } /depends/zlib/ )
2023-05-23 18:03:36 -06:00
set ( ZLIB_MD5 a3b2fc6b68efafa89b0882e354fc8418 )
2023-05-23 18:15:47 -06:00
download_file ( "https://github.com/DFHack/dfhack-bin/releases/download/0.44.09/win64-${ZLIB_FILE}"
2023-05-24 13:15:52 -06:00
$ { Z L I B _ P A T H } l i b / $ { Z L I B _ F I L E }
2023-05-23 18:03:36 -06:00
$ { Z L I B _ M D 5 } )
set ( ZLIB_ROOT ${ ZLIB_PATH } )
else ( )
# Rescan for pthread and zlib if the build arch changed
if ( NOT "${DFHACK_BUILD_ARCH}" STREQUAL "${DFHACK_BUILD_ARCH_PREV}" )
unset ( ZLIB_LIBRARY CACHE )
unset ( CMAKE_HAVE_PTHREAD_H CACHE )
2019-07-16 20:19:11 -06:00
endif ( )
2016-07-27 19:08:24 -06:00
2023-05-23 18:03:36 -06:00
if ( NOT APPLE AND DFHACK_BUILD_32 )
set ( ZLIB_ROOT /usr/lib/i386-linux-gnu )
endif ( )
endif ( )
find_package ( ZLIB REQUIRED )
include_directories ( ${ ZLIB_INCLUDE_DIRS } )
2023-04-13 02:16:22 -06:00
2023-07-30 20:53:46 -06:00
if ( BUILD_LIBRARY )
# Download SDL release and extract into depends in the build dir
# all we need are the header files (including generated headers), so the same release package
# will work for all platforms
# (the above statement is untested for OSX)
set ( SDL_VERSION 2.26.2 )
set ( SDL_ZIP_MD5 574daf26d48de753d0b1e19823c9d8bb )
set ( SDL_ZIP_FILE SDL2-devel- ${ SDL_VERSION } -VC.zip )
set ( SDL_ZIP_PATH ${ dfhack_SOURCE_DIR } /depends/SDL2/ )
download_file ( "https://github.com/libsdl-org/SDL/releases/download/release-${SDL_VERSION}/${SDL_ZIP_FILE}"
$ { S D L _ Z I P _ P A T H } $ { S D L _ Z I P _ F I L E }
$ { S D L _ Z I P _ M D 5 } )
file ( ARCHIVE_EXTRACT INPUT ${ SDL_ZIP_PATH } ${ SDL_ZIP_FILE }
D E S T I N A T I O N $ { S D L _ Z I P _ P A T H } )
include_directories ( ${ SDL_ZIP_PATH } /SDL2- ${ SDL_VERSION } /include )
endif ( )
2018-04-04 17:45:44 -06:00
2019-07-16 20:19:11 -06:00
if ( APPLE )
# libstdc++ (GCC 4.8.5 for OS X 10.6)
# fixes crash-on-unwind bug in DF's libstdc++
2022-03-29 11:28:52 -06:00
set ( LIBSTDCXX_DOWNLOAD_DIR ${ dfhack_SOURCE_DIR } /package/darwin/osx ${ DFHACK_BUILD_ARCH } )
2018-04-04 17:45:44 -06:00
2019-07-16 20:19:11 -06:00
if ( ${ GCC_VERSION_OUT } VERSION_LESS "4.9" )
set ( LIBSTDCXX_GCC_VER "48" )
2018-04-04 17:45:44 -06:00
else ( )
2019-07-16 20:19:11 -06:00
set ( LIBSTDCXX_GCC_VER "7" )
set ( LIBSTDCXX_DOWNLOAD_DIR "${LIBSTDCXX_DOWNLOAD_DIR}-gcc7" )
endif ( )
if ( ${ DFHACK_BUILD_ARCH } STREQUAL "64" )
if ( ${ LIBSTDCXX_GCC_VER } STREQUAL "48" )
download_file_unzip ( "https://github.com/DFHack/dfhack-bin/releases/download/0.44.09/osx64-gcc48-libstdcxx.6.dylib.gz"
" g z "
$ { L I B S T D C X X _ D O W N L O A D _ D I R } / l i b s t d c + + . 6 . d y l i b . g z
" c f 2 6 e d 5 8 8 b e 8 e 8 3 c 8 e 3 a 4 9 9 1 9 7 9 3 b 4 1 6 "
$ { L I B S T D C X X _ D O W N L O A D _ D I R } / l i b s t d c + + . 6 . d y l i b
" 1 6 d c 6 d b d 4 e c d e 7 f 9 b 9 5 b b 6 d c 9 1 f 0 7 4 0 4 " )
else ( )
# GCC 7
download_file_unzip ( "https://github.com/DFHack/dfhack-bin/releases/download/0.44.09/osx64-gcc7-libstdcxx.6.dylib.gz"
" g z "
$ { L I B S T D C X X _ D O W N L O A D _ D I R } / l i b s t d c + + . 6 . d y l i b . g z
" 8 1 3 1 4 b 7 8 4 6 f 9 e 8 8 0 6 4 0 9 b e f 2 1 6 0 c 7 6 e 6 "
$ { L I B S T D C X X _ D O W N L O A D _ D I R } / l i b s t d c + + . 6 . d y l i b
" 9 3 b 6 c f 4 b 0 1 e 9 a 9 0 8 4 a 5 0 8 f d 6 a 4 a 8 8 9 9 2 " )
endif ( )
else ( ) # 32-bit
if ( ${ LIBSTDCXX_GCC_VER } STREQUAL "48" )
download_file_unzip ( "https://github.com/DFHack/dfhack-bin/releases/download/0.44.09/osx32-gcc48-libstdcxx.6.dylib.gz"
" g z "
$ { L I B S T D C X X _ D O W N L O A D _ D I R } / l i b s t d c + + . 6 . d y l i b . g z
" 4 0 f 3 d 8 3 8 7 1 b 1 1 4 f 0 2 7 9 2 4 0 6 2 6 3 1 1 6 2 1 b "
$ { L I B S T D C X X _ D O W N L O A D _ D I R } / l i b s t d c + + . 6 . d y l i b
" c 3 f 5 6 7 8 b 8 2 0 4 9 1 7 e 0 3 8 7 0 8 3 4 9 0 2 c 3 e 8 b " )
else ( )
# GCC 7
download_file_unzip ( "https://github.com/DFHack/dfhack-bin/releases/download/0.44.09/osx32-gcc7-libstdcxx.6.dylib.gz"
" g z "
$ { L I B S T D C X X _ D O W N L O A D _ D I R } / l i b s t d c + + . 6 . d y l i b . g z
" d b d 2 1 3 1 7 1 f 6 6 e d b 9 0 d 2 0 4 d 5 2 5 f 1 0 c 9 6 9 "
$ { L I B S T D C X X _ D O W N L O A D _ D I R } / l i b s t d c + + . 6 . d y l i b
" b 1 4 c 8 5 7 e 7 e 4 8 5 a 0 9 7 c 7 0 a 9 c c d 3 1 3 2 d a 7 " )
endif ( )
2018-04-04 17:45:44 -06:00
endif ( )
2018-04-04 18:01:27 -06:00
2019-07-20 13:15:39 -06:00
if ( NOT EXTERNAL_LIBSTDCXX )
install ( PROGRAMS ${ LIBSTDCXX_DOWNLOAD_DIR } /libstdc++.6.dylib
D E S T I N A T I O N . / h a c k / )
endif ( )
2016-07-27 19:43:38 -06:00
endif ( )
#### expose depends ####
2022-11-28 18:16:48 -07:00
include_directories ( depends/protobuf )
include_directories ( depends/lua/include )
include_directories ( depends/md5 )
2022-11-13 13:43:21 -07:00
2016-06-26 17:48:55 -06:00
# Support linking against external tinyxml
# If we find an external tinyxml, set the DFHACK_TINYXML variable to "tinyxml"
# Otherwise, set it to "dfhack-tinyxml"
option ( EXTERNAL_TINYXML "Choose to link against external TinyXML" OFF )
if ( EXTERNAL_TINYXML )
find_package ( TinyXML REQUIRED )
if ( NOT TinyXML_FOUND )
message ( SEND_ERROR "Could not find an external TinyXML, consider setting EXTERNAL_TINYXML to OFF." )
endif ( )
2019-07-16 20:19:11 -06:00
set ( DFHACK_TINYXML "tinyxml" )
2016-06-26 17:48:55 -06:00
else ( )
include_directories ( depends/tinyxml )
2019-07-16 20:19:11 -06:00
set ( DFHACK_TINYXML "dfhack-tinyxml" )
2016-06-26 17:48:55 -06:00
endif ( )
2021-02-24 17:23:15 -07:00
include_directories ( depends/lodepng )
2012-03-13 07:46:48 -06:00
include_directories ( depends/tthread )
2012-03-13 10:10:46 -06:00
include_directories ( depends/clsocket/src )
2020-09-17 22:33:41 -06:00
include_directories ( depends/xlsxio/include )
2023-07-28 20:12:58 -06:00
if ( BUILD_LIBRARY )
add_subdirectory ( depends )
endif ( )
2012-03-10 07:31:46 -07:00
2022-11-11 15:48:00 -07:00
# Testing with CTest
2022-11-28 18:16:48 -07:00
macro ( dfhack_test name files )
2023-07-28 20:12:58 -06:00
if ( BUILD_LIBRARY AND UNIX AND NOT APPLE ) # remove this once our MSVC build env has been updated
2022-11-28 18:16:48 -07:00
add_executable ( ${ name } ${ files } )
target_include_directories ( ${ name } PUBLIC depends/googletest/googletest/include )
2023-07-19 00:15:22 -06:00
target_link_libraries ( ${ name } dfhack gtest )
2022-11-28 18:16:48 -07:00
add_test ( NAME ${ name } COMMAND ${ name } )
2022-11-30 06:34:39 -07:00
endif ( )
2022-11-28 18:16:48 -07:00
endmacro ( )
include ( CTest )
2022-11-11 15:48:00 -07:00
2022-11-11 18:17:29 -07:00
find_package ( Git REQUIRED )
if ( NOT GIT_FOUND )
message ( SEND_ERROR "could not find git" )
endif ( )
2011-08-14 00:42:21 -06:00
# build the lib itself
2023-07-29 01:34:56 -06:00
add_subdirectory ( library )
2019-07-16 20:19:11 -06:00
if ( BUILD_LIBRARY )
2023-07-29 01:34:56 -06:00
file ( WRITE ${ CMAKE_BINARY_DIR } /dfhack_setarch.txt ${ DFHACK_SETARCH } )
install ( FILES ${ CMAKE_BINARY_DIR } /dfhack_setarch.txt DESTINATION ${ DFHACK_DATA_DESTINATION } )
2011-03-18 09:47:55 -06:00
endif ( )
2010-08-15 16:45:02 -06:00
2019-07-16 20:19:11 -06:00
# build the plugins
2023-07-29 00:58:54 -06:00
add_subdirectory ( plugins )
2011-03-17 17:07:40 -06:00
2023-07-28 20:12:58 -06:00
if ( INSTALL_DATA_FILES )
add_subdirectory ( data )
2023-07-29 01:34:56 -06:00
install ( FILES LICENSE.rst DESTINATION ${ DFHACK_USERDOC_DESTINATION } )
install ( FILES docs/changelog-placeholder.txt DESTINATION ${ DFHACK_USERDOC_DESTINATION } RENAME changelog.txt )
install ( DIRECTORY ${ CMAKE_CURRENT_SOURCE_DIR } /depends/luacov/src/luacov/ DESTINATION ${ DFHACK_DATA_DESTINATION } /lua/luacov )
2023-07-28 20:12:58 -06:00
endif ( )
if ( INSTALL_SCRIPTS )
add_subdirectory ( scripts )
endif ( )
2016-06-29 17:38:15 -06:00
2019-07-16 20:19:11 -06:00
if ( BUILD_DOCS )
2022-08-15 00:01:20 -06:00
find_package ( Python3 )
find_package ( Sphinx )
2019-07-16 20:19:11 -06:00
if ( NOT SPHINX_FOUND )
message ( SEND_ERROR "Sphinx not found but BUILD_DOCS enabled" )
endif ( )
2022-07-05 13:21:41 -06:00
file ( GLOB SPHINX_GLOB_DEPS
L I S T _ D I R E C T O R I E S f a l s e
2019-07-16 20:19:11 -06:00
" $ { C M A K E _ C U R R E N T _ S O U R C E _ D I R } / d o c s / i m a g e s / * . p n g "
" $ { C M A K E _ C U R R E N T _ S O U R C E _ D I R } / d o c s / s t y l e s / * "
2022-07-05 13:21:41 -06:00
" $ { C M A K E _ C U R R E N T _ S O U R C E _ D I R } / d a t a / i n i t / * i n i t "
)
file ( GLOB_RECURSE SPHINX_GLOB_RECURSE_DEPS
" $ { C M A K E _ C U R R E N T _ S O U R C E _ D I R } / * . r s t "
" $ { C M A K E _ C U R R E N T _ S O U R C E _ D I R } / c h a n g e l o g . t x t "
2022-08-08 00:35:00 -06:00
" $ { C M A K E _ C U R R E N T _ S O U R C E _ D I R } / d o c s / * p y "
2022-07-05 13:21:41 -06:00
)
list ( FILTER SPHINX_GLOB_RECURSE_DEPS
2022-08-05 23:20:58 -06:00
E X C L U D E R E G E X " d o c s / c h a n g e l o g s "
2019-07-16 20:19:11 -06:00
)
2022-08-05 23:20:58 -06:00
list ( FILTER SPHINX_GLOB_RECURSE_DEPS
E X C L U D E R E G E X " d o c s / h t m l "
)
list ( FILTER SPHINX_GLOB_RECURSE_DEPS
E X C L U D E R E G E X " d o c s / t a g s "
)
list ( FILTER SPHINX_GLOB_RECURSE_DEPS
E X C L U D E R E G E X " d o c s / t e x t "
)
list ( FILTER SPHINX_GLOB_RECURSE_DEPS
E X C L U D E R E G E X " d o c s / t o o l s "
2019-07-16 20:19:11 -06:00
)
2022-07-05 13:21:41 -06:00
set ( SPHINX_DEPS ${ SPHINX_GLOB_DEPS } ${ SPHINX_GLOB_RECURSE_DEPS } ${ SPHINX_SCRIPT_DEPS }
2019-07-16 20:19:11 -06:00
" $ { C M A K E _ C U R R E N T _ S O U R C E _ D I R } / C M a k e L i s t s . t x t "
2022-07-05 13:21:41 -06:00
" $ { C M A K E _ C U R R E N T _ S O U R C E _ D I R } / c o n f . p y "
2019-07-16 20:19:11 -06:00
)
2023-08-05 00:59:04 -06:00
if ( BUILD_DOCS_NO_HTML )
set ( SPHINX_OUTPUT "${CMAKE_CURRENT_SOURCE_DIR}/docs/text/index.txt" )
set ( SPHINX_BUILD_TARGETS text )
else ( )
set ( SPHINX_OUTPUT "${CMAKE_CURRENT_SOURCE_DIR}/docs/html/.buildinfo" )
set ( SPHINX_BUILD_TARGETS html text )
endif ( )
2022-08-05 23:05:52 -06:00
set_property (
D I R E C T O R Y P R O P E R T Y A D D I T I O N A L _ C L E A N _ F I L E S T R U E
" $ { C M A K E _ C U R R E N T _ S O U R C E _ D I R } / d o c s / c h a n g e l o g s "
" $ { C M A K E _ C U R R E N T _ S O U R C E _ D I R } / d o c s / h t m l "
2022-08-26 14:37:58 -06:00
" $ { C M A K E _ C U R R E N T _ S O U R C E _ D I R } / d o c s / p d f "
" $ { C M A K E _ C U R R E N T _ S O U R C E _ D I R } / d o c s / p s e u d o x m l "
2022-08-05 23:05:52 -06:00
" $ { C M A K E _ C U R R E N T _ S O U R C E _ D I R } / d o c s / t a g s "
" $ { C M A K E _ C U R R E N T _ S O U R C E _ D I R } / d o c s / t e x t "
" $ { C M A K E _ C U R R E N T _ S O U R C E _ D I R } / d o c s / t o o l s "
2022-08-26 14:37:58 -06:00
" $ { C M A K E _ C U R R E N T _ S O U R C E _ D I R } / d o c s / x m l "
2022-08-05 23:05:52 -06:00
" $ { C M A K E _ B I N A R Y _ D I R } / d o c s / h t m l "
2022-08-26 14:37:58 -06:00
" $ { C M A K E _ B I N A R Y _ D I R } / d o c s / p d f "
" $ { C M A K E _ B I N A R Y _ D I R } / d o c s / p s e u d o x m l "
2022-08-05 23:05:52 -06:00
" $ { C M A K E _ B I N A R Y _ D I R } / d o c s / t e x t "
2022-08-26 14:37:58 -06:00
" $ { C M A K E _ B I N A R Y _ D I R } / d o c s / x m l "
2022-08-05 23:38:19 -06:00
)
2023-08-05 00:59:04 -06:00
2019-07-16 20:19:11 -06:00
add_custom_command ( OUTPUT ${ SPHINX_OUTPUT }
2022-08-15 15:49:44 -06:00
C O M M A N D " $ { P y t h o n 3 _ E X E C U T A B L E } " " $ { C M A K E _ C U R R E N T _ S O U R C E _ D I R } / d o c s / b u i l d . p y "
2023-08-05 00:59:04 -06:00
$ { S P H I N X _ B U I L D _ T A R G E T S } - - s p h i n x = " $ { S P H I N X _ E X E C U T A B L E } " - - - q - W
2019-07-16 20:19:11 -06:00
D E P E N D S $ { S P H I N X _ D E P S }
2022-07-05 13:21:41 -06:00
C O M M E N T " B u i l d i n g d o c u m e n t a t i o n w i t h S p h i n x "
2019-07-16 20:19:11 -06:00
)
add_custom_target ( dfhack_docs ALL
D E P E N D S $ { S P H I N X _ O U T P U T }
)
# Sphinx doesn't touch this file if it didn't make changes,
# which makes CMake think it didn't complete
add_custom_command ( TARGET dfhack_docs POST_BUILD
C O M M A N D $ { C M A K E _ C O M M A N D } - E t o u c h $ { S P H I N X _ O U T P U T } )
2023-08-05 00:59:04 -06:00
if ( NOT BUILD_DOCS_NO_HTML )
install ( DIRECTORY ${ dfhack_SOURCE_DIR } /docs/html/
D E S T I N A T I O N $ { D F H A C K _ U S E R D O C _ D E S T I N A T I O N } / d o c s
F I L E S _ M A T C H I N G P A T T E R N " * "
P A T T E R N h t m l / _ s o u r c e s E X C L U D E )
endif ( )
2022-07-05 13:21:41 -06:00
install ( DIRECTORY ${ dfhack_SOURCE_DIR } /docs/text/
D E S T I N A T I O N $ { D F H A C K _ U S E R D O C _ D E S T I N A T I O N } / d o c s )
2022-07-10 00:01:31 -06:00
install ( FILES docs/changelogs/news.rst docs/changelogs/news-dev.rst DESTINATION ${ DFHACK_USERDOC_DESTINATION } )
2019-07-16 20:19:11 -06:00
install ( FILES "README.html" DESTINATION "${DFHACK_DATA_DESTINATION}" )
2015-09-24 00:04:09 -06:00
endif ( )
2022-11-28 18:16:48 -07:00
option ( BUILD_TESTS "Include tests (currently just installs Lua tests into the scripts folder)" OFF )
if ( BUILD_TESTS )
if ( EXISTS "${dfhack_SOURCE_DIR}/test/scripts" )
message ( SEND_ERROR "test/scripts must not exist in the dfhack repo since it would conflict with the tests installed from the scripts repo." )
endif ( )
install ( DIRECTORY ${ dfhack_SOURCE_DIR } /test
2022-11-28 18:40:06 -07:00
D E S T I N A T I O N $ { D F H A C K _ D A T A _ D E S T I N A T I O N } / s c r i p t s )
2022-11-28 18:16:48 -07:00
install ( FILES ci/test.lua DESTINATION ${ DFHACK_DATA_DESTINATION } /scripts )
endif ( )
2011-06-19 17:12:07 -06:00
# Packaging with CPack!
2019-07-16 20:19:11 -06:00
set ( DFHACK_PACKAGE_SUFFIX "" )
if ( UNIX )
2015-11-07 18:27:48 -07:00
execute_process ( COMMAND ${ CMAKE_CXX_COMPILER } -dumpversion OUTPUT_VARIABLE GCC_VERSION )
string ( STRIP ${ GCC_VERSION } GCC_VERSION )
2019-07-16 20:19:11 -06:00
set ( DFHACK_PACKAGE_SUFFIX "-gcc-${GCC_VERSION}" )
set ( CPACK_GENERATOR "TBZ2" )
elseif ( WIN32 )
set ( CPACK_GENERATOR "ZIP" )
endif ( )
2011-08-14 17:30:15 -06:00
set ( CPACK_INCLUDE_TOPLEVEL_DIRECTORY 0 )
2019-07-16 20:19:11 -06:00
if ( APPLE )
2015-01-07 14:03:24 -07:00
set ( DFHACK_PACKAGE_PLATFORM_NAME OSX )
2019-07-16 20:19:11 -06:00
else ( )
2015-01-07 14:03:24 -07:00
set ( DFHACK_PACKAGE_PLATFORM_NAME ${ CMAKE_SYSTEM_NAME } )
2019-07-16 20:19:11 -06:00
endif ( )
2018-07-11 09:47:55 -06:00
# set on command line
if ( DFHACK_BUILD_ID STREQUAL "" )
2019-07-16 20:19:11 -06:00
set ( DFHACK_BUILD_ID_PACKAGE "" )
2018-07-11 09:47:55 -06:00
else ( )
2019-07-16 20:19:11 -06:00
set ( DFHACK_BUILD_ID_PACKAGE "${DFHACK_BUILD_ID}-" )
2018-07-11 09:47:55 -06:00
endif ( )
2020-03-21 00:42:12 -06:00
set ( CPACK_PACKAGE_FILE_NAME "dfhack-${DFHACK_VERSION}-${DFHACK_BUILD_ID_PACKAGE}${DFHACK_PACKAGE_PLATFORM_NAME}-${DFHACK_BUILD_ARCH}bit${DFHACK_PACKAGE_SUFFIX}" )
2019-07-16 20:19:11 -06:00
include ( CPack )
option ( DFHACK_INCLUDE_CORE "Download and include Dwarf Fortress core files in DFHack. Useful for local testing, but should not be used in releases." OFF )
if ( DFHACK_INCLUDE_CORE )
string ( REPLACE "." "_" DF_CORE_FILENAME "${DF_VERSION}" )
string ( REGEX REPLACE "^0_" "df_" DF_CORE_FILENAME "${DF_CORE_FILENAME}" )
if ( UNIX )
if ( APPLE )
string ( APPEND DF_CORE_FILENAME "_osx" )
else ( )
string ( APPEND DF_CORE_FILENAME "_linux" )
endif ( )
if ( DFHACK_BUILD_32 )
string ( APPEND DF_CORE_FILENAME "32" )
endif ( )
string ( APPEND DF_CORE_FILENAME ".tar.bz2" )
else ( )
string ( APPEND DF_CORE_FILENAME "_win" )
if ( DFHACK_BUILD_32 )
string ( APPEND DF_CORE_FILENAME "32" )
endif ( )
string ( APPEND DF_CORE_FILENAME ".zip" )
endif ( )
set ( DF_CORE_URL "http://bay12games.com/dwarves/${DF_CORE_FILENAME}" )
if ( NOT EXISTS "${CMAKE_BINARY_DIR}/${DF_CORE_FILENAME}" )
file ( DOWNLOAD "${DF_CORE_URL}" "${CMAKE_BINARY_DIR}/${DF_CORE_FILENAME}" SHOW_PROGRESS )
endif ( )
file ( REMOVE_RECURSE "${CMAKE_BINARY_DIR}/df-core" )
file ( MAKE_DIRECTORY "${CMAKE_BINARY_DIR}/df-core" )
if ( UNIX )
2018-07-20 12:29:18 -06:00
execute_process ( COMMAND ${ CMAKE_COMMAND } -E tar xjf "../${DF_CORE_FILENAME}" --strip-components=1
2019-07-16 20:19:11 -06:00
W O R K I N G _ D I R E C T O R Y " $ { C M A K E _ B I N A R Y _ D I R } / d f - c o r e " )
else ( )
2018-07-20 12:29:18 -06:00
execute_process ( COMMAND ${ CMAKE_COMMAND } -E tar xf "../${DF_CORE_FILENAME}" --format=zip
2019-07-16 20:19:11 -06:00
W O R K I N G _ D I R E C T O R Y " $ { C M A K E _ B I N A R Y _ D I R } / d f - c o r e " )
file ( REMOVE "${CMAKE_BINARY_DIR}/df-core/SDL.dll" )
endif ( )
install ( DIRECTORY "${CMAKE_BINARY_DIR}/df-core/"
D E S T I N A T I O N . )
endif ( )
2016-09-15 08:24:57 -06:00
# Store old build arch
2019-07-16 20:19:11 -06:00
set ( DFHACK_BUILD_ARCH_PREV "${DFHACK_BUILD_ARCH}" CACHE STRING "Previous build architecture" FORCE )
2020-02-08 19:17:53 -07:00
option ( BUILD_SIZECHECK "Build the sizecheck library, for research" OFF )
2023-07-28 20:12:58 -06:00
if ( BUILD_LIBRARY AND BUILD_SIZECHECK )
2020-02-08 19:17:53 -07:00
add_subdirectory ( depends/sizecheck )
add_dependencies ( dfhack sizecheck )
endif ( )
2023-03-07 23:13:08 -07:00
add_subdirectory ( package/windows )