From aef1332e4293d873ce5b827785daa3097209c5e6 Mon Sep 17 00:00:00 2001 From: Perttu Ahola Date: Mon, 23 Jul 2012 15:23:33 +0300 Subject: [PATCH] Improve build configuration options --- CMakeLists.txt | 57 ++++++++++++++++++++++++++++++++++++------ src/CMakeLists.txt | 8 +++--- src/cmake_config.h.in | 10 +++++--- src/config.h | 9 ++++--- src/lua/CMakeLists.txt | 2 ++ src/main.cpp | 4 +-- src/porting.cpp | 49 ++++++++++++++++++++++++++---------- 7 files changed, 104 insertions(+), 35 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index dc903721b..6f6d1111b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -62,7 +62,7 @@ if(WIN32) elseif(APPLE) # Random placeholders; this isn't usually used and may not work # See https://github.com/toabi/minetest-mac/ - set(SHAREDIR "share/${PROJECT_NAME}") + set(SHAREDIR "${CMAKE_INSTALL_PREFIX}/share/${PROJECT_NAME}") set(BINDIR "bin") set(DOCDIR "share/doc/${PROJECT_NAME}") set(EXAMPLE_CONF_DIR ${DOCDIR}) @@ -78,17 +78,58 @@ elseif(UNIX) # Linux, BSD etc set(ICONDIR "unix/icons") set(LOCALEDIR "locale") else() - set(SHAREDIR "share/${PROJECT_NAME}") - set(BINDIR "bin") - set(DOCDIR "share/doc/${PROJECT_NAME}") - set(MANDIR "share/man") + set(SHAREDIR "${CMAKE_INSTALL_PREFIX}/share/${PROJECT_NAME}") + set(BINDIR "${CMAKE_INSTALL_PREFIX}/bin") + set(DOCDIR "${CMAKE_INSTALL_PREFIX}/share/doc/${PROJECT_NAME}") + set(MANDIR "${CMAKE_INSTALL_PREFIX}/share/man") set(EXAMPLE_CONF_DIR ${DOCDIR}) - set(XDG_APPS_DIR "share/applications") - set(ICONDIR "share/icons") - set(LOCALEDIR "share/locale") + set(XDG_APPS_DIR "${CMAKE_INSTALL_PREFIX}/share/applications") + set(ICONDIR "${CMAKE_INSTALL_PREFIX}/share/icons") + set(LOCALEDIR "${CMAKE_INSTALL_PREFIX}/share/locale") endif() endif() +set(CUSTOM_SHAREDIR "" CACHE STRING "Directory to install data files into") +if(NOT CUSTOM_SHAREDIR STREQUAL "") + set(SHAREDIR "${CUSTOM_SHAREDIR}") + message(STATUS "Using SHAREDIR=${SHAREDIR}") +endif() +set(CUSTOM_BINDIR "" CACHE STRING "Directory to install binaries into") +if(NOT CUSTOM_BINDIR STREQUAL "") + set(BINDIR "${CUSTOM_BINDIR}") + message(STATUS "Using BINDIR=${BINDIR}") +endif() +set(CUSTOM_DOCDIR "" CACHE STRING "Directory to install documentation into") +if(NOT CUSTOM_DOCDIR STREQUAL "") + set(DOCDIR "${CUSTOM_DOCDIR}") + message(STATUS "Using DOCDIR=${DOCDIR}") +endif() +set(CUSTOM_MANDIR "" CACHE STRING "Directory to install manpages into") +if(NOT CUSTOM_MANDIR STREQUAL "") + set(MANDIR "${CUSTOM_MANDIR}") + message(STATUS "Using MANDIR=${MANDIR}") +endif() +set(CUSTOM_EXAMPLE_CONF_DIR "" CACHE STRING "Directory to install example config file into") +if(NOT CUSTOM_EXAMPLE_CONF_DIR STREQUAL "") + set(EXAMPLE_CONF_DIR "${CUSTOM_EXAMPLE_CONF_DIR}") + message(STATUS "Using EXAMPLE_CONF_DIR=${EXAMPLE_CONF_DIR}") +endif() +set(CUSTOM_XDG_APPS_DIR "" CACHE STRING "Directory to install .desktop files into") +if(NOT CUSTOM_XDG_APPS_DIR STREQUAL "") + set(XDG_APPS_DIR "${CUSTOM_XDG_APPS_DIR}") + message(STATUS "Using XDG_APPS_DIR=${XDG_APPS_DIR}") +endif() +set(CUSTOM_ICONDIR "" CACHE STRING "Directory to install icons into") +if(NOT CUSTOM_ICONDIR STREQUAL "") + set(ICONDIR "${CUSTOM_ICONDIR}") + message(STATUS "Using ICONDIR=${ICONDIR}") +endif() +set(CUSTOM_LOCALEDIR "" CACHE STRING "Directory to install l10n files into") +if(NOT CUSTOM_LOCALEDIR STREQUAL "") + set(LOCALEDIR "${CUSTOM_LOCALEDIR}") + message(STATUS "Using LOCALEDIR=${LOCALEDIR}") +endif() + install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/builtin" DESTINATION "${SHAREDIR}") install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/games/minimal" DESTINATION "${SHAREDIR}/games") set(MINETEST_GAME_SOURCE "${CMAKE_CURRENT_SOURCE_DIR}/games/minetest_game") diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index a0276cfaa..e369b9623 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,10 +1,6 @@ project(minetest) cmake_minimum_required( VERSION 2.6 ) -if(RUN_IN_PLACE) - add_definitions ( -DRUN_IN_PLACE ) -endif(RUN_IN_PLACE) - # Set some random things default to not being visible in the GUI mark_as_advanced(EXECUTABLE_OUTPUT_PATH LIBRARY_OUTPUT_PATH) mark_as_advanced(JTHREAD_INCLUDE_DIR JTHREAD_LIBRARY) @@ -139,13 +135,15 @@ else() #set(CLIENT_PLATFORM_LIBS -lXxf86vm) # This way Xxf86vm is found on OpenBSD too find_library(XXF86VM_LIBRARY Xxf86vm) + mark_as_advanced(XXF86VM_LIBRARY) set(CLIENT_PLATFORM_LIBS ${CLIENT_PLATFORM_LIBS} ${XXF86VM_LIBRARY}) endif() find_package(Jthread REQUIRED) find_package(Sqlite3 REQUIRED) -# TODO: Create proper find script for Lua +# Do not use system-wide installation of Lua, because it'll likely be a +# different version and/or has different build options. set(LUA_INCLUDE_DIR "${PROJECT_SOURCE_DIR}/lua/src") set(LUA_LIBRARY "lua") diff --git a/src/cmake_config.h.in b/src/cmake_config.h.in index 054cca165..c2bdc9670 100644 --- a/src/cmake_config.h.in +++ b/src/cmake_config.h.in @@ -4,16 +4,18 @@ #define CMAKE_CONFIG_H #define CMAKE_PROJECT_NAME "@PROJECT_NAME@" -#define CMAKE_INSTALL_PREFIX "@CMAKE_INSTALL_PREFIX@" #define CMAKE_VERSION_STRING "@VERSION_STRING@" +#define CMAKE_RUN_IN_PLACE @RUN_IN_PLACE@ +#define CMAKE_USE_GETTEXT @USE_GETTEXT@ +#define CMAKE_USE_SOUND @USE_SOUND@ +#define CMAKE_STATIC_SHAREDIR "@SHAREDIR@" + #ifdef NDEBUG #define CMAKE_BUILD_TYPE "Release" #else #define CMAKE_BUILD_TYPE "Debug" #endif -#define CMAKE_USE_GETTEXT @USE_GETTEXT@ -#define CMAKE_USE_SOUND @USE_SOUND@ -#define CMAKE_BUILD_INFO "VER=@VERSION_STRING@ BUILD_TYPE="CMAKE_BUILD_TYPE" RUN_IN_PLACE=@RUN_IN_PLACE@ USE_GETTEXT=@USE_GETTEXT@ USE_SOUND=@USE_SOUND@ INSTALL_PREFIX=@CMAKE_INSTALL_PREFIX@" +#define CMAKE_BUILD_INFO "VER=@VERSION_STRING@ BUILD_TYPE="CMAKE_BUILD_TYPE" RUN_IN_PLACE=@RUN_IN_PLACE@ USE_GETTEXT=@USE_GETTEXT@ USE_SOUND=@USE_SOUND@ STATIC_SHAREDIR=@SHAREDIR@" #endif diff --git a/src/config.h b/src/config.h index 233d74717..aedca8b20 100644 --- a/src/config.h +++ b/src/config.h @@ -8,9 +8,10 @@ #define PROJECT_NAME "Minetest" #define VERSION_STRING "unknown" -#define BUILD_TYPE "unknown" +#define RUN_IN_PLACE 0 #define USE_GETTEXT 0 #define USE_SOUND 0 +#define STATIC_SHAREDIR "" #define BUILD_INFO "non-cmake" #ifdef USE_CMAKE_CONFIG_H @@ -19,12 +20,14 @@ #define PROJECT_NAME CMAKE_PROJECT_NAME #undef VERSION_STRING #define VERSION_STRING CMAKE_VERSION_STRING - #undef BUILD_INFO - #define BUILD_INFO CMAKE_BUILD_INFO + #undef RUN_IN_PLACE + #define RUN_IN_PLACE CMAKE_RUN_IN_PLACE #undef USE_GETTEXT #define USE_GETTEXT CMAKE_USE_GETTEXT #undef USE_SOUND #define USE_SOUND CMAKE_USE_SOUND + #undef STATIC_SHAREDIR + #define STATIC_SHAREDIR CMAKE_STATIC_SHAREDIR #undef BUILD_INFO #define BUILD_INFO CMAKE_BUILD_INFO #endif diff --git a/src/lua/CMakeLists.txt b/src/lua/CMakeLists.txt index f2f8b9768..36e271889 100644 --- a/src/lua/CMakeLists.txt +++ b/src/lua/CMakeLists.txt @@ -45,6 +45,7 @@ if(DEFAULT_DLOPEN) else() option(LUA_USE_DLOPEN "Enable dlopen support." OFF) endif() +mark_as_advanced(LUA_USE_DLOPEN) if(DEFAULT_POSIX) else() @@ -55,6 +56,7 @@ if(DEFAULT_ANSI) else() option(LUA_ANSI "Disable non-ansi features." OFF) endif() +mark_as_advanced(LUA_ANSI) # # Lua version diff --git a/src/main.cpp b/src/main.cpp index 092a7b03f..6075e9d10 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -878,7 +878,7 @@ int main(int argc, char *argv[]) // Initialize debug streams #define DEBUGFILE "debug.txt" -#ifdef RUN_IN_PLACE +#if RUN_IN_PLACE std::string logfile = DEBUGFILE; #else std::string logfile = porting::path_user+DIR_DELIM+DEBUGFILE; @@ -962,7 +962,7 @@ int main(int argc, char *argv[]) // Legacy configuration file location filenames.push_back(porting::path_user + DIR_DELIM + ".." + DIR_DELIM + "minetest.conf"); -#ifdef RUN_IN_PLACE +#if RUN_IN_PLACE // Try also from a lower level (to aid having the same configuration // for many RUN_IN_PLACE installs) filenames.push_back(porting::path_user + diff --git a/src/porting.cpp b/src/porting.cpp index fb999abf9..945aea6eb 100644 --- a/src/porting.cpp +++ b/src/porting.cpp @@ -29,6 +29,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "filesys.h" #include "log.h" #include "util/string.h" +#include #ifdef __APPLE__ #include "CoreFoundation/CoreFoundation.h" @@ -154,7 +155,7 @@ bool detectMSVCBuildDir(char *c_path) void initializePaths() { -#ifdef RUN_IN_PLACE +#if RUN_IN_PLACE /* Use relative paths if RUN_IN_PLACE */ @@ -252,19 +253,41 @@ void initializePaths() #elif defined(linux) #include - char buf[BUFSIZ]; - memset(buf, 0, BUFSIZ); // Get path to executable - assert(readlink("/proc/self/exe", buf, BUFSIZ-1) != -1); - - pathRemoveFile(buf, '/'); + std::string bindir = ""; + { + char buf[BUFSIZ]; + memset(buf, 0, BUFSIZ); + assert(readlink("/proc/self/exe", buf, BUFSIZ-1) != -1); + pathRemoveFile(buf, '/'); + bindir = buf; + } - path_share = std::string(buf) + "/../share/" + PROJECT_NAME; - //path_share = std::string(INSTALL_PREFIX) + "/share/" + PROJECT_NAME; - if (!fs::PathExists(path_share)) { - dstream<<"WARNING: system-wide share not found at \""< trylist; + std::string static_sharedir = STATIC_SHAREDIR; + if(static_sharedir != "" && static_sharedir != ".") + trylist.push_back(static_sharedir); + trylist.push_back(bindir + "/../share/" + PROJECT_NAME); + trylist.push_back(bindir + "/.."); + + for(std::list::const_iterator i = trylist.begin(); + i != trylist.end(); i++) + { + const std::string &trypath = *i; + if(!fs::PathExists(trypath) || !fs::PathExists(trypath + "/builtin")){ + dstream<<"WARNING: system-wide share not found at \"" + <