dfhack/library/CMakeLists.txt

461 lines
15 KiB
CMake

2019-07-16 20:19:11 -06:00
project(dfapi)
cmake_minimum_required(VERSION 2.8.12)
# prevent CMake warnings about INTERFACE_LINK_LIBRARIES vs LINK_INTERFACE_LIBRARIES
2019-07-16 20:19:11 -06:00
cmake_policy(SET CMP0022 NEW)
2019-07-16 20:19:11 -06:00
# build options
option(BUILD_DEVEL "Install/package files required for development(For SDK)." OFF)
if(UNIX)
option(CONSOLE_NO_CATCH "Make the console not catch 'CTRL+C' events for easier debugging." OFF)
endif()
2019-07-16 20:19:11 -06:00
include_directories(proto)
include_directories(include)
2009-09-13 18:02:46 -06:00
execute_process(COMMAND ${PERL_EXECUTABLE} xml/list.pl xml ${dfapi_SOURCE_DIR}/include/df ";"
2019-07-16 20:19:11 -06:00
WORKING_DIRECTORY ${dfapi_SOURCE_DIR}
OUTPUT_VARIABLE GENERATED_HDRS)
set_source_files_properties(${GENERATED_HDRS} PROPERTIES HEADER_FILE_ONLY TRUE GENERATED TRUE)
set(MAIN_HEADERS
include/Internal.h
include/DFHack.h
include/DFHackVersion.h
include/Console.h
include/Core.h
include/ColorText.h
include/DataDefs.h
include/DataIdentity.h
include/Debug.h
include/DebugManager.h
include/VTableInterpose.h
include/LuaWrapper.h
include/LuaTools.h
include/Error.h
include/Export.h
include/Hooks.h
include/MiscUtils.h
include/Module.h
include/Pragma.h
include/MemAccess.h
include/PluginManager.h
include/PluginStatics.h
2019-07-16 20:19:11 -06:00
include/Signal.hpp
include/TileTypes.h
include/Types.h
include/VersionInfo.h
include/VersionInfoFactory.h
include/RemoteClient.h
include/RemoteServer.h
include/RemoteTools.h
)
2019-07-16 20:19:11 -06:00
set(MAIN_HEADERS_WINDOWS
include/wdirent.h
)
2019-07-16 20:19:11 -06:00
set(MAIN_SOURCES
Core.cpp
ColorText.cpp
CompilerWorkAround.cpp
DataDefs.cpp
Debug.cpp
Error.cpp
VTableInterpose.cpp
LuaWrapper.cpp
LuaTypes.cpp
LuaTools.cpp
LuaApi.cpp
DataStatics.cpp
DataStaticsCtor.cpp
DataStaticsFields.cpp
MiscUtils.cpp
Types.cpp
PluginManager.cpp
PluginStatics.cpp
2019-07-16 20:19:11 -06:00
TileTypes.cpp
VersionInfoFactory.cpp
RemoteClient.cpp
RemoteServer.cpp
RemoteTools.cpp
)
if(WIN32)
set(CONSOLE_SOURCES Console-windows.cpp)
else()
set(CONSOLE_SOURCES Console-posix.cpp)
endif()
2019-07-16 20:19:11 -06:00
set(MAIN_SOURCES_WINDOWS
${CONSOLE_SOURCES}
2019-07-16 20:19:11 -06:00
Hooks-windows.cpp
PlugLoad-windows.cpp
Process-windows.cpp
)
2019-07-16 20:19:11 -06:00
if(WIN32)
source_group("Main\\Headers" FILES ${MAIN_HEADERS} ${MAIN_HEADERS_WINDOWS})
source_group("Main\\Sources" FILES ${MAIN_SOURCES} ${MAIN_SOURCES_WINDOWS})
endif()
2019-07-16 20:19:11 -06:00
set(MAIN_SOURCES_LINUX
${CONSOLE_SOURCES}
2019-07-16 20:19:11 -06:00
Hooks-linux.cpp
PlugLoad-posix.cpp
Process-linux.cpp
)
2019-07-16 20:19:11 -06:00
set(MAIN_SOURCES_DARWIN
${CONSOLE_SOURCES}
2019-07-16 20:19:11 -06:00
Hooks-darwin.cpp
PlugLoad-posix.cpp
Process-darwin.cpp
)
2019-07-16 20:19:11 -06:00
set(MODULE_HEADERS
include/modules/Buildings.h
include/modules/Burrows.h
include/modules/Constructions.h
include/modules/Designations.h
include/modules/EventManager.h
include/modules/Filesystem.h
include/modules/Graphic.h
include/modules/Gui.h
include/modules/GuiHooks.h
include/modules/Items.h
include/modules/Job.h
include/modules/Kitchen.h
include/modules/MapCache.h
include/modules/Maps.h
include/modules/Materials.h
include/modules/Once.h
include/modules/Persistence.h
2019-07-16 20:19:11 -06:00
include/modules/Random.h
include/modules/Renderer.h
include/modules/Screen.h
include/modules/Translation.h
include/modules/Units.h
include/modules/World.h
)
2019-07-16 20:19:11 -06:00
set(MODULE_SOURCES
modules/Buildings.cpp
modules/Burrows.cpp
modules/Constructions.cpp
modules/Designations.cpp
modules/EventManager.cpp
modules/Filesystem.cpp
modules/Graphic.cpp
modules/Gui.cpp
modules/Items.cpp
modules/Job.cpp
modules/Kitchen.cpp
modules/MapCache.cpp
modules/Maps.cpp
modules/Materials.cpp
modules/Once.cpp
modules/Persistence.cpp
2019-07-16 20:19:11 -06:00
modules/Random.cpp
modules/Renderer.cpp
modules/Screen.cpp
modules/Translation.cpp
modules/Units.cpp
modules/World.cpp
2010-08-12 18:35:10 -06:00
)
2019-07-16 20:19:11 -06:00
set(STATIC_FIELDS_FILES)
foreach(GROUP other a b c d e f g h i j k l m n o p q r s t u v w x y z)
set(STATIC_FIELDS_FILENAME ${dfhack_SOURCE_DIR}/library/DataStaticsFields/${GROUP}.cpp)
if(${GROUP} STREQUAL "other")
set(STATIC_FIELDS_INC_FILENAME "df/static.fields.inc")
else()
set(STATIC_FIELDS_INC_FILENAME "df/static.fields-${GROUP}.inc")
endif()
file(WRITE ${STATIC_FIELDS_FILENAME}.tmp
"#define STATIC_FIELDS_GROUP\n"
"#include \"../DataStaticsFields.cpp\"\n"
"#include \"${STATIC_FIELDS_INC_FILENAME}\"\n"
)
2019-07-16 20:19:11 -06:00
execute_process(COMMAND ${CMAKE_COMMAND} -E copy_if_different
${STATIC_FIELDS_FILENAME}.tmp ${STATIC_FIELDS_FILENAME})
2019-07-16 20:19:11 -06:00
file(REMOVE ${STATIC_FIELDS_FILENAME}.tmp)
list(APPEND STATIC_FIELDS_FILES ${STATIC_FIELDS_FILENAME})
endforeach()
list(APPEND MAIN_SOURCES ${STATIC_FIELDS_FILES})
if(WIN32)
source_group("Modules\\Headers" FILES ${MODULE_HEADERS})
source_group("Modules\\Sources" FILES ${MODULE_SOURCES})
source_group("Generated" FILES ${GENERATED_HDRS})
endif()
set(PROJECT_HEADERS)
list(APPEND PROJECT_HEADERS ${MAIN_HEADERS})
list(APPEND PROJECT_HEADERS ${MODULE_HEADERS})
set(PROJECT_SOURCES)
list(APPEND PROJECT_SOURCES ${MAIN_SOURCES})
list(APPEND PROJECT_SOURCES ${MODULE_SOURCES})
if(UNIX)
if(APPLE)
2019-07-16 20:19:11 -06:00
list(APPEND PROJECT_SOURCES ${MAIN_SOURCES_DARWIN})
else()
list(APPEND PROJECT_SOURCES ${MAIN_SOURCES_LINUX})
endif()
elseif(WIN32)
list(APPEND PROJECT_SOURCES ${MAIN_SOURCES_WINDOWS})
list(APPEND PROJECT_HEADERS ${MAIN_HEADERS_WINDOWS})
endif()
# Protobuf
2019-07-16 20:19:11 -06:00
file(GLOB PROJECT_PROTOS ${CMAKE_CURRENT_SOURCE_DIR}/proto/*.proto)
2019-07-16 20:19:11 -06:00
string(REPLACE ".proto" ".pb.cc" PROJECT_PROTO_SRCS "${PROJECT_PROTOS}")
string(REPLACE ".proto" ".pb.h" PROJECT_PROTO_HDRS "${PROJECT_PROTOS}")
string(REPLACE "/proto/" "/proto/tmp/" PROJECT_PROTO_TMP_FILES "${PROJECT_PROTO_SRCS};${PROJECT_PROTO_HDRS}")
set_source_files_properties(${PROJECT_PROTO_SRCS} ${PROJECT_PROTO_HDRS}
PROPERTIES GENERATED TRUE)
# Force a re-gen if any *.pb.* files are missing
# (only runs when cmake is run, but better than nothing)
2019-07-16 20:19:11 -06:00
foreach(file IN LISTS PROJECT_PROTO_SRCS PROJECT_PROTO_HDRS)
if(NOT EXISTS ${file})
# message("Resetting generate_proto_core because '${file}' is missing")
file(REMOVE ${PROJECT_PROTO_TMP_FILES})
break()
endif()
endforeach()
list(APPEND PROJECT_HEADERS ${PROJECT_PROTO_HDRS})
list(APPEND PROJECT_SOURCES ${PROJECT_PROTO_SRCS})
add_custom_command(
OUTPUT ${PROJECT_PROTO_TMP_FILES}
COMMAND protoc-bin -I=${CMAKE_CURRENT_SOURCE_DIR}/proto/
2019-07-16 20:19:11 -06:00
--cpp_out=dllexport_decl=DFHACK_EXPORT:${CMAKE_CURRENT_SOURCE_DIR}/proto/tmp/
${PROJECT_PROTOS}
COMMAND ${PERL_EXECUTABLE} ${dfhack_SOURCE_DIR}/depends/copy-if-different.pl
2019-07-16 20:19:11 -06:00
${PROJECT_PROTO_TMP_FILES}
${CMAKE_CURRENT_SOURCE_DIR}/proto/
COMMENT "Generating core protobufs"
DEPENDS protoc-bin ${PROJECT_PROTOS}
)
2019-07-16 20:19:11 -06:00
if(UNIX)
set_source_files_properties(${PROJECT_PROTO_SRCS} PROPERTIES COMPILE_FLAGS "-Wno-misleading-indentation")
endif()
2019-07-16 20:19:11 -06:00
add_custom_target(generate_proto_core DEPENDS ${PROJECT_PROTO_TMP_FILES})
# Merge headers into sources
2019-07-16 20:19:11 -06:00
set_source_files_properties( ${PROJECT_HEADERS} PROPERTIES HEADER_FILE_ONLY TRUE )
list(APPEND PROJECT_SOURCES ${PROJECT_HEADERS})
2011-12-24 03:37:00 -07:00
# Generation
2019-07-16 20:19:11 -06:00
list(APPEND PROJECT_SOURCES ${GENERATED_HDRS})
2011-12-24 03:37:00 -07:00
2019-07-16 20:19:11 -06:00
file(GLOB GENERATE_INPUT_SCRIPTS ${dfapi_SOURCE_DIR}/xml/*.pm ${dfapi_SOURCE_DIR}/xml/*.xslt)
file(GLOB GENERATE_INPUT_XMLS ${dfapi_SOURCE_DIR}/xml/df.*.xml)
2011-12-24 03:37:00 -07:00
set(CODEGEN_OUT ${dfapi_SOURCE_DIR}/include/df/codegen.out.xml)
2019-07-16 20:19:11 -06:00
if(NOT("${CMAKE_GENERATOR}" STREQUAL Ninja))
# use BYPRODUCTS instead under Ninja to avoid rebuilds
2019-07-16 20:19:11 -06:00
list(APPEND CODEGEN_OUT ${GENERATED_HDRS})
endif()
2019-07-16 20:19:11 -06:00
add_custom_command(
OUTPUT ${CODEGEN_OUT}
BYPRODUCTS ${GENERATED_HDRS}
COMMAND ${PERL_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/xml/codegen.pl
${CMAKE_CURRENT_SOURCE_DIR}/xml
${CMAKE_CURRENT_SOURCE_DIR}/include/df
2011-12-24 03:37:00 -07:00
MAIN_DEPENDENCY ${dfapi_SOURCE_DIR}/xml/codegen.pl
COMMENT "Generating codegen.out.xml and df/headers"
DEPENDS ${GENERATE_INPUT_XMLS} ${GENERATE_INPUT_SCRIPTS}
2011-12-24 03:37:00 -07:00
)
2019-07-16 20:19:11 -06:00
add_custom_target(generate_headers
DEPENDS ${dfapi_SOURCE_DIR}/include/df/codegen.out.xml)
2019-07-16 20:19:11 -06:00
if(REMOVE_SYMBOLS_FROM_DF_STUBS)
if(UNIX)
# Don't produce debug info for generated stubs
set_source_files_properties(DataStatics.cpp DataStaticsCtor.cpp DataStaticsFields.cpp ${STATIC_FIELDS_FILES}
PROPERTIES COMPILE_FLAGS "-g0 -O1")
else(WIN32)
set_source_files_properties(DataStatics.cpp DataStaticsCtor.cpp DataStaticsFields.cpp ${STATIC_FIELDS_FILES}
PROPERTIES COMPILE_FLAGS "/O1 /bigobj")
endif()
else()
if(WIN32)
set_source_files_properties(DataStatics.cpp DataStaticsCtor.cpp DataStaticsFields.cpp ${STATIC_FIELDS_FILES}
PROPERTIES COMPILE_FLAGS "/Od /bigobj")
endif()
endif()
2011-12-24 03:37:00 -07:00
# Compilation
2019-07-16 20:19:11 -06:00
add_definitions(-DBUILD_DFHACK_LIB)
2019-07-16 20:19:11 -06:00
if(UNIX)
if(CONSOLE_NO_CATCH)
add_definitions(-DCONSOLE_NO_CATCH)
endif()
endif()
2019-07-16 20:19:11 -06:00
if(APPLE)
set(PROJECT_LIBS dl dfhack-md5 ${DFHACK_TINYXML} dfhack-tinythread)
elseif(UNIX)
set(PROJECT_LIBS rt dl dfhack-md5 ${DFHACK_TINYXML} dfhack-tinythread)
else(WIN32)
# FIXME: do we really need psapi?
set(PROJECT_LIBS psapi dfhack-md5 ${DFHACK_TINYXML} dfhack-tinythread)
endif()
2009-09-13 18:02:46 -06:00
set(VERSION_SRCS DFHackVersion.cpp)
set(VERSION_HDRS include/git-describe.h)
2019-07-16 20:19:11 -06:00
set_source_files_properties(${VERSION_HDRS} PROPERTIES HEADER_FILE_ONLY TRUE)
2019-07-16 20:19:11 -06:00
list(APPEND VERSION_SRCS ${VERSION_HDRS})
2019-07-16 20:19:11 -06:00
add_library(dfhack-version STATIC ${VERSION_SRCS})
set_property(TARGET dfhack-version APPEND PROPERTY COMPILE_DEFINITIONS
DFHACK_VERSION="${DFHACK_VERSION}"
DF_VERSION="${DF_VERSION}"
DFHACK_RELEASE="${DFHACK_RELEASE}"
2018-03-10 14:55:00 -07:00
DFHACK_ABI_VERSION=${DFHACK_ABI_VERSION}
)
2019-07-16 20:19:11 -06:00
if(DFHACK_PRERELEASE)
set_property(TARGET dfhack-version APPEND PROPERTY COMPILE_DEFINITIONS
DFHACK_PRERELEASE=1
)
2019-07-16 20:19:11 -06:00
endif()
configure_file(git-describe.cmake.in ${CMAKE_CURRENT_SOURCE_DIR}/git-describe.cmake @ONLY)
if(EXISTS ${dfhack_SOURCE_DIR}/.git/index AND EXISTS ${dfhack_SOURCE_DIR}/.git/modules/library/xml/index)
2019-07-16 20:19:11 -06:00
add_custom_command(OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/include/git-describe.h
COMMAND ${CMAKE_COMMAND}
-D dfhack_SOURCE_DIR:STRING=${dfhack_SOURCE_DIR}
-D GIT_EXECUTABLE:STRING=${GIT_EXECUTABLE}
-P ${CMAKE_CURRENT_SOURCE_DIR}/git-describe.cmake
COMMENT "Obtaining git commit information"
DEPENDS ${dfhack_SOURCE_DIR}/.git/index
${dfhack_SOURCE_DIR}/.git/modules/library/xml/index
2019-07-16 20:19:11 -06:00
${CMAKE_CURRENT_SOURCE_DIR}/git-describe.cmake
include/git-describe.h.in
)
2019-07-16 20:19:11 -06:00
endif()
2019-07-16 20:19:11 -06:00
add_library(dfhack SHARED ${PROJECT_SOURCES})
add_dependencies(dfhack generate_proto_core)
add_dependencies(dfhack generate_headers)
2009-10-23 12:05:42 -06:00
add_library(dfhack-client SHARED RemoteClient.cpp ColorText.cpp MiscUtils.cpp Error.cpp ${PROJECT_PROTO_SRCS} ${CONSOLE_SOURCES})
2019-07-16 20:19:11 -06:00
add_dependencies(dfhack-client dfhack)
2019-07-16 20:19:11 -06:00
add_executable(dfhack-run dfhack-run.cpp)
2019-07-16 20:19:11 -06:00
add_executable(binpatch binpatch.cpp)
target_link_libraries(binpatch dfhack-md5)
2019-07-16 20:19:11 -06:00
if(WIN32)
# name the resulting library SDL.dll on Windows
set_target_properties(dfhack PROPERTIES OUTPUT_NAME "SDL" )
2019-07-16 20:19:11 -06:00
set_target_properties(dfhack PROPERTIES COMPILE_FLAGS "/FI\"Export.h\"" )
set_target_properties(dfhack-client PROPERTIES COMPILE_FLAGS "/FI\"Export.h\"" )
else()
set_target_properties(dfhack PROPERTIES COMPILE_FLAGS "-include Export.h" )
set_target_properties(dfhack-client PROPERTIES COMPILE_FLAGS "-include Export.h" )
endif()
# effectively disables debug builds...
set_target_properties(dfhack PROPERTIES DEBUG_POSTFIX "-debug" )
if(APPLE)
set(DF_SDL_LIBRARY ${CMAKE_INSTALL_PREFIX}/libs/SDL.framework/Versions/A/SDL)
if(NOT EXISTS ${DF_SDL_LIBRARY})
message(SEND_ERROR "SDL framework not found. Make sure CMAKE_INSTALL_PREFIX is specified and correct.")
endif()
set(SDL_LIBRARY ${CMAKE_BINARY_DIR}/SDL)
execute_process(COMMAND ${CMAKE_COMMAND} -E copy_if_different ${DF_SDL_LIBRARY} ${SDL_LIBRARY})
set(CXX_LIBRARY ${CMAKE_INSTALL_PREFIX}/libs/libstdc++.6.dylib)
set(ZIP_LIBRARY /usr/lib/libz.dylib)
target_link_libraries(dfhack ${SDL_LIBRARY})
target_link_libraries(dfhack ${CXX_LIBRARY})
if(EXISTS ${ZIP_LIBRARY})
# doesn't exist on macOS 11, but DFHack seems to find the right library there
target_link_libraries(dfhack ${ZIP_LIBRARY})
endif()
2019-07-16 20:19:11 -06:00
target_link_libraries(dfhack ncurses)
set_target_properties(dfhack PROPERTIES VERSION 1.0.0)
set_target_properties(dfhack PROPERTIES SOVERSION 1.0.0)
2012-02-27 19:37:56 -07:00
endif()
2011-06-19 20:29:38 -06:00
target_link_libraries(dfhack protobuf-lite clsocket lua jsoncpp_static dfhack-version ${PROJECT_LIBS})
2019-07-16 20:19:11 -06:00
set_target_properties(dfhack PROPERTIES INTERFACE_LINK_LIBRARIES "")
target_link_libraries(dfhack-client protobuf-lite clsocket jsoncpp_static)
2019-07-16 20:19:11 -06:00
target_link_libraries(dfhack-run dfhack-client)
2012-09-13 12:58:52 -06:00
if(APPLE)
2012-11-16 14:33:36 -07:00
add_custom_command(TARGET dfhack-run COMMAND ${dfhack_SOURCE_DIR}/package/darwin/fix-libs.sh WORKING_DIRECTORY ../ COMMENT "Fixing library dependencies...")
2012-09-13 12:58:52 -06:00
endif()
2019-07-16 20:19:11 -06:00
if(UNIX)
if(APPLE)
2012-11-16 14:33:36 -07:00
install(PROGRAMS ${dfhack_SOURCE_DIR}/package/darwin/dfhack
2019-07-16 20:19:11 -06:00
DESTINATION .)
2012-11-16 14:33:36 -07:00
install(PROGRAMS ${dfhack_SOURCE_DIR}/package/darwin/dfhack-run
2019-07-16 20:19:11 -06:00
DESTINATION .)
2012-05-29 14:12:35 -06:00
else()
2012-11-16 14:33:36 -07:00
# On linux, copy our version of the df launch script which sets LD_PRELOAD
install(PROGRAMS ${dfhack_SOURCE_DIR}/package/linux/dfhack
DESTINATION .)
2012-11-16 14:33:36 -07:00
install(PROGRAMS ${dfhack_SOURCE_DIR}/package/linux/dfhack-run
DESTINATION .)
2012-05-29 14:12:35 -06:00
endif()
2019-07-16 20:19:11 -06:00
else()
# On windows, copy the renamed SDL so DF can still run.
install(PROGRAMS ${dfhack_SOURCE_DIR}/package/windows/win${DFHACK_BUILD_ARCH}/SDLreal.dll
DESTINATION ${DFHACK_LIBRARY_DESTINATION})
2019-07-16 20:19:11 -06:00
endif()
2019-07-16 20:19:11 -06:00
# install the main lib
install(TARGETS dfhack
LIBRARY DESTINATION ${DFHACK_LIBRARY_DESTINATION}
RUNTIME DESTINATION ${DFHACK_LIBRARY_DESTINATION})
2019-07-16 20:19:11 -06:00
# install the offset file
2012-02-11 11:24:44 -07:00
install(FILES xml/symbols.xml
2019-07-16 20:19:11 -06:00
DESTINATION ${DFHACK_DATA_DESTINATION})
install(TARGETS dfhack-run dfhack-client binpatch
2019-07-16 20:19:11 -06:00
LIBRARY DESTINATION ${DFHACK_LIBRARY_DESTINATION}
RUNTIME DESTINATION ${DFHACK_LIBRARY_DESTINATION})
install(DIRECTORY lua/
2019-07-16 20:19:11 -06:00
DESTINATION ${DFHACK_LUA_DESTINATION}
FILES_MATCHING PATTERN "*.lua")
install(DIRECTORY ${dfhack_SOURCE_DIR}/patches
2019-07-16 20:19:11 -06:00
DESTINATION ${DFHACK_DATA_DESTINATION}
FILES_MATCHING PATTERN "*.dif")
2012-02-27 19:37:56 -07:00
# Unused for so long that it's not even relevant now...
if(BUILD_DEVEL)
if(WIN32)
install(TARGETS dfhack
2019-07-16 20:19:11 -06:00
ARCHIVE DESTINATION ${DFHACK_DEVLIB_DESTINATION})
endif()
# note the ending '/'. This means *contents* of the directory are installed
2011-03-20 10:24:34 -06:00
# without the '/', the directory itself is installed
install(DIRECTORY include/
2019-07-16 20:19:11 -06:00
DESTINATION ${DFHACK_INCLUDES_DESTINATION}
FILES_MATCHING PATTERN "*.h" PATTERN "*.inc" )
2011-03-17 17:07:40 -06:00
endif()
2020-12-29 21:47:44 -07:00
add_subdirectory(xml)