(Unix) Changed the default installation prefix from /usr/local to /usr on Linux.

Also changed the prefix on NetBSD from /usr/local to /usr/pkg.
This commit is contained in:
Leon Styhre 2021-04-02 12:12:49 +02:00
parent fc347e5caf
commit 4ff95c4ddf
2 changed files with 22 additions and 12 deletions

View file

@ -177,8 +177,19 @@ if(DEFINED libCEC_FOUND)
add_definitions(-DHAVE_LIBCEC) add_definitions(-DHAVE_LIBCEC)
endif() endif()
# For Unix systems, assign the installation prefix. # For Unix systems, assign the installation prefix. If it's not explicitly set,
# we use /usr on Linux, /usr/pkg on NetBSD and /usr/local on FreeBSD and OpenBSD.
if(NOT WIN32 AND NOT APPLE) if(NOT WIN32 AND NOT APPLE)
if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
if(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
set(CMAKE_INSTALL_PREFIX "/usr")
elseif(${CMAKE_SYSTEM_NAME} MATCHES "NetBSD")
set(CMAKE_INSTALL_PREFIX "/usr/pkg")
else()
set(CMAKE_INSTALL_PREFIX "/usr/local")
endif()
endif()
message("-- Installation prefix is set to " ${CMAKE_INSTALL_PREFIX})
add_definitions(-DES_INSTALL_PREFIX="${CMAKE_INSTALL_PREFIX}") add_definitions(-DES_INSTALL_PREFIX="${CMAKE_INSTALL_PREFIX}")
endif() endif()

View file

@ -36,16 +36,23 @@
#include <unistd.h> #include <unistd.h>
#endif #endif
// For Unix systems, try to get the install prefix as defined when CMake was run. // For Unix systems, set the install prefix as defined via CMAKE_INSTALL_PREFIX when CMake was run.
// The installPrefix directory is the value set for CMAKE_INSTALL_PREFIX during build. // If not defined, the default prefix '/usr' will be used on Linux, '/usr/pkg' on NetBSD and
// If not defined, the default prefix path '/usr/local' will be used. // '/usr/local' on FreeBSD and OpenBSD. This fallback should not be required though unless the
// build environment is broken.
#if defined(__unix__) #if defined(__unix__)
#if defined(ES_INSTALL_PREFIX) #if defined(ES_INSTALL_PREFIX)
std::string installPrefix = ES_INSTALL_PREFIX; std::string installPrefix = ES_INSTALL_PREFIX;
#else #else
#if defined(__linux__)
std::string installPrefix = "/usr";
#elif defined(__NetBSD__)
std::string installPrefix = "/usr/pkg";
#else
std::string installPrefix = "/usr/local"; std::string installPrefix = "/usr/local";
#endif #endif
#endif #endif
#endif
namespace Utils namespace Utils
{ {
@ -240,15 +247,7 @@ namespace Utils
std::string getProgramDataPath() std::string getProgramDataPath()
{ {
// For Unix systems, installPrefix should be populated by CMAKE from
// $CMAKE_INSTALL_PREFIX. But just as a precaution, let's check if this
// variable is blank, and if so set it to '/usr/local'.
// Just in case some build environments won't handle this correctly.
// For Windows it doesn't really work like that and the application could have
// been install to an arbitrary location, so this function won't be used on that OS.
#if defined(__unix__) #if defined(__unix__)
if (!installPrefix.length())
installPrefix = "/usr/local";
return installPrefix + "/share/emulationstation"; return installPrefix + "/share/emulationstation";
#else #else
return ""; return "";