dfhack/CMakeLists.txt

265 lines
8.4 KiB
CMake

2009-09-13 18:02:46 -06:00
# main project file. use it from a build sub-folder, see COMPILE for details
# prevent CMake warnings about INTERFACE_LINK_LIBRARIES vs LINK_INTERFACE_LIBRARIES
IF(CMAKE_VERSION VERSION_GREATER "2.8.12")
CMAKE_POLICY(SET CMP0022 OLD)
ENDIF()
# Set up build types
if(CMAKE_CONFIGURATION_TYPES)
SET(CMAKE_CONFIGURATION_TYPES Release RelWithDebInfo)
SET(CMAKE_CONFIGURATION_TYPES "${CMAKE_CONFIGURATION_TYPES}" CACHE STRING "List of supported configuration types" FORCE)
else(CMAKE_CONFIGURATION_TYPES)
if (NOT CMAKE_BUILD_TYPE)
SET(CMAKE_BUILD_TYPE "Release" CACHE STRING "Choose the type of build, options are: Release RelWithDebInfo.")
endif (NOT CMAKE_BUILD_TYPE)
endif(CMAKE_CONFIGURATION_TYPES)
2015-09-27 02:53:18 -06:00
OPTION(BUILD_DOCS "Choose whether to build the documentation (requires python and Sphinx)." ON)
2015-09-24 00:04:09 -06:00
2012-03-13 14:16:30 -06:00
## some generic CMake magic
cmake_minimum_required(VERSION 2.8 FATAL_ERROR)
project(dfhack)
macro(CHECK_GCC COMPILER_PATH)
execute_process(COMMAND ${COMPILER_PATH} -dumpversion OUTPUT_VARIABLE GCC_VERSION_OUT)
string(STRIP "${GCC_VERSION_OUT}" GCC_VERSION_OUT)
if (${GCC_VERSION_OUT} VERSION_LESS "4.5" OR ${GCC_VERSION_OUT} VERSION_GREATER "4.9.9")
message(SEND_ERROR "${COMPILER_PATH} version ${GCC_VERSION_OUT} cannot be used - use GCC 4.5 through 4.9")
endif()
endmacro()
if(UNIX)
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()
endif()
if(WIN32)
2015-10-13 14:25:38 -06:00
if((NOT MSVC) OR (NOT MSVC_VERSION STREQUAL 1600))
message(SEND_ERROR "MSVC 2010 is required")
endif()
endif()
2012-04-14 16:27:02 -06:00
if(MSVC)
# disable C4819 code-page warning
add_definitions( "/wd4819" )
2012-04-14 16:27:02 -06:00
endif()
# set up folder structures for IDE solutions
# MSVC Express won't load solutions that use this. It also doesn't include MFC supported
# Check for MFC!
find_package(MFC QUIET)
if(MFC_FOUND OR (NOT MSVC))
OPTION(CMAKE_USE_FOLDERS "Enable folder grouping of projects in IDEs." ON)
else()
OPTION(CMAKE_USE_FOLDERS "Enable folder grouping of projects in IDEs." OFF)
endif()
2012-03-13 14:05:25 -06:00
if(CMAKE_USE_FOLDERS)
SET_PROPERTY(GLOBAL PROPERTY USE_FOLDERS ON)
else()
SET_PROPERTY(GLOBAL PROPERTY USE_FOLDERS OFF)
endif()
# macro for setting up IDE folders without nasty IF()s everywhere
MACRO(IDE_FOLDER target folder)
if(CMAKE_USE_FOLDERS)
SET_PROPERTY(TARGET ${target} PROPERTY FOLDER ${folder})
endif()
ENDMACRO()
2011-03-20 10:17:33 -06:00
SET(CMAKE_MODULE_PATH
${dfhack_SOURCE_DIR}/CMake/Modules
${CMAKE_MODULE_PATH}
)
# mixing the build system with the source code is ugly and stupid. enforce the opposite :)
if("${CMAKE_SOURCE_DIR}" STREQUAL "${CMAKE_BINARY_DIR}")
2011-03-17 17:07:40 -06:00
message(FATAL_ERROR "In-source builds are not allowed.")
endif()
2009-09-13 18:02:46 -06:00
# make sure all the necessary submodules have been set up
2015-07-29 12:47:55 -06:00
if (NOT EXISTS ${dfhack_SOURCE_DIR}/library/xml/codegen.pl OR NOT EXISTS ${dfhack_SOURCE_DIR}/depends/clsocket/CMakeLists.txt)
2015-09-26 08:51:02 -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 Compile.rst or Compile.html)")
endif()
# set up versioning.
set(DF_VERSION "0.40.24")
2015-03-30 10:38:56 -06:00
SET(DFHACK_RELEASE "r3")
set(DFHACK_VERSION "${DF_VERSION}-${DFHACK_RELEASE}")
## where to install things (after the build is done, classic 'make install' or package structure)
# the dfhack libraries will be installed here:
IF(UNIX)
# put the lib into DF/hack
SET(DFHACK_LIBRARY_DESTINATION hack)
2012-02-27 19:37:56 -07:00
SET(DFHACK_EGGY_DESTINATION libs)
ELSE()
# windows is crap, therefore we can't do nice things with it. leave the libs on a nasty pile...
SET(DFHACK_LIBRARY_DESTINATION .)
2012-02-27 19:37:56 -07:00
SET(DFHACK_EGGY_DESTINATION .)
ENDIF()
# external tools will be installed here:
SET(DFHACK_BINARY_DESTINATION .)
# dfhack data goes here:
SET(DFHACK_DATA_DESTINATION hack)
# plugin libs go here:
SET(DFHACK_PLUGIN_DESTINATION hack/plugins)
# dfhack header files go here:
SET(DFHACK_INCLUDES_DESTINATION hack/include)
# dfhack lua files go here:
SET(DFHACK_LUA_DESTINATION hack/lua)
# the windows .lib file goes here:
SET(DFHACK_DEVLIB_DESTINATION hack)
# user documentation goes here:
SET(DFHACK_USERDOC_DESTINATION hack)
# developer documentation goes here:
SET(DFHACK_DEVDOC_DESTINATION hack)
2011-05-21 12:32:53 -06:00
## some options for the user/developer to play with
OPTION(BUILD_LIBRARY "Build the library that goes into DF." ON)
OPTION(BUILD_PLUGINS "Build the plugins." ON)
IF(UNIX)
2015-09-26 11:16:05 -06:00
## flags for GCC
# default to hidden symbols
# build 32bit
# ensure compatibility with older CPUs
# enable C++11 features
add_definitions(-DLINUX_BUILD)
SET(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} -g -Wall -Wno-unused-variable")
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fvisibility=hidden -m32 -march=i686 -mtune=generic -std=c++0x")
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fvisibility=hidden -m32 -march=i686 -mtune=generic")
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")
ENDIF()
# use shared libraries for protobuf
ADD_DEFINITIONS(-DPROTOBUF_USE_DLLS)
ADD_DEFINITIONS(-DLUA_BUILD_AS_DLL)
if(APPLE)
2012-11-16 14:33:36 -07:00
add_definitions(-D_DARWIN)
set(CMAKE_MACOSX_RPATH 1)
elseif(UNIX)
add_definitions(-D_LINUX)
elseif(WIN32)
add_definitions(-DWIN32)
endif()
#### expose depends ####
# find and make available libz
if(NOT UNIX)
SET(ZLIB_ROOT depends/zlib/)
endif()
find_package(ZLIB REQUIRED)
include_directories(depends/protobuf)
include_directories(depends/lua/include)
include_directories(depends/md5)
2015-07-29 12:47:55 -06:00
include_directories(depends/jsoncpp)
include_directories(depends/tinyxml)
include_directories(depends/tthread)
include_directories(${ZLIB_INCLUDE_DIRS})
include_directories(depends/clsocket/src)
add_subdirectory(depends)
2015-06-25 09:43:54 -06:00
find_package(Git)
if(NOT GIT_FOUND)
message(FATAL_ERROR "could not find git")
endif()
# build the lib itself
IF(BUILD_LIBRARY)
add_subdirectory (library)
install(FILES LICENSE.rst NEWS.rst DESTINATION ${DFHACK_USERDOC_DESTINATION})
endif()
install(DIRECTORY dfhack-config/ DESTINATION dfhack-config/default)
#build the plugins
2011-06-19 20:29:38 -06:00
IF(BUILD_PLUGINS)
add_subdirectory (plugins)
endif()
2011-03-17 17:07:40 -06:00
add_subdirectory(scripts)
2015-09-24 00:04:09 -06:00
find_package(Sphinx)
if (BUILD_DOCS)
2015-09-26 11:28:06 -06:00
if (NOT SPHINX_FOUND)
message(SEND_ERROR "Sphinx not found but BUILD_DOCS enabled")
endif()
2015-09-26 15:52:06 -06:00
file(GLOB SPHINX_DEPS
"${CMAKE_CURRENT_SOURCE_DIR}/docs/*.rst"
"${CMAKE_CURRENT_SOURCE_DIR}/docs/images/*.png"
"${CMAKE_CURRENT_SOURCE_DIR}/docs/styles/*"
"${CMAKE_CURRENT_SOURCE_DIR}/docs/conf.py"
"${CMAKE_CURRENT_SOURCE_DIR}/scripts/about.txt"
"${CMAKE_CURRENT_SOURCE_DIR}/scripts/*/about.txt"
)
file(GLOB_RECURSE SPHINX_SCRIPT_DEPS
"${CMAKE_CURRENT_SOURCE_DIR}/scripts/*.lua"
"${CMAKE_CURRENT_SOURCE_DIR}/scripts/*.rb"
2015-09-26 15:52:06 -06:00
)
set(SPHINX_DEPS ${SPHINX_DEPS} ${SPHINX_SCRIPT_DEPS} LICENSE.rst NEWS.rst index.rst)
2015-09-26 15:52:06 -06:00
set(SPHINX_OUTPUT "${CMAKE_CURRENT_SOURCE_DIR}/docs/html/.buildinfo")
set_source_files_properties(${SPHINX_OUTPUT} PROPERTIES GENERATED TRUE)
add_custom_command(OUTPUT ${SPHINX_OUTPUT}
COMMAND ${SPHINX_EXECUTABLE}
-a -E -q -b html
2015-09-26 11:28:06 -06:00
"${CMAKE_CURRENT_SOURCE_DIR}"
"${CMAKE_CURRENT_SOURCE_DIR}/docs/html"
-w "${CMAKE_CURRENT_SOURCE_DIR}/docs/_sphinx-warnings.txt"
2015-09-26 15:52:06 -06:00
DEPENDS ${SPHINX_DEPS}
COMMENT "Building HTML documentation with Sphinx"
)
add_custom_target(dfhack_docs ALL
DEPENDS ${SPHINX_OUTPUT}
)
# 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
COMMAND ${CMAKE_COMMAND} -E touch ${SPHINX_OUTPUT})
install(DIRECTORY ${dfhack_SOURCE_DIR}/docs
2015-09-26 15:52:06 -06:00
DESTINATION ${DFHACK_USERDOC_DESTINATION}
)
install(FILES "README.html" DESTINATION "${DFHACK_DATA_DESTINATION}")
2015-09-24 00:04:09 -06:00
endif()
# Packaging with CPack!
IF(UNIX)
2012-11-16 14:33:36 -07:00
if(APPLE)
2015-09-26 11:16:05 -06:00
SET(CPACK_GENERATOR "ZIP;TBZ2")
2012-11-16 14:33:36 -07:00
else()
SET(CPACK_GENERATOR "TBZ2")
2012-11-16 14:33:36 -07:00
endif()
ELSEIF(WIN32)
SET(CPACK_GENERATOR "ZIP")
ENDIF()
set(CPACK_INCLUDE_TOPLEVEL_DIRECTORY 0)
IF(APPLE)
set(DFHACK_PACKAGE_PLATFORM_NAME OSX)
ELSE()
set(DFHACK_PACKAGE_PLATFORM_NAME ${CMAKE_SYSTEM_NAME})
ENDIF()
set(CPACK_PACKAGE_FILE_NAME "dfhack-${DFHACK_VERSION}-${DFHACK_PACKAGE_PLATFORM_NAME}")
INCLUDE(CPack)
2015-09-24 00:04:09 -06:00
#INCLUDE(FindSphinx.cmake)