Use GNUInstallDirs to specify directories

* GNUInstallDirs is the only Kitware-supported
  way to change the default directories. Most
  distributions have hooks for changing these
  directories, which makes integrating wesnoth
  easier and more consistent with the rest of
  the CMake ecosystem.
* Make build system perfectly out-of-source
  compatible. The build system should never
  touch files in the source tree.
This commit is contained in:
David Seifert 2017-11-17 17:28:52 +01:00 committed by Jyrki Vesterinen
parent 7d910ab075
commit 0e57d0840a
6 changed files with 40 additions and 46 deletions

View file

@ -7,7 +7,9 @@
# * install .desktop files taking binary prefix and suffix into account
# set minimum version
cmake_minimum_required(VERSION 2.6.0)
cmake_minimum_required(VERSION 2.8.5)
project(wesnoth)
include(CheckCXXCompilerFlag)
@ -20,14 +22,12 @@ list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake")
# Options
#
# Adhere to GNU filesystem layout conventions
include(GNUInstallDirs)
#Path options
set(BINDIR "bin" CACHE STRING "Where to install binaries")
set(DATAROOTDIR "${CMAKE_INSTALL_PREFIX}/share" CACHE STRING "Sets the root of data directories to a non-default location")
set(DOCDIR "${DATAROOTDIR}/doc/wesnoth" CACHE STRING "Sets the doc directory to a non-default location.")
set(MANDIR "${DATAROOTDIR}/man" CACHE STRING "Where to install manpages")
set(DATADIRNAME "wesnoth" CACHE STRING "change the name of the directory for the read-only architecture-independent game data")
set(EXECUTABLE_OUTPUT_PATH "${CMAKE_BINARY_DIR}" CACHE STRING "change the dir where binaries are placed right at compile time")
set(LOCALEDIR "translations" CACHE STRING "change the name of the locale data directory to a non-default name")
set(PREFERENCES_DIR "" CACHE STRING "Use a non-default preferences directory (.wesnoth on unix)")
set(DEFAULT_PREFS_FILE "" CACHE STRING "Set system wide preferences file")
@ -150,8 +150,6 @@ mark_as_advanced(on ENABLE_SHARED_LIBRARIES)
if(UNIX AND NOT APPLE AND NOT CYGWIN)
option(ENABLE_DESKTOP_ENTRY "enable installation of desktop entry files" ON)
set(ICONDIR "${DATAROOTDIR}/pixmaps" CACHE STRING "Sets the icon directory for desktop entry to a non-default location.")
set(DESKTOPDIR "${DATAROOTDIR}/applications/" CACHE STRING "Sets the desktop file directory for desktop entry to a non-default location.")
endif(UNIX AND NOT APPLE AND NOT CYGWIN)
option(ENABLE_STRICT_COMPILATION "Sets the strict compilation mode" OFF)
@ -477,19 +475,14 @@ if(UNIX AND NOT CMAKE_COMPILER_IS_GNUCXX)
set(CMAKE_EXE_LINKER_FLAGS "-lstdc++ -lm ${CMAKE_EXE_LINKER_FLAGS}")
endif(UNIX AND NOT CMAKE_COMPILER_IS_GNUCXX)
# compose datadir path of datarootdir and datadirname
set(DATADIR ${DATAROOTDIR}/${DATADIRNAME})
if(NOT WIN32)
add_definitions(-DWESNOTH_PATH="${DATADIR}")
add_definitions(-DWESNOTH_PATH="${CMAKE_INSTALL_FULL_DATADIR}/${DATADIRNAME}")
endif(NOT WIN32)
if(X11_FOUND)
add_definitions(-D_X11)
endif(X11_FOUND)
add_definitions(-DLOCALEDIR="${LOCALEDIR}")
# -NDEBUG is automatically added to all release build types, so manually remove
# this define from the related variables
MESSAGE ("removing NDEBUG flag from CMAKE_CXX_FLAGS_RELWITHDEBINFO")
@ -666,15 +659,16 @@ endif()
# End setting options for Profile build
# #
# When the path starts with a / on a Unix system it's an absolute path.
# This means that on Windows the path used is always relative.
if(LOCALEDIR MATCHES "^/")
add_definitions(-DHAS_RELATIVE_LOCALEDIR=0)
set(LOCALE_INSTALL ${LOCALEDIR})
else(LOCALEDIR MATCHES "^/")
# On Windows the path used is always relative.
if(WIN32)
add_definitions(-DHAS_RELATIVE_LOCALEDIR=1)
set(LOCALE_INSTALL ${DATADIR}/${LOCALEDIR})
endif(LOCALEDIR MATCHES "^/")
file(RELATIVE_PATH LOCALEDIR "${CMAKE_INSTALL_FULL_BINDIR}" "${CMAKE_INSTALL_FULL_LOCALEDIR}")
else(WIN32)
add_definitions(-DHAS_RELATIVE_LOCALEDIR=0)
set(LOCALEDIR "${CMAKE_INSTALL_FULL_LOCALEDIR}")
endif(WIN32)
add_definitions(-DLOCALEDIR="${LOCALEDIR}")
add_definitions(-DFIFODIR="${FIFO_DIR}")
@ -792,7 +786,7 @@ add_subdirectory(src)
#
# Install files
#
install(DIRECTORY data fonts images sounds DESTINATION ${DATADIR} USE_SOURCE_PERMISSIONS PATTERN ".git" EXCLUDE )
install(DIRECTORY data fonts images sounds DESTINATION ${CMAKE_INSTALL_DATADIR}/${DATADIRNAME} USE_SOURCE_PERMISSIONS PATTERN ".git" EXCLUDE )
#
@ -809,9 +803,9 @@ if(ENABLE_DESKTOP_ENTRY AND ENABLE_GAME)
#execute_process(COMMAND sed "-i" "'s/^\(Name.*=.*\)$/\1TEST/g'" ${CMAKE_CURRENT_BINARY_DIR}/${BINARY_PREFIX}wesnoth${BINARY_SUFFIX}.desktop )
#exec_program(sed ARGS "-i" "'s/^\(Name.*=.*\)$/\1TEST/g'" ${CMAKE_CURRENT_BINARY_DIR}/${BINARY_PREFIX}wesnoth${BINARY_SUFFIX}.desktop )
# install the generated .desktop file
# install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${BINARY_PREFIX}wesnoth${BINARY_SUFFIX}.desktop DESTINATION ${DESKTOPDIR} )
install(FILES icons/wesnoth.desktop DESTINATION ${DESKTOPDIR} )
install(FILES icons/wesnoth-icon.png DESTINATION ${ICONDIR} )
# install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${BINARY_PREFIX}wesnoth${BINARY_SUFFIX}.desktop DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/applications )
install(FILES icons/wesnoth.desktop DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/applications )
install(FILES icons/wesnoth-icon.png DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/icons/hicolor/64x64/apps )
endif(ENABLE_DESKTOP_ENTRY AND ENABLE_GAME)
@ -830,7 +824,7 @@ if(ENABLE_SERVER AND FIFO_DIR)
endif()
# Index for checking states of localized images at runtime.
install(FILES l10n-track DESTINATION ${DATADIR})
install(FILES l10n-track DESTINATION ${CMAKE_INSTALL_DATADIR}/${DATADIRNAME})
#
# uninstall

View file

@ -9,11 +9,11 @@ endif()
set(ALL_MANPAGES wesnoth.6 wesnothd.6)
foreach(MANPAGE ${MANPAGES})
install(FILES ${MANPAGE} DESTINATION "${MANDIR}/man6/")
install(FILES ${MANPAGE} DESTINATION "${CMAKE_INSTALL_MANDIR}/man6/")
if(ENABLE_NLS)
foreach(LANG ${LINGUAS})
install(FILES ${LANG}/${MANPAGE} DESTINATION "${MANDIR}/${LANG}/man6/" OPTIONAL)
install(FILES ${LANG}/${MANPAGE} DESTINATION "${CMAKE_INSTALL_MANDIR}/${LANG}/man6/" OPTIONAL)
endforeach(LANG ${LINGUAS})
endif(ENABLE_NLS)
endforeach(MANPAGE ${MANPAGES})

View file

@ -1,14 +1,14 @@
set_directory_properties(PROPERTIES CLEAN_NO_CUSTOM true)
install(FILES manual.en.html DESTINATION "${DOCDIR}")
install(FILES manual.en.html DESTINATION "${CMAKE_INSTALL_DOCDIR}/html")
install(DIRECTORY images styles
DESTINATION "${DOCDIR}"
DESTINATION "${CMAKE_INSTALL_DOCDIR}/html"
PATTERN ".git" EXCLUDE
)
if(ENABLE_NLS)
foreach(LANG ${LINGUAS})
install(FILES manual.${LANG}.html DESTINATION "${DOCDIR}" OPTIONAL)
install(FILES manual.${LANG}.html DESTINATION "${CMAKE_INSTALL_DOCDIR}/html" OPTIONAL)
endforeach(LANG ${LINGUAS})
endif(ENABLE_NLS)

View file

@ -3,7 +3,7 @@ Description=Wesnoth Multiplayer Server Daemon
After=network.target
[Service]
ExecStart=@CMAKE_INSTALL_PREFIX@/@BINDIR@/wesnothd
ExecStart=@CMAKE_INSTALL_FULL_BINDIR@/wesnothd
[Install]
WantedBy=multi-user.target

View file

@ -229,32 +229,32 @@ if(ENABLE_NLS)
foreach(DOMAIN ${DOMAINS})
add_custom_command(
OUTPUT ${CMAKE_SOURCE_DIR}/${LOCALEDIR}/${LINGUA}/LC_MESSAGES
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${LINGUA}/LC_MESSAGES
COMMAND ${CMAKE_COMMAND} -E make_directory
${CMAKE_SOURCE_DIR}/${LOCALEDIR}/${LINGUA}/LC_MESSAGES
${CMAKE_CURRENT_BINARY_DIR}/${LINGUA}/LC_MESSAGES
COMMENT "mo-update [${LINGUA}]: Creating locale directory."
)
add_custom_command(
OUTPUT ${CMAKE_SOURCE_DIR}/${LOCALEDIR}/${LINGUA}/LC_MESSAGES/${DOMAIN}.mo
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${LINGUA}/LC_MESSAGES/${DOMAIN}.mo
COMMAND ${GETTEXT_MSGFMT_EXECUTABLE}
${GETTEXT_MSGFMT_PARAMETER}
-o ${CMAKE_SOURCE_DIR}/${LOCALEDIR}/${LINGUA}/LC_MESSAGES/${DOMAIN}.mo ${LINGUA}.po
-o ${CMAKE_CURRENT_BINARY_DIR}/${LINGUA}/LC_MESSAGES/${DOMAIN}.mo ${LINGUA}.po
DEPENDS
${CMAKE_SOURCE_DIR}/${LOCALEDIR}/${LINGUA}/LC_MESSAGES
${CMAKE_CURRENT_BINARY_DIR}/${LINGUA}/LC_MESSAGES
${PROJECT_SOURCE_DIR}/po/${DOMAIN}/${LINGUA}.po
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/po/${DOMAIN}
COMMENT "mo-update [${DOMAIN}-${LINGUA}]: Creating mo file."
)
install(FILES ${CMAKE_SOURCE_DIR}/${LOCALEDIR}/${LINGUA}/LC_MESSAGES/${DOMAIN}.mo
DESTINATION ${LOCALE_INSTALL}/${LINGUA}/LC_MESSAGES)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${LINGUA}/LC_MESSAGES/${DOMAIN}.mo
DESTINATION ${CMAKE_INSTALL_LOCALEDIR}/${LINGUA}/LC_MESSAGES)
set(mo-update-SRC ${mo-update-SRC}
${CMAKE_SOURCE_DIR}/${LOCALEDIR}/${LINGUA}/LC_MESSAGES/${DOMAIN}.mo
${CMAKE_CURRENT_BINARY_DIR}/${LINGUA}/LC_MESSAGES/${DOMAIN}.mo
)
set(mo-update-LINGUA-SRC ${mo-update-LINGUA-SRC}
${CMAKE_SOURCE_DIR}/${LOCALEDIR}/${LINGUA}/LC_MESSAGES/${DOMAIN}.mo
${CMAKE_CURRENT_BINARY_DIR}/${LINGUA}/LC_MESSAGES/${DOMAIN}.mo
)
endforeach(DOMAIN ${DOMAINS})
@ -276,7 +276,7 @@ if(ENABLE_NLS)
)
set_directory_properties(properties
ADDITIONAL_MAKE_CLEAN_FILES ${CMAKE_SOURCE_DIR}/${LOCALEDIR}
ADDITIONAL_MAKE_CLEAN_FILES ${CMAKE_CURRENT_BINARY_DIR}
)
endif(ENABLE_NLS)

View file

@ -389,7 +389,7 @@ if(ENABLE_GAME)
PROPERTIES OUTPUT_NAME ${BINARY_PREFIX}wesnoth${BINARY_SUFFIX}
)
install(TARGETS wesnoth DESTINATION ${BINDIR})
install(TARGETS wesnoth DESTINATION ${CMAKE_INSTALL_BINDIR})
endif(ENABLE_GAME)
########### Wesnothd Server ###############
@ -404,7 +404,7 @@ if(ENABLE_SERVER)
set_target_properties(wesnothd PROPERTIES OUTPUT_NAME ${BINARY_PREFIX}wesnothd${BINARY_SUFFIX})
install(TARGETS wesnothd DESTINATION ${BINDIR})
install(TARGETS wesnothd DESTINATION ${CMAKE_INSTALL_BINDIR})
endif(ENABLE_SERVER)
@ -424,7 +424,7 @@ if(ENABLE_CAMPAIGN_SERVER)
)
set_target_properties(campaignd PROPERTIES OUTPUT_NAME ${BINARY_PREFIX}campaignd${BINARY_SUFFIX})
install(TARGETS campaignd DESTINATION ${BINDIR})
install(TARGETS campaignd DESTINATION ${CMAKE_INSTALL_BINDIR})
endif(ENABLE_CAMPAIGN_SERVER)