Skip to content

Commit 2911b20

Browse files
committed
DFHack. Now with more packaging fun.
1 parent 557d673 commit 2911b20

File tree

3 files changed

+73
-48
lines changed

3 files changed

+73
-48
lines changed

CMakeLists.txt

Lines changed: 57 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,27 +11,62 @@ SET(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/CMake/Modules)
1111
SET(CMAKE_SOURCE_DIR ${PROJECT_SOURCE_DIR})
1212

1313
if("${CMAKE_SOURCE_DIR}" STREQUAL "${CMAKE_BINARY_DIR}")
14-
message(SEND_ERROR "In-source builds are not allowed.")
14+
message(FATAL_ERROR "In-source builds are not allowed.")
1515
endif()
1616

17-
## version - only set this for actual releases
18-
SET (DFHACK_VERSION "dev" CACHE STRING "Version number of dfhack. Set to 'dev' by default. Only set for releases." )
17+
set(DEVEL_RELEASE "-dev")
18+
set(CPACK_PACKAGE_VERSION_MAJOR "0")
19+
set(CPACK_PACKAGE_VERSION_MINOR "5")
20+
set(CPACK_PACKAGE_VERSION_PATCH "8")
21+
set(DFHACK_VERSION "${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}.${CPACK_PACKAGE_VERSION_PATCH}${DEVEL_RELEASE}")
22+
set(CPACK_PACKAGE_NAME "dfhack")
1923

2024
## setting the build type
2125
IF(NOT DEFINED CMAKE_BUILD_TYPE)
2226
SET(CMAKE_BUILD_TYPE "Release" CACHE STRING "Choose the type of build, options are: Debug Release RelWithDebInfo MinSizeRel.")
2327
ENDIF()
2428

25-
## put everything in one big ugly directory to make MSVC and KDevelop happy
29+
## put everything in one big ugly directory to make MSVC and KDevelop debuggers happy
2630
SET(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin")
2731
SET(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin")
2832
SET(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin")
2933

34+
SET(DFHACK_INSTALL "portable" CACHE STRING "Choose the install type: 'portable' for a portable zip or tar.gz package, 'linux' for packaging and system installs on linux, 'none' for no install target (default).")
35+
SET( MEMXML_DATA_PATH . CACHE PATH "Path to a valid Memory.xml file. This is baked into the library, so when you package DFHack for linux, set it to the right path.")
36+
37+
IF(${DFHACK_INSTALL} STREQUAL "portable")
38+
# the dfhack libraries will be installed here:
39+
SET(DFHACK_LIBRARY_DESTINATION .)
40+
# the dfhack tools will be installed here:
41+
SET(DFHACK_BINARY_DESTINATION .)
42+
# Memory.xml goes here:
43+
SET(DFHACK_DATA_DESTINATION .)
44+
# Includes go here:
45+
SET(DFHACK_INCLUDES_DESTINATION dev/include)
46+
# the Windows .lib files go here:
47+
IF(WIN32)
48+
SET(DFHACK_DEVLIB_DESTINATION dev)
49+
SET(CMAKE_INSTALL_SYSTEM_RUNTIME_DESTINATION .)
50+
ENDIF()
51+
ENDIF()
52+
53+
IF(${DFHACK_INSTALL} STREQUAL "linux")
54+
# the dfhack libraries will be installed here:
55+
SET(DFHACK_LIBRARY_DESTINATION lib)
56+
# the dfhack tools will be installed here:
57+
SET(DFHACK_BINARY_DESTINATION bin)
58+
# Memory.xml goes here:
59+
SET(DFHACK_DATA_DESTINATION share/dfhack)
60+
# Includes go here:
61+
SET(DFHACK_INCLUDES_DESTINATION include)
62+
ENDIF()
63+
64+
## some options for the user/developer to play with
65+
OPTION(BUILD_DFHACK_SUPPORTED "Build the supported tools." ON)
66+
OPTION(BUILD_DFHACK_C_BINDINGS "Build the C portion of the library" ON)
3067
OPTION(BUILD_DFHACK_DOXYGEN "Create doxygen documentation for developers" ON)
3168
OPTION(BUILD_DFHACK_EXAMPLES "Build example tools" OFF)
3269
OPTION(BUILD_DFHACK_PLAYGROUND "Build tools from the playground folder" OFF)
33-
OPTION(BUILD_DFHACK_C_BINDINGS "Build the C portion of the library" ON)
34-
OPTION(BUILD_DFHACK_SUPPORTED "Build the supported toold." ON)
3570

3671
include_directories (${CMAKE_SOURCE_DIR}/library/include/)
3772
include_directories (${CMAKE_SOURCE_DIR}/library/shm/)
@@ -40,6 +75,8 @@ include_directories (${CMAKE_SOURCE_DIR}/library/depends/argstream/)
4075
add_subdirectory (library)
4176

4277
# macro to save on typing in the tool subdirs
78+
# builds a tool, links it to the dfhack lib and makes sure the dependency
79+
# LOCAL_DEPNAME is built first, in case there is one
4380
MACRO(DFHACK_TOOL TOOL_NAME TOOL_SOURCES)
4481
ADD_EXECUTABLE(${TOOL_NAME} ${TOOL_SOURCES})
4582
TARGET_LINK_LIBRARIES(${TOOL_NAME} dfhack)
@@ -48,7 +85,7 @@ MACRO(DFHACK_TOOL TOOL_NAME TOOL_SOURCES)
4885
endif()
4986
install(TARGETS
5087
${TOOL_NAME}
51-
RUNTIME DESTINATION bin)
88+
RUNTIME DESTINATION ${DFHACK_BINARY_DESTINATION})
5289
ENDMACRO()
5390

5491
IF(BUILD_DFHACK_SUPPORTED)
@@ -66,3 +103,16 @@ ENDIF()
66103
IF(BUILD_DFHACK_DOXYGEN)
67104
add_subdirectory (doc)
68105
ENDIF()
106+
107+
IF(${DFHACK_INSTALL} STREQUAL "portable")
108+
IF(UNIX)
109+
SET(CPACK_GENERATOR "TGZ")
110+
ENDIF()
111+
IF(WIN32)
112+
SET(CPACK_GENERATOR "ZIP")
113+
# this includes the MSVC C++ DLLs in the package. Doesn't work with Express versions in general.
114+
INCLUDE(InstallRequiredSystemLibraries)
115+
ENDIF()
116+
set(CPACK_PACKAGE_FILE_NAME "${CPACK_PACKAGE_NAME}-${DFHACK_VERSION}-${CMAKE_SYSTEM_NAME}-${CMAKE_SYSTEM_PROCESSOR}")
117+
INCLUDE(CPack)
118+
ENDIF()

library/CMakeLists.txt

Lines changed: 14 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ cmake_minimum_required(VERSION 2.8)
44
SET(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/CMake/Modules)
55

66
if("${CMAKE_SOURCE_DIR}" STREQUAL "${CMAKE_BINARY_DIR}")
7-
message(SEND_ERROR "In-source builds are not allowed.")
7+
message(FATAL_ERROR "In-source builds are not allowed.")
88
endif()
99

1010
IF(NOT DEFINED CMAKE_BUILD_TYPE)
@@ -165,8 +165,6 @@ SET_SOURCE_FILES_PROPERTIES( ${PROJECT_HDRS} PROPERTIES HEADER_FILE_ONLY TRUE )
165165

166166
LIST(APPEND PROJECT_SRCS ${PROJECT_HDRS})
167167

168-
SET( MEMXML_DATA_PATH . CACHE PATH "search path for Memory.xml")
169-
170168
# Are we 64bit? (Damn you, ptrace()!)
171169
IF( CMAKE_SIZEOF_VOID_P MATCHES 4 )
172170
SET( HAVE_64_BIT 0 )
@@ -185,7 +183,7 @@ IF(UNIX)
185183
SET(CMAKE_CXX_FLAGS_DEBUG "-g -Wall")
186184
SET(CMAKE_CXX_FLAGS "-fvisibility=hidden")
187185

188-
SET(PROJECT_LIBS ${X11_LIBRARY} rt ) #dfhack-md5 dfhack-tixml
186+
SET(PROJECT_LIBS ${X11_LIBRARY} rt )
189187
ELSE()
190188
IF(MSVC)
191189
SET(PROJECT_LIBS psapi ${CMAKE_SOURCE_DIR}/library/depends/ntdll/ntdll.lib)
@@ -203,38 +201,15 @@ TARGET_LINK_LIBRARIES(dfhack ${PROJECT_LIBS})
203201
ADD_CUSTOM_COMMAND( TARGET dfhack POST_BUILD
204202
COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_SOURCE_DIR}/Memory.xml ${CMAKE_BINARY_DIR}/bin/${CMAKE_CFG_INTDIR}/)
205203

206-
#if(MSVC)
207-
# This is a MSVC hack used for copying files into the target directory
208-
# of build target set in MSVC.
209-
# It exploits the fact that MSVC has some variables in .vcproj files, much like cmake does here.
210-
#
211-
# So, $(TargetDir) is ignored by cmake, and replaced with the actual output directory by MSVC
212-
#ADD_CUSTOM_COMMAND(TARGET dfhack
213-
#COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_SOURCE_DIR}/data/Memory-ng.xml "$(TargetDir)/Memory.xml"
214-
#MAIN_DEPENDENCY ${CMAKE_SOURCE_DIR}/data/Memory-ng.xml
215-
#)
216-
#ADD_CUSTOM_COMMAND(TARGET dfhack
217-
#COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_SOURCE_DIR}/Compile.html "$(TargetDir)/Compile.html"
218-
#MAIN_DEPENDENCY ${CMAKE_SOURCE_DIR}/Compile.html
219-
#)
220-
#ADD_CUSTOM_COMMAND(TARGET dfhack
221-
#COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_SOURCE_DIR}/Readme.html "$(TargetDir)/Readme.html"
222-
#MAIN_DEPENDENCY ${CMAKE_SOURCE_DIR}/Readme.html
223-
#)
224-
#ADD_CUSTOM_COMMAND(TARGET dfhack
225-
#COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_SOURCE_DIR}/LICENSE "$(TargetDir)/LICENSE.txt"
226-
#MAIN_DEPENDENCY ${CMAKE_SOURCE_DIR}/LICENSE
227-
#)
228-
#else(MSVC)
229-
# Just put the file in the output directory on Linux and Mac
230-
#configure_file(${CMAKE_SOURCE_DIR}/data/Memory-ng.xml ${DATA_OUTPUT_PATH}/Memory.xml COPYONLY)
231-
#configure_file(${CMAKE_SOURCE_DIR}/Compile.html ${DATA_OUTPUT_PATH}/Compile.html COPYONLY)
232-
#configure_file(${CMAKE_SOURCE_DIR}/Readme.html ${DATA_OUTPUT_PATH}/Readme.html COPYONLY)
233-
#configure_file(${CMAKE_SOURCE_DIR}/LICENSE ${DATA_OUTPUT_PATH}/LICENSE.txt COPYONLY)
234-
#endif(MSVC)
235-
236-
#IF(UNIX)
237-
# install(TARGETS dfhack LIBRARY DESTINATION lib)
238-
# install(FILES ${CMAKE_SOURCE_DIR}/output/Memory.xml DESTINATION share/dfhack)
239-
# install(DIRECTORY ${CMAKE_SOURCE_DIR}/library/include/ DESTINATION include FILES_MATCHING PATTERN "*.h")
240-
#ENDIF(UNIX)
204+
install(TARGETS dfhack
205+
LIBRARY DESTINATION ${DFHACK_LIBRARY_DESTINATION}
206+
RUNTIME DESTINATION ${DFHACK_LIBRARY_DESTINATION}) #linux: lib
207+
install(FILES ${CMAKE_SOURCE_DIR}/Memory.xml
208+
DESTINATION ${DFHACK_DATA_DESTINATION}) #linux: share/dfhack
209+
if(WIN32)
210+
install(TARGETS dfhack
211+
ARCHIVE DESTINATION ${DFHACK_DEVLIB_DESTINATION})
212+
endif()
213+
install(DIRECTORY ${CMAKE_SOURCE_DIR}/library/include/
214+
DESTINATION ${DFHACK_INCLUDES_DESTINATION}
215+
FILES_MATCHING PATTERN "*.h" ) #linux: include

tools/supported/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,10 +98,10 @@ IF(UNIX)
9898
TARGET_LINK_LIBRARIES(dfveinlook dfhack ${CURSES_LIBRARIES})
9999
install(TARGETS
100100
dfveinlook
101-
RUNTIME DESTINATION bin
101+
RUNTIME DESTINATION ${DFHACK_BINARY_DESTINATION}
102102
)
103103
ENDIF(NCURSES_H)
104104
ELSE(CURSES_FOUND)
105105
MESSAGE(STATUS "Wide-character ncurses library not found - veinlook can't be built")
106106
ENDIF(CURSES_FOUND)
107-
ENDIF(UNIX)
107+
ENDIF(UNIX)

0 commit comments

Comments
 (0)