Commit 0ca04bed by Maarten L. Hekkelman

Updated cmake file, configurable data dir

parent 89850de6
...@@ -30,7 +30,7 @@ endif() ...@@ -30,7 +30,7 @@ endif()
option(BUILD_SHARED_LIBS "Build a shared library instead of a static one" ON) option(BUILD_SHARED_LIBS "Build a shared library instead of a static one" ON)
set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON) set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON)
set(CMAKE_DEBUG_POSTFIX d) # set(CMAKE_DEBUG_POSTFIX d)
if(MSVC) if(MSVC)
# make msvc standards compliant... # make msvc standards compliant...
...@@ -69,8 +69,16 @@ if(MSVC) ...@@ -69,8 +69,16 @@ if(MSVC)
set(COFF_SPEC "--coff=${COFF_TYPE}") set(COFF_SPEC "--coff=${COFF_TYPE}")
endif() endif()
if(LINUX)
# On Linux, install in the $HOME/.local folder by default
if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
message(WARNING "The library and auxiliary files will be installed in $ENV{HOME}/.local")
set(CMAKE_INSTALL_PREFIX "$ENV{HOME}/.local" CACHE PATH "..." FORCE)
endif()
endif()
# Optionally use mrc to create resources # Optionally use mrc to create resources
find_program(MRC mrc HINTS "$ENV{LOCALAPPDATA}/mrc" "${CMAKE_INSTALL_PREFIX}/../mrc" "/usr/local/bin") find_program(MRC mrc HINTS "$ENV{LOCALAPPDATA}/mrc" "$ENV{HOME}/.local/bin" "${CMAKE_INSTALL_PREFIX}/../mrc" "/usr/local/bin")
if(MRC) if(MRC)
option(USE_RSRC "Use mrc to create resources" ON) option(USE_RSRC "Use mrc to create resources" ON)
...@@ -159,6 +167,7 @@ set(project_headers ...@@ -159,6 +167,7 @@ set(project_headers
) )
add_library(cifpp ${project_sources} ${project_headers}) add_library(cifpp ${project_sources} ${project_headers})
set_target_properties(cifpp PROPERTIES POSITION_INDEPENDENT_CODE ON)
target_include_directories(cifpp target_include_directories(cifpp
PUBLIC PUBLIC
...@@ -215,7 +224,8 @@ add_compile_definitions( ...@@ -215,7 +224,8 @@ add_compile_definitions(
# CACHE_DIR="${CMAKE_INSTALL_PREFIX}/${SHARE_INSTALL_DIR}" # CACHE_DIR="${CMAKE_INSTALL_PREFIX}/${SHARE_INSTALL_DIR}"
DATA_DIR="${CMAKE_INSTALL_PREFIX}/${SHARE_INSTALL_DIR}" ) DATA_DIR="${CMAKE_INSTALL_PREFIX}/${SHARE_INSTALL_DIR}" )
generate_export_header(cifpp) generate_export_header(cifpp
EXPORT_FILE_NAME cif++/Cif++Export.hpp)
# Install rules # Install rules
...@@ -226,9 +236,10 @@ install(TARGETS cifpp ...@@ -226,9 +236,10 @@ install(TARGETS cifpp
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}) INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
export(EXPORT cifppTargets install(EXPORT cifppTargets
FILE "${CMAKE_CURRENT_BINARY_DIR}/cmake/cifppTargets.cmake" FILE "cifppTargets.cmake"
NAMESPACE cifpp:: NAMESPACE cifpp::
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/cifpp
) )
install( install(
...@@ -238,7 +249,7 @@ install( ...@@ -238,7 +249,7 @@ install(
) )
install( install(
FILES "${CMAKE_CURRENT_BINARY_DIR}/cifpp_export.h" FILES "${CMAKE_CURRENT_BINARY_DIR}/cif++/Cif++Export.hpp"
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/cif++ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/cif++
COMPONENT Devel COMPONENT Devel
) )
......
...@@ -45,7 +45,7 @@ ...@@ -45,7 +45,7 @@
#include <unistd.h> #include <unistd.h>
#endif #endif
#include "cifpp_export.h" #include "cif++/Cif++Export.hpp"
#if _MSC_VER #if _MSC_VER
# pragma warning (disable : 4355) // this is used in Base Initializer list # pragma warning (disable : 4355) // this is used in Base Initializer list
...@@ -221,7 +221,6 @@ class Progress ...@@ -221,7 +221,6 @@ class Progress
std::unique_ptr<std::istream> loadResource(std::filesystem::path name); std::unique_ptr<std::istream> loadResource(std::filesystem::path name);
void addFileResource(const std::string &name, std::filesystem::path dataFile); void addFileResource(const std::string &name, std::filesystem::path dataFile);
void addDataDirectory(std::filesystem::path dataDir);
} }
...@@ -1227,6 +1227,14 @@ namespace cif ...@@ -1227,6 +1227,14 @@ namespace cif
// -------------------------------------------------------------------- // --------------------------------------------------------------------
std::map<std::string,std::filesystem::path> gLocalResources; std::map<std::string,std::filesystem::path> gLocalResources;
std::filesystem::path gDataDir;
void addDataDirectory(std::filesystem::path dataDir)
{
if (VERBOSE and not fs::exists(dataDir))
std::cerr << "The specified data directory " << dataDir << " does not exist" << std::endl;
gDataDir = dataDir;
}
void addFileResource(const std::string &name, std::filesystem::path dataFile) void addFileResource(const std::string &name, std::filesystem::path dataFile)
{ {
...@@ -1246,6 +1254,9 @@ std::unique_ptr<std::istream> loadResource(std::filesystem::path name) ...@@ -1246,6 +1254,9 @@ std::unique_ptr<std::istream> loadResource(std::filesystem::path name)
result.reset(file.release()); result.reset(file.release());
} }
if (not result and not fs::exists(p) and not gDataDir.empty())
p = gDataDir / name;
#if defined(CACHE_DIR) #if defined(CACHE_DIR)
if (not result and not fs::exists(p)) if (not result and not fs::exists(p))
{ {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment