Skip to content

Update driver install dir to follow cmake install prefix #1792

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@ gdlde/
gdlde*.zip
.vscode
.idea/
Testing/
2020.2.zip
qhull-2020.2
9 changes: 1 addition & 8 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -161,14 +161,7 @@ set(JPEGDIR "" CACHE PATH "GDL: Specify the JPEG directory tree")
set(SZIPDIR "" CACHE PATH "GDL: Specify the SZip directory tree")

set(GDL_DATA_DIR "/share/gnudatalanguage" CACHE PATH "GDL: data directory relative to CMAKE_INSTALL_PREFIX")
set(GDL_LIB_DIR "" CACHE PATH "GDL: library directory relative to CMAKE_INSTALL_PREFIX")
#define (for plplotdriver/CMakeLists.txt) the GDL_DRV_DIR where the drivers will be installed.
#if GDL_LIB_DIR is empty, it will be the default (GDL_DATA_DIR/drivers) otherwise it is GDL_LIB_DIR (not GDL_LIB_DIR/drivers)
if ( GDL_LIB_DIR STREQUAL "" OR NOT GDL_LIB_DIR)
set (GDL_DRV_DIR "${CMAKE_INSTALL_PREFIX}/${GDL_DATA_DIR}/drivers") # CACHE PATH "GDL: where the drivers will be installed.")
else()
set (GDL_DRV_DIR "${GDL_LIB_DIR}" ) # CACHE PATH "GDL: where the drivers will be installed.")
endif()
set(GDL_LIB_DIR "/lib/gnudatalanguage" CACHE PATH "GDL: library directory relative to CMAKE_INSTALL_PREFIX")
# check for 64-bit OS
if(${CMAKE_SIZEOF_VOID_P} EQUAL 8)
set(HAVE_64BIT_OS 1)
Expand Down
3 changes: 3 additions & 0 deletions INSTALL.CMake
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ Other options include:
- GDL_DATA_DIR (default: /share/gnudatalanguage) to specify
a custom installation location for GDL files
(a subdirectory of the main installation prefix)
- GDL_LIB_DIR (default: /lib/gnudatalanguage) to specify
a custom installation location for local PlPlot driver files
(a subdirectory of the main installation prefix)

The list of all GDL-related options accepted by CMake along
with their default values can be obtained by calling:
Expand Down
6 changes: 2 additions & 4 deletions config.h.cmake
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
#ifndef __CONFIG_H__
#define __CONFIG_H__

#define EXEC_PREFIX "@CMAKE_INSTALL_PREFIX@"
#define GDLDATADIR "@CMAKE_INSTALL_PREFIX@@GDL_DATA_DIR@"
#define GDLLIBDIR "@GDL_LIB_DIR@"
#define GDL_DRV_DIR "@GDL_DRV_DIR@"
#cmakedefine GDL_DATA_DIR "@GDL_DATA_DIR@"
#cmakedefine GDL_LIB_DIR "@GDL_LIB_DIR@"

#define _CRT_SECURE_NO_WARNINGS

Expand Down
7 changes: 4 additions & 3 deletions scripts/build_gdl.sh
Original file line number Diff line number Diff line change
Expand Up @@ -559,11 +559,12 @@ function install_gdl {

function test_gdl {
log "Testing GDL..."
cd ${ROOT_DIR}/build
if [ -f ${GDL_DIR}/CMakeModules/CodeCoverage.cmake ]; then
cd "${ROOT_DIR}/build" || exit 1
if [ -f "${GDL_DIR}/CMakeModules/CodeCoverage.cmake" ]; then
make codecov || exit 1
else
CTEST_OUTPUT_ON_FAILURE=1 make test || exit 1
# since we do not install anything we need to set the driver path to the directory of the compiles drivers
CTEST_OUTPUT_ON_FAILURE=1 GDL_DRV_DIR="${ROOT_DIR}/build/src/plplotdriver" make test || exit 1
fi
}

Expand Down
70 changes: 29 additions & 41 deletions src/gdl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -215,15 +215,15 @@ namespace MyPaths {
if (length > 0)
{
path = (char*)malloc(length + 1);
if (!path) return std::string(".");
if (!path) return {"."};
wai_getExecutablePath(path, length, &dirname_length);
path[dirname_length] = '\0';
// printf(" dirname: %s\n", path);
std::string pathstring(path);
free(path);
return pathstring;
}
return std::string(".");
return {"."};
}
}

Expand All @@ -236,43 +236,44 @@ int main(int argc, char *argv[])
bool setQuietSysvar=false;
bool willSuppressEditInput=false;
std::string myMessageBoxName="";

//The default installation location --- will not always be there.
gdlDataDir = std::string(GDLDATADIR);
gdlLibDir = std::string(GDLLIBDIR);

// The default installation location --- will not always be there.
gdlDataDir = std::string(GDL_DATA_DIR);
gdlLibDir = std::string(GDL_LIB_DIR);

#ifdef _WIN32
std::replace(gdlDataDir.begin(), gdlDataDir.end(), '/', '\\');
std::replace(gdlLibDir.begin(), gdlLibDir.end(), '/', '\\');
#endif
#endif
// make sure dirs are prefixed with the system's path separator
if (gdlDataDir.at(0) != lib::PathSeparator()) gdlDataDir.assign(lib::PathSeparator() + gdlDataDir);
if (gdlLibDir.at(0) != lib::PathSeparator()) gdlLibDir.assign(lib::PathSeparator() + gdlLibDir);

//check where is the executable being run
whereami_gdl=MyPaths::getExecutablePath();
// if I am at a 'bin' location, then there are chances that I've bee INSTALLED, so all the resources I need can be accessed relatively to this 'bin' directory.
// if not, then I'm probably just a 'build' gdl and my ressources may (should?) be in the default location GDLDATADIR
std::size_t pos=whereami_gdl.rfind("bin");
if (pos == whereami_gdl.size()-3) { //we are the installed gdl!
gdlDataDir.assign( whereami_gdl+ lib::PathSeparator() + ".." + lib::PathSeparator() + "share" + lib::PathSeparator() + "gnudatalanguage") ;
// std::cerr<<"installed at: "<<gdlDataDir<<std::endl;

auto whereami = MyPaths::getExecutablePath();
// if I am at a 'bin' location, then there are chances that I've been INSTALLED, so all the resources I need can be accessed relatively to this 'bin' directory.
// if not, then I'm probably just a 'build' gdl and my resources may (should?) be in the default location GDL_DATA_DIR
auto pos = whereami.rfind("bin");
if (pos != std::string::npos) { // we are the installed gdl!
// use pos - 1, so we remove the path separator, too
gdlDataDir.assign(whereami.substr(0, pos - 1) + gdlDataDir);
gdlLibDir.assign(whereami.substr(0, pos - 1) + gdlLibDir);
}

//PATH. This one is often modified by people before starting GDL.
string gdlPath=GetEnvPathString("GDL_PATH"); //warning: is a Path, use system separator.
if( gdlPath == "") gdlPath=GetEnvString("IDL_PATH"); //warning: is a Path, use system separator.
if( gdlPath == "") gdlPath = gdlDataDir + lib::PathSeparator() + "lib";

//LIBDIR. Can be '' in which case the location of drivers is deduced from the location of
//the executable (OSX, Windows, unix in user-installed mode).
string driversPath = GetEnvPathString("GDL_DRV_DIR");
if (driversPath == "") { //NOT enforced by GDL_DRV_DIR
driversPath = gdlLibDir; //e.g. Fedora
if (driversPath == "") { //NOT enforced by GDLLIBDIR at build : not a distro
driversPath = gdlDataDir + lib::PathSeparator() + "drivers"; //deduced from the location of the executable
}
}
auto gdlPath = GetEnvPathString("GDL_PATH");
if( gdlPath.empty()) gdlPath = GetEnvPathString("IDL_PATH");
if( gdlPath.empty()) gdlPath = gdlDataDir + lib::PathSeparator() + "lib";

auto driversPath = GetEnvPathString("GDL_DRV_DIR");
// use the identical approach already used for figuring out the path to out *.pro files etc.
if (driversPath.empty()) driversPath = gdlLibDir;

//various env set?
char* wantCalm = getenv("IDL_QUIET");
if (wantCalm != NULL) setQuietSysvar=true;

//drivers if local
useLocalDrivers=false;
bool driversNotFound=false;
Expand Down Expand Up @@ -621,19 +622,6 @@ int main(int argc, char *argv[])
{
cerr << "- Please report bugs, feature or help requests and patches at: https://github.com/gnudatalanguage/gdl" << endl << endl;
}
// else
// {
// // if path not given, add users home
// if( !PathGiven(startup))
// {
// string home=GetEnvString("HOME");
// if( home != "")
// {
// AppendIfNeeded(home,"/");
// startup=home+startup;
// }
// }
// }

#ifdef USE_MPI
if (iAmMaster) {
Expand Down
82 changes: 47 additions & 35 deletions src/plplotdriver/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,40 +5,52 @@ if(INSTALL_LOCAL_DRIVERS)

#these drivers are always present
list(APPEND WHAT "ps" "svg" "mem")
list(APPEND WHATFILES "mem.driver_info" "svg.driver_info" "ps.driver_info")
add_library(ps MODULE ps.c)
target_link_libraries(
ps
${PLPLOT_LIBRARIES}
)
# Copy thr driver info file after building the target so we can use the build-dir directly when testing
add_custom_command(
TARGET ps POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy
${CMAKE_SOURCE_DIR}/src/plplotdriver/ps.driver_info
${CMAKE_CURRENT_BINARY_DIR}/ps.driver_info
)
target_link_libraries(ps ${PLPLOT_LIBRARIES})
add_library(svg MODULE svg.c)
target_link_libraries(
svg
${PLPLOT_LIBRARIES}
)
# Copy thr driver info file after building the target so we can use the build-dir directly when testing
add_custom_command(
TARGET svg POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy
${CMAKE_SOURCE_DIR}/src/plplotdriver/svg.driver_info
${CMAKE_CURRENT_BINARY_DIR}/svg.driver_info
)
target_link_libraries(svg ${PLPLOT_LIBRARIES})
add_library(mem MODULE mem.c)
target_link_libraries(
mem
${PLPLOT_LIBRARIES}
)
# Copy thr driver info file after building the target so we can use the build-dir directly when testing
add_custom_command(
TARGET mem POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy
${CMAKE_SOURCE_DIR}/src/plplotdriver/mem.driver_info
${CMAKE_CURRENT_BINARY_DIR}/mem.driver_info
)
target_link_libraries(mem ${PLPLOT_LIBRARIES})

#driver wxwidgets
if (HAVE_LIBWXWIDGETS)
set(LINK_DIRECTORIES ${LINK_DIRECTORIES} ${wxWidgets_LIBRARY_DIRS})
foreach(WXDEF ${wxWidgets_DEFINITIONS})
add_definitions(-D${WXDEF})
add_definitions(-D${WXDEF})
endforeach(WXDEF ${wxWidgets_DEFINITIONS})
include_directories( ${wxWidgets_INCLUDE_DIRS})
add_library(wxwidgets MODULE deprecated_wxwidgets.cpp deprecated_wxwidgets_app.cpp deprecated_wxwidgets_dc.cpp deprecated_wxwidgets_gc.cpp)
target_link_libraries(
wxwidgets
${PLPLOT_LIBRARIES}
${wxWidgets_LIBRARIES}
)
list(APPEND WHAT "wxwidgets")
list(APPEND WHATFILES "wxwidgets.driver_info")
endif(HAVE_LIBWXWIDGETS)

# Copy thr driver info file after building the target so we can use the build-dir directly when testing
add_custom_command(
TARGET wxwidgets POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy
${CMAKE_SOURCE_DIR}/src/plplotdriver/wxwidgets.driver_info
${CMAKE_CURRENT_BINARY_DIR}/wxwidgets.driver_info
)
target_link_libraries(wxwidgets ${PLPLOT_LIBRARIES} ${wxWidgets_LIBRARIES})
list(APPEND WHAT "wxwidgets")
endif(HAVE_LIBWXWIDGETS)

# driver xwin -- check if X11 is present
find_package(X11 QUIET)
Expand All @@ -47,27 +59,27 @@ if(INSTALL_LOCAL_DRIVERS)
set(LIBRARIES ${LIBRARIES} ${X11_LIBRARIES})
include_directories(${X11_INCLUDE_DIR})
add_library(xwin MODULE xwin.c)
target_link_libraries(
xwin
${PLPLOT_LIBRARIES}
${X11_LIBRARIES}
)
list (APPEND WHAT "xwin")
list(APPEND WHATFILES "wxin.driver_info")
# Copy thr driver info file after building the target so we can use the build-dir directly when testing
add_custom_command(
TARGET xwin POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy
${CMAKE_SOURCE_DIR}/src/plplotdriver/xwin.driver_info
${CMAKE_CURRENT_BINARY_DIR}/xwin.driver_info
)
target_link_libraries(xwin ${PLPLOT_LIBRARIES} ${X11_LIBRARIES})
list(APPEND WHAT "xwin")
endif(X11_FOUND)



if(WIN32)
set(DYNAMIC_SUFFIX ".dll")
else(WIN32)
set(DYNAMIC_SUFFIX ".so")
endif(WIN32)

foreach(v IN LISTS WHAT)
set_target_properties(${v} PROPERTIES PREFIX "" SUFFIX ${DYNAMIC_SUFFIX} )
install(TARGETS ${v} DESTINATION ${GDL_DRV_DIR})
install( FILES ${v}.driver_info DESTINATION ${GDL_DRV_DIR})
set_target_properties(${v} PROPERTIES PREFIX "" SUFFIX ${DYNAMIC_SUFFIX} )
install(TARGETS ${v} DESTINATION ${CMAKE_INSTALL_PREFIX}/${GDL_LIB_DIR})
install(FILES ${v}.driver_info DESTINATION ${CMAKE_INSTALL_PREFIX}/${GDL_LIB_DIR})
endforeach()

endif(INSTALL_LOCAL_DRIVERS)
2 changes: 1 addition & 1 deletion src/pythongdl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -585,7 +585,7 @@ extern "C" {
// if( gdlPath == "") gdlPath=GetEnvString("IDL_PATH");
// if( gdlPath == "")
// {
// gdlPath = "+" GDLDATADIR "/lib";
// gdlPath = "+" GDL_DATA_DIR "/lib";
// }
// SysVar::SetGDLPath( gdlPath);

Expand Down
21 changes: 9 additions & 12 deletions src/str.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,25 +45,25 @@ namespace lib {
std::string PathSeparator()
{
#ifdef _WIN32
if (lib::posixpaths) return std::string ("/");
return std::string ("\\");
if (lib::posixpaths) return {"/"};
return {"\\"};
#else
return std::string ("/");
return {"/"};
#endif
}

std::string SearchPathSeparator()
{
#ifdef _WIN32
return std::string (";");
return {";"};
#else
return std::string (":");
return {":"};
#endif
}

std::string ParentDirectoryIndicator()
{
return std::string ("..");
return {".."};
}
}
//using namespace std;
Expand All @@ -73,16 +73,13 @@ namespace lib {
std::string GetEnvString(const char* env)
{
char* c=getenv(env);
if( !c) return std::string("");
return std::string(c);
if( !c) return {""};
return {c};
}
//same but for a path: separator will be '\' for _WIN32
std::string GetEnvPathString(const char* env)
{
std::string ret("");
char* c=getenv(env);
if( !c) return ret;
ret=std::string(c);
std::string ret = GetEnvString(env);
#ifdef _WIN32
std::replace(ret.begin(), ret.end(), '/', '\\');
#endif
Expand Down
Loading