Skip to content

Commit 89ce414

Browse files
committed
Reworked driver install patch.
1 parent 113352d commit 89ce414

File tree

7 files changed

+88
-86
lines changed

7 files changed

+88
-86
lines changed

CMakeLists.txt

+1-8
Original file line numberDiff line numberDiff line change
@@ -161,14 +161,7 @@ set(JPEGDIR "" CACHE PATH "GDL: Specify the JPEG directory tree")
161161
set(SZIPDIR "" CACHE PATH "GDL: Specify the SZip directory tree")
162162

163163
set(GDL_DATA_DIR "/share/gnudatalanguage" CACHE PATH "GDL: data directory relative to CMAKE_INSTALL_PREFIX")
164-
set(GDL_LIB_DIR "" CACHE PATH "GDL: library directory relative to CMAKE_INSTALL_PREFIX")
165-
#define (for plplotdriver/CMakeLists.txt) the GDL_DRV_DIR where the drivers will be installed.
166-
#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)
167-
if ( GDL_LIB_DIR STREQUAL "" OR NOT GDL_LIB_DIR)
168-
set (GDL_DRV_DIR "${CMAKE_INSTALL_PREFIX}/${GDL_DATA_DIR}/drivers") # CACHE PATH "GDL: where the drivers will be installed.")
169-
else()
170-
set (GDL_DRV_DIR "${CMAKE_INSTALL_PREFIX}/${GDL_LIB_DIR}" ) # CACHE PATH "GDL: where the drivers will be installed.")
171-
endif()
164+
set(GDL_LIB_DIR "/lib/gnudatalanguage" CACHE PATH "GDL: library directory relative to CMAKE_INSTALL_PREFIX")
172165
# check for 64-bit OS
173166
if(${CMAKE_SIZEOF_VOID_P} EQUAL 8)
174167
set(HAVE_64BIT_OS 1)

INSTALL.CMake

+3
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ Other options include:
4141
- GDL_DATA_DIR (default: /share/gnudatalanguage) to specify
4242
a custom installation location for GDL files
4343
(a subdirectory of the main installation prefix)
44+
- GDL_LIB_DIR (default: /lib/gnudatalanguage) to specify
45+
a custom installation location for local PlPlot driver files
46+
(a subdirectory of the main installation prefix)
4447

4548
The list of all GDL-related options accepted by CMake along
4649
with their default values can be obtained by calling:

config.h.cmake

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
#ifndef __CONFIG_H__
22
#define __CONFIG_H__
33

4-
#define EXEC_PREFIX "@CMAKE_INSTALL_PREFIX@"
5-
#define GDLDATADIR "@CMAKE_INSTALL_PREFIX@@GDL_DATA_DIR@"
6-
#define GDLLIBDIR "@CMAKE_INSTALL_PREFIX@@GDL_LIB_DIR@"
7-
#define GDL_DRV_DIR "@GDL_DRV_DIR@"
4+
#cmakedefine GDL_DATA_DIR "@GDL_DATA_DIR@"
5+
#cmakedefine GDL_LIB_DIR "@GDL_LIB_DIR@"
86

97
#define _CRT_SECURE_NO_WARNINGS
108

src/gdl.cpp

+25-26
Original file line numberDiff line numberDiff line change
@@ -224,15 +224,15 @@ namespace MyPaths {
224224
if (length > 0)
225225
{
226226
path = (char*)malloc(length + 1);
227-
if (!path) return std::string(".");
227+
if (!path) return {"."};
228228
wai_getExecutablePath(path, length, &dirname_length);
229229
path[dirname_length] = '\0';
230230
// printf(" dirname: %s\n", path);
231231
std::string pathstring(path);
232232
free(path);
233233
return pathstring;
234234
}
235-
return std::string(".");
235+
return {"."};
236236
}
237237
}
238238

@@ -243,38 +243,37 @@ int main(int argc, char *argv[])
243243
bool quiet = false;
244244
bool gdlde = false;
245245

246-
//The default installation location --- will not always be there.
247-
gdlDataDir = std::string(GDLDATADIR);
248-
gdlLibDir = std::string(GDLLIBDIR);
246+
// The default installation location --- will not always be there.
247+
gdlDataDir = std::string(GDL_DATA_DIR);
248+
gdlLibDir = std::string(GDL_LIB_DIR);
249249
#ifdef _WIN32
250250
std::replace(gdlDataDir.begin(), gdlDataDir.end(), '/', '\\');
251251
std::replace(gdlLibDir.begin(), gdlLibDir.end(), '/', '\\');
252-
#endif
252+
#endif
253+
// make sure dirs are prefixed with the system's path separator
254+
if (gdlDataDir.at(0) != lib::PathSeparator()) gdlDataDir.assign(lib::PathSeparator() + gdlDataDir);
255+
if (gdlLibDir.at(0) != lib::PathSeparator()) gdlLibDir.assign(lib::PathSeparator() + gdlLibDir);
253256

254257
//check where is the executable being run
255-
std::string whereami=MyPaths::getExecutablePath();
256-
// 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.
257-
// if not, then I'm probably just a 'build' gdl and my ressources may (should?) be in the default location GDLDATADIR
258-
std::size_t pos=whereami.rfind("bin");
259-
if (pos == whereami.size()-3) { //we are the installed gdl!
260-
gdlDataDir.assign( whereami+ lib::PathSeparator() + ".." + lib::PathSeparator() + "share" + lib::PathSeparator() + "gnudatalanguage") ;
261-
// std::cerr<<"installed at: "<<gdlDataDir<<std::endl;
258+
auto whereami = MyPaths::getExecutablePath();
259+
// 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.
260+
// if not, then I'm probably just a 'build' gdl and my resources may (should?) be in the default location GDL_DATA_DIR
261+
auto pos = whereami.rfind("bin");
262+
if (pos != std::string::npos) { // we are the installed gdl!
263+
// use pos - 1, so we remove the path separator, too
264+
gdlDataDir.assign(whereami.substr(0, pos - 1) + gdlDataDir);
265+
gdlLibDir.assign(whereami.substr(0, pos - 1) + gdlLibDir);
262266
}
263267

264268
//PATH. This one is often modified by people before starting GDL.
265-
string gdlPath=GetEnvPathString("GDL_PATH"); //warning: is a Path, use system separator.
266-
if( gdlPath == "") gdlPath=GetEnvString("IDL_PATH"); //warning: is a Path, use system separator.
267-
if( gdlPath == "") gdlPath = gdlDataDir + lib::PathSeparator() + "lib";
268-
269-
//LIBDIR. Can be '' in which case the location of drivers is deduced from the location of
270-
//the executable (OSX, Windows, unix in user-installed mode).
271-
string driversPath = GetEnvPathString("GDL_DRV_DIR");
272-
if (driversPath == "") { //NOT enforced by GDL_DRV_DIR
273-
driversPath = gdlLibDir; //e.g. Fedora
274-
if (driversPath == "") { //NOT enforced by GDLLIBDIR at build : not a distro
275-
driversPath = gdlDataDir + lib::PathSeparator() + "drivers"; //deduced from the location of the executable
276-
}
277-
}
269+
auto gdlPath = GetEnvPathString("GDL_PATH");
270+
if( gdlPath.empty()) gdlPath = GetEnvPathString("IDL_PATH");
271+
if( gdlPath.empty()) gdlPath = gdlDataDir + lib::PathSeparator() + "lib";
272+
273+
auto driversPath = GetEnvPathString("GDL_DRV_DIR");
274+
// use the identical approach already used for figuring out the path to out *.pro files etc.
275+
if (driversPath.empty()) driversPath = gdlLibDir;
276+
278277
//drivers if local
279278
useLocalDrivers=false;
280279
bool driversNotFound=false;

src/plplotdriver/CMakeLists.txt

+47-35
Original file line numberDiff line numberDiff line change
@@ -5,40 +5,52 @@ if(INSTALL_LOCAL_DRIVERS)
55

66
#these drivers are always present
77
list(APPEND WHAT "ps" "svg" "mem")
8-
list(APPEND WHATFILES "mem.driver_info" "svg.driver_info" "ps.driver_info")
98
add_library(ps MODULE ps.c)
10-
target_link_libraries(
11-
ps
12-
${PLPLOT_LIBRARIES}
13-
)
9+
# Copy thr driver info file after building the target so we can use the build-dir directly when testing
10+
add_custom_command(
11+
TARGET ps POST_BUILD
12+
COMMAND ${CMAKE_COMMAND} -E copy
13+
${CMAKE_SOURCE_DIR}/src/plplotdriver/ps.driver_info
14+
${CMAKE_CURRENT_BINARY_DIR}/ps.driver_info
15+
)
16+
target_link_libraries(ps ${PLPLOT_LIBRARIES})
1417
add_library(svg MODULE svg.c)
15-
target_link_libraries(
16-
svg
17-
${PLPLOT_LIBRARIES}
18-
)
18+
# Copy thr driver info file after building the target so we can use the build-dir directly when testing
19+
add_custom_command(
20+
TARGET svg POST_BUILD
21+
COMMAND ${CMAKE_COMMAND} -E copy
22+
${CMAKE_SOURCE_DIR}/src/plplotdriver/svg.driver_info
23+
${CMAKE_CURRENT_BINARY_DIR}/svg.driver_info
24+
)
25+
target_link_libraries(svg ${PLPLOT_LIBRARIES})
1926
add_library(mem MODULE mem.c)
20-
target_link_libraries(
21-
mem
22-
${PLPLOT_LIBRARIES}
23-
)
27+
# Copy thr driver info file after building the target so we can use the build-dir directly when testing
28+
add_custom_command(
29+
TARGET mem POST_BUILD
30+
COMMAND ${CMAKE_COMMAND} -E copy
31+
${CMAKE_SOURCE_DIR}/src/plplotdriver/mem.driver_info
32+
${CMAKE_CURRENT_BINARY_DIR}/mem.driver_info
33+
)
34+
target_link_libraries(mem ${PLPLOT_LIBRARIES})
2435

2536
#driver wxwidgets
2637
if (HAVE_LIBWXWIDGETS)
2738
set(LINK_DIRECTORIES ${LINK_DIRECTORIES} ${wxWidgets_LIBRARY_DIRS})
2839
foreach(WXDEF ${wxWidgets_DEFINITIONS})
29-
add_definitions(-D${WXDEF})
40+
add_definitions(-D${WXDEF})
3041
endforeach(WXDEF ${wxWidgets_DEFINITIONS})
3142
include_directories( ${wxWidgets_INCLUDE_DIRS})
3243
add_library(wxwidgets MODULE deprecated_wxwidgets.cpp deprecated_wxwidgets_app.cpp deprecated_wxwidgets_dc.cpp deprecated_wxwidgets_gc.cpp)
33-
target_link_libraries(
34-
wxwidgets
35-
${PLPLOT_LIBRARIES}
36-
${wxWidgets_LIBRARIES}
37-
)
38-
list(APPEND WHAT "wxwidgets")
39-
list(APPEND WHATFILES "wxwidgets.driver_info")
40-
endif(HAVE_LIBWXWIDGETS)
41-
44+
# Copy thr driver info file after building the target so we can use the build-dir directly when testing
45+
add_custom_command(
46+
TARGET wxwidgets POST_BUILD
47+
COMMAND ${CMAKE_COMMAND} -E copy
48+
${CMAKE_SOURCE_DIR}/src/plplotdriver/wxwidgets.driver_info
49+
${CMAKE_CURRENT_BINARY_DIR}/wxwidgets.driver_info
50+
)
51+
target_link_libraries(wxwidgets ${PLPLOT_LIBRARIES} ${wxWidgets_LIBRARIES})
52+
list(APPEND WHAT "wxwidgets")
53+
endif(HAVE_LIBWXWIDGETS)
4254

4355
# driver xwin -- check if X11 is present
4456
find_package(X11 QUIET)
@@ -47,27 +59,27 @@ if(INSTALL_LOCAL_DRIVERS)
4759
set(LIBRARIES ${LIBRARIES} ${X11_LIBRARIES})
4860
include_directories(${X11_INCLUDE_DIR})
4961
add_library(xwin MODULE xwin.c)
50-
target_link_libraries(
51-
xwin
52-
${PLPLOT_LIBRARIES}
53-
${X11_LIBRARIES}
54-
)
55-
list (APPEND WHAT "xwin")
56-
list(APPEND WHATFILES "wxin.driver_info")
62+
# Copy thr driver info file after building the target so we can use the build-dir directly when testing
63+
add_custom_command(
64+
TARGET xwin POST_BUILD
65+
COMMAND ${CMAKE_COMMAND} -E copy
66+
${CMAKE_SOURCE_DIR}/src/plplotdriver/xwin.driver_info
67+
${CMAKE_CURRENT_BINARY_DIR}/xwin.driver_info
68+
)
69+
target_link_libraries(xwin ${PLPLOT_LIBRARIES} ${X11_LIBRARIES})
70+
list(APPEND WHAT "xwin")
5771
endif(X11_FOUND)
5872

59-
60-
6173
if(WIN32)
6274
set(DYNAMIC_SUFFIX ".dll")
6375
else(WIN32)
6476
set(DYNAMIC_SUFFIX ".so")
6577
endif(WIN32)
6678

6779
foreach(v IN LISTS WHAT)
68-
set_target_properties(${v} PROPERTIES PREFIX "" SUFFIX ${DYNAMIC_SUFFIX} )
69-
install(TARGETS ${v} DESTINATION ${GDL_DRV_DIR})
70-
install( FILES ${v}.driver_info DESTINATION ${GDL_DRV_DIR})
80+
set_target_properties(${v} PROPERTIES PREFIX "" SUFFIX ${DYNAMIC_SUFFIX} )
81+
install(TARGETS ${v} DESTINATION ${CMAKE_INSTALL_PREFIX}/${GDL_LIB_DIR})
82+
install(FILES ${v}.driver_info DESTINATION ${CMAKE_INSTALL_PREFIX}/${GDL_LIB_DIR})
7183
endforeach()
7284

7385
endif(INSTALL_LOCAL_DRIVERS)

src/pythongdl.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -585,7 +585,7 @@ extern "C" {
585585
// if( gdlPath == "") gdlPath=GetEnvString("IDL_PATH");
586586
// if( gdlPath == "")
587587
// {
588-
// gdlPath = "+" GDLDATADIR "/lib";
588+
// gdlPath = "+" GDL_DATA_DIR "/lib";
589589
// }
590590
// SysVar::SetGDLPath( gdlPath);
591591

src/str.cpp

+9-12
Original file line numberDiff line numberDiff line change
@@ -45,25 +45,25 @@ namespace lib {
4545
std::string PathSeparator()
4646
{
4747
#ifdef _WIN32
48-
if (lib::posixpaths) return std::string ("/");
49-
return std::string ("\\");
48+
if (lib::posixpaths) return {"/"};
49+
return {"\\"};
5050
#else
51-
return std::string ("/");
51+
return {"/"};
5252
#endif
5353
}
5454

5555
std::string SearchPathSeparator()
5656
{
5757
#ifdef _WIN32
58-
return std::string (";");
58+
return {";"};
5959
#else
60-
return std::string (":");
60+
return {":"};
6161
#endif
6262
}
6363

6464
std::string ParentDirectoryIndicator()
6565
{
66-
return std::string ("..");
66+
return {".."};
6767
}
6868
}
6969
//using namespace std;
@@ -73,16 +73,13 @@ namespace lib {
7373
std::string GetEnvString(const char* env)
7474
{
7575
char* c=getenv(env);
76-
if( !c) return std::string("");
77-
return std::string(c);
76+
if( !c) return {""};
77+
return {c};
7878
}
7979
//same but for a path: separator will be '\' for _WIN32
8080
std::string GetEnvPathString(const char* env)
8181
{
82-
std::string ret("");
83-
char* c=getenv(env);
84-
if( !c) return ret;
85-
ret=std::string(c);
82+
std::string ret = GetEnvString(env);
8683
#ifdef _WIN32
8784
std::replace(ret.begin(), ret.end(), '/', '\\');
8885
#endif

0 commit comments

Comments
 (0)