clean up some cmake

develop
Myk Taylor 2023-05-23 17:03:36 -07:00
parent b59201d325
commit abc1a6a569
No known key found for this signature in database
GPG Key ID: 8A39CA0FA0C16E78
1 changed files with 48 additions and 79 deletions

@ -1,21 +1,19 @@
# main project file. use it from a build sub-folder, see COMPILE for details # main project file. use it from a build sub-folder, see COMPILE for details
## some generic CMake magic ## some generic CMake magic
cmake_minimum_required(VERSION 3.6 FATAL_ERROR) cmake_minimum_required(VERSION 3.18 FATAL_ERROR)
cmake_policy(SET CMP0048 NEW) cmake_policy(SET CMP0048 NEW)
cmake_policy(SET CMP0074 NEW)
project(dfhack) project(dfhack)
if("${CMAKE_GENERATOR}" STREQUAL Ninja) # set up versioning.
if("${CMAKE_VERSION}" VERSION_LESS 3.9) set(DF_VERSION "50.08")
message(WARNING "You are using an old version of CMake (${CMAKE_VERSION}) with Ninja. This may result in ninja errors - see docs/Compile.rst for more details. Upgrading your CMake version is recommended.") set(DFHACK_RELEASE "r2rc1")
endif() set(DFHACK_PRERELEASE TRUE)
endif()
if(NOT("${CMAKE_VERSION}" VERSION_LESS 3.12)) set(DFHACK_VERSION "${DF_VERSION}-${DFHACK_RELEASE}")
# make ZLIB_ROOT work in CMake >= 3.12 set(DFHACK_ABI_VERSION 1)
# https://cmake.org/cmake/help/git-stage/policy/CMP0074.html set(DFHACK_BUILD_ID "" CACHE STRING "Build ID (should be specified on command line)")
cmake_policy(SET CMP0074 NEW)
endif()
# Set up build types # Set up build types
if(CMAKE_CONFIGURATION_TYPES) if(CMAKE_CONFIGURATION_TYPES)
@ -123,7 +121,7 @@ elseif("${DFHACK_BUILD_ARCH}" STREQUAL "64")
set(DFHACK_SETARCH "x86_64") set(DFHACK_SETARCH "x86_64")
add_definitions(-DDFHACK64) add_definitions(-DDFHACK64)
else() else()
message(SEND_ERROR "Invalid build architecture (should be 32/64): ${DFHACK_BUILD_ARCH}") message(SEND_ERROR "Invalid build architecture (should be 32 or 64): ${DFHACK_BUILD_ARCH}")
endif() endif()
if(CMAKE_CROSSCOMPILING) if(CMAKE_CROSSCOMPILING)
@ -182,30 +180,24 @@ endif()
if(NOT EXISTS ${dfhack_SOURCE_DIR}/library/xml/codegen.pl if(NOT EXISTS ${dfhack_SOURCE_DIR}/library/xml/codegen.pl
OR NOT EXISTS ${dfhack_SOURCE_DIR}/scripts/CMakeLists.txt OR NOT EXISTS ${dfhack_SOURCE_DIR}/scripts/CMakeLists.txt
OR NOT EXISTS ${dfhack_SOURCE_DIR}/depends/clsocket/CMakeLists.txt OR NOT EXISTS ${dfhack_SOURCE_DIR}/depends/clsocket/CMakeLists.txt
OR NOT EXISTS ${dfhack_SOURCE_DIR}/depends/jsoncpp-sub/CMakeLists.txt
OR NOT EXISTS ${dfhack_SOURCE_DIR}/depends/libexpat/expat/CMakeLists.txt OR NOT EXISTS ${dfhack_SOURCE_DIR}/depends/libexpat/expat/CMakeLists.txt
OR NOT EXISTS ${dfhack_SOURCE_DIR}/depends/libzip/CMakeLists.txt OR NOT EXISTS ${dfhack_SOURCE_DIR}/depends/libzip/CMakeLists.txt
OR NOT EXISTS ${dfhack_SOURCE_DIR}/depends/xlsxio/CMakeLists.txt OR NOT EXISTS ${dfhack_SOURCE_DIR}/depends/xlsxio/CMakeLists.txt
OR NOT EXISTS ${dfhack_SOURCE_DIR}/depends/googletest/CMakeLists.txt
OR NOT EXISTS ${dfhack_SOURCE_DIR}/depends/luacov/src OR NOT EXISTS ${dfhack_SOURCE_DIR}/depends/luacov/src
) )
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/Compile.rst)") 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)")
endif() endif()
# set up versioning. # dfhack data goes here:
set(DF_VERSION "50.08") set(DFHACK_DATA_DESTINATION hack)
set(DFHACK_RELEASE "r3")
set(DFHACK_PRERELEASE FALSE)
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)")
## where to install things (after the build is done, classic 'make install' or package structure) ## where to install things (after the build is done, classic 'make install' or package structure)
# the dfhack libraries will be installed here: # the dfhack libraries will be installed here:
if(UNIX) if(UNIX)
# put the lib into DF/hack # put the lib into DF/hack
set(DFHACK_LIBRARY_DESTINATION hack) set(DFHACK_LIBRARY_DESTINATION ${DFHACK_DATA_DESTINATION})
else() else()
# windows is crap, therefore we can't do nice things with it. leave the libs on a nasty pile... # windows is crap, therefore we can't do nice things with it. leave the libs on a nasty pile...
set(DFHACK_LIBRARY_DESTINATION .) set(DFHACK_LIBRARY_DESTINATION .)
@ -213,31 +205,26 @@ endif()
# external tools will be installed here: # external tools will be installed here:
set(DFHACK_BINARY_DESTINATION .) set(DFHACK_BINARY_DESTINATION .)
# dfhack data goes here:
set(DFHACK_DATA_DESTINATION hack)
# plugin libs go here: # plugin libs go here:
set(DFHACK_PLUGIN_DESTINATION hack/plugins) set(DFHACK_PLUGIN_DESTINATION ${DFHACK_DATA_DESTINATION}/plugins)
# dfhack header files go here:
set(DFHACK_INCLUDES_DESTINATION hack/include)
# dfhack lua files go here: # dfhack lua files go here:
set(DFHACK_LUA_DESTINATION hack/lua) set(DFHACK_LUA_DESTINATION ${DFHACK_DATA_DESTINATION}/lua)
# the windows .lib file goes here: # the windows .lib file goes here:
set(DFHACK_DEVLIB_DESTINATION hack) set(DFHACK_DEVLIB_DESTINATION ${DFHACK_DATA_DESTINATION})
# user documentation goes here: # user documentation goes here:
set(DFHACK_USERDOC_DESTINATION hack) set(DFHACK_USERDOC_DESTINATION ${DFHACK_DATA_DESTINATION})
# developer documentation goes here: # developer documentation goes here:
set(DFHACK_DEVDOC_DESTINATION hack) set(DFHACK_DEVDOC_DESTINATION ${DFHACK_DATA_DESTINATION})
# some options for the user/developer to play with # some options for the user/developer to play with
option(BUILD_LIBRARY "Build the library that goes into DF." ON) option(BUILD_LIBRARY "Build the DFHack library." ON)
option(BUILD_PLUGINS "Build the plugins." ON) option(BUILD_PLUGINS "Build the DFHack plugins." ON)
set(CMAKE_POSITION_INDEPENDENT_CODE TRUE) set(CMAKE_POSITION_INDEPENDENT_CODE TRUE)
if(UNIX) if(UNIX)
## flags for GCC ## flags for GCC
# default to hidden symbols # default to hidden symbols
# build 32bit
# ensure compatibility with older CPUs # ensure compatibility with older CPUs
# enable C++11 features # enable C++11 features
add_definitions(-DLINUX_BUILD) add_definitions(-DLINUX_BUILD)
@ -254,7 +241,7 @@ if(UNIX)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -m32 -march=i686") set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -m32 -march=i686")
endif() endif()
string(REPLACE "-DNDEBUG" "" CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO}") string(REPLACE "-DNDEBUG" "" CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO}")
set(CMAKE_INSTALL_RPATH "hack") set(CMAKE_INSTALL_RPATH ${DFHACK_LIBRARY_DESTINATION})
elseif(MSVC) elseif(MSVC)
# for msvc, tell it to always use 8-byte pointers to member functions to avoid confusion # 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 "${CMAKE_CXX_FLAGS} /vmg /vmm /MP")
@ -276,30 +263,37 @@ elseif(WIN32)
add_definitions(-DWIN32) add_definitions(-DWIN32)
endif() endif()
#### download depends #### #### dependencies ####
# fix for pyenv: default to `python3` before `python3.x`
set(Python_FIND_UNVERSIONED_NAMES FIRST)
include(CMake/DownloadFile.cmake) include(CMake/DownloadFile.cmake)
if(WIN32) if(WIN32)
# Download zlib on Windows set(ZLIB_FILE win64-zlib.lib)
set(ZLIB_DOWNLOAD_DIR ${dfhack_SOURCE_DIR}/depends/zlib/lib/win${DFHACK_BUILD_ARCH}) set(ZLIB_PATH ${CMAKE_BINARY_DIR}/depends/zlib/)
if(${DFHACK_BUILD_ARCH} STREQUAL "64") set(ZLIB_MD5 a3b2fc6b68efafa89b0882e354fc8418)
download_file("https://github.com/DFHack/dfhack-bin/releases/download/0.44.09/win64-zlib.lib" file(COPY ${dfhack_SOURCE_DIR}/depends/zlib/ DESTINATION ${ZLIB_PATH})
${ZLIB_DOWNLOAD_DIR}/zlib.lib download_file("https://github.com/DFHack/dfhack-bin/releases/download/0.44.09/${ZLIB_FILE}"
"a3b2fc6b68efafa89b0882e354fc8418") ${ZLIB_PATH}${ZLIB_FILE}
else() ${ZLIB_MD5})
download_file("https://github.com/DFHack/dfhack-bin/releases/download/0.44.09/win32-zlib.lib" set(ZLIB_ROOT ${ZLIB_PATH})
${ZLIB_DOWNLOAD_DIR}/zlib.lib else()
"f4ebaa21d9de28566e88b1edfcdff901") # 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)
endif() endif()
# Move zlib to the build folder so possible 32 and 64-bit builds if(NOT APPLE AND DFHACK_BUILD_32)
# in the same source tree don't conflict set(ZLIB_ROOT /usr/lib/i386-linux-gnu)
file(COPY ${dfhack_SOURCE_DIR}/depends/zlib endif()
DESTINATION ${CMAKE_BINARY_DIR}/depends/) endif()
file(COPY ${ZLIB_DOWNLOAD_DIR}/zlib.lib find_package(ZLIB REQUIRED)
DESTINATION ${CMAKE_BINARY_DIR}/depends/zlib/lib/) include_directories(${ZLIB_INCLUDE_DIRS})
if(WIN32)
# Do the same for SDL.dll # Do the same for SDL.dll
# (DFHack doesn't require this at build time, so no need to move it to the build folder) # (DFHack doesn't require this at build time, so no need to move it to the build folder)
# TODO: remove SDL.dll from our distribution once DF moves to SDL2. we only # TODO: remove SDL.dll from our distribution once DF moves to SDL2. we only
@ -315,7 +309,6 @@ if(WIN32)
${SDL_DOWNLOAD_DIR}/SDL.dll ${SDL_DOWNLOAD_DIR}/SDL.dll
"5a09604daca6b2b5ce049d79af935d6a") "5a09604daca6b2b5ce049d79af935d6a")
endif() endif()
endif() endif()
if(APPLE) if(APPLE)
@ -376,29 +369,6 @@ endif()
#### expose depends #### #### expose depends ####
# fix for pyenv: default to `python3` before `python3.x`
set(Python_FIND_UNVERSIONED_NAMES FIRST)
if(UNIX)
# 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)
endif()
endif()
# find and make available libz
if(NOT UNIX) # Windows
# zlib is in here so 32-bit and 64-bit builds in the same source tree are possible
set(ZLIB_ROOT ${CMAKE_BINARY_DIR}/depends/zlib/)
else()
if(NOT APPLE AND DFHACK_BUILD_32)
# 32-bit Linux
set(ZLIB_ROOT /usr/lib/i386-linux-gnu)
endif()
endif()
find_package(ZLIB REQUIRED)
include_directories(depends/protobuf) include_directories(depends/protobuf)
include_directories(depends/lua/include) include_directories(depends/lua/include)
include_directories(depends/md5) include_directories(depends/md5)
@ -420,7 +390,6 @@ endif()
include_directories(depends/lodepng) include_directories(depends/lodepng)
include_directories(depends/tthread) include_directories(depends/tthread)
include_directories(${ZLIB_INCLUDE_DIRS})
include_directories(depends/clsocket/src) include_directories(depends/clsocket/src)
include_directories(depends/xlsxio/include) include_directories(depends/xlsxio/include)
add_subdirectory(depends) add_subdirectory(depends)