diff --git a/CMakeLists.txt b/CMakeLists.txt index a9e6b3b7c..37266750c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -177,8 +177,19 @@ if(DEFINED libCEC_FOUND) add_definitions(-DHAVE_LIBCEC) 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(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}") endif() diff --git a/es-core/src/utils/FileSystemUtil.cpp b/es-core/src/utils/FileSystemUtil.cpp index 2790c1bb8..b5ec6535a 100644 --- a/es-core/src/utils/FileSystemUtil.cpp +++ b/es-core/src/utils/FileSystemUtil.cpp @@ -36,16 +36,23 @@ #include #endif -// For Unix systems, try to get the install prefix as defined when CMake was run. -// The installPrefix directory is the value set for CMAKE_INSTALL_PREFIX during build. -// If not defined, the default prefix path '/usr/local' will be used. +// For Unix systems, set the install prefix as defined via CMAKE_INSTALL_PREFIX when CMake was run. +// If not defined, the default prefix '/usr' will be used on Linux, '/usr/pkg' on NetBSD and +// '/usr/local' on FreeBSD and OpenBSD. This fallback should not be required though unless the +// build environment is broken. #if defined(__unix__) #if defined(ES_INSTALL_PREFIX) std::string installPrefix = ES_INSTALL_PREFIX; #else +#if defined(__linux__) +std::string installPrefix = "/usr"; +#elif defined(__NetBSD__) +std::string installPrefix = "/usr/pkg"; +#else std::string installPrefix = "/usr/local"; #endif #endif +#endif namespace Utils { @@ -240,15 +247,7 @@ namespace Utils 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 (!installPrefix.length()) - installPrefix = "/usr/local"; return installPrefix + "/share/emulationstation"; #else return "";