From: Ole Streicher <olebole@debian.org>
Date: Sun, 24 Jan 2016 12:00:00 +0000
Subject: Create a shared library

Create a shared library to link to gdl executable and Python extension
The library is called libgnudatalanguage.so to avoid confusion with the
libgdl from the GNOME project.

Forwarded: https://sourceforge.net/p/gnudatalanguage/patches/95/
---
 CMakeLists.txt                |  4 +---
 src/CMakeLists.txt            | 42 ++++++++++++++++++++++++------------------
 src/plplot/src/CMakeLists.txt |  7 +------
 src/pythongdl.cpp             | 10 ++++++++++
 4 files changed, 36 insertions(+), 27 deletions(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 47d2ab2..1b2d5ae 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -984,9 +984,7 @@ if (TARGET version)
   add_dependencies(gdl version)
 endif()
 
-if(NOT PYTHON_MODULE)
-    add_subdirectory(testsuite)
-endif(NOT PYTHON_MODULE)
+add_subdirectory(testsuite)
 
 install(FILES ${CMAKE_SOURCE_DIR}/AUTHORS ${CMAKE_SOURCE_DIR}/README DESTINATION ${CMAKE_INSTALL_PREFIX}/${GDL_DATA_DIR})
 install(FILES ${CMAKE_SOURCE_DIR}/doc/gdl.1 DESTINATION ${CMAKE_INSTALL_PREFIX}/share/man/man1)
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 6da60fc..565db8b 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -221,31 +221,37 @@ add_subdirectory(plplot)
 include_directories(${CMAKE_SOURCE_DIR} ${CMAKE_SOURCE_DIR}/src ${CMAKE_SOURCE_DIR}/src/antlr ${CMAKE_BINARY_DIR}/src ${CMAKE_SOURCE_DIR}/src/whereami/src ${CMAKE_BINARY_DIR})
 link_directories(${LINK_DIRECTORIES})
 
+add_library(gnudatalanguage SHARED ${SOURCES})
+SET_TARGET_PROPERTIES(gnudatalanguage PROPERTIES SOVERSION 0)
 if(PYTHON_MODULE) #GDL.so
-	add_library(gdl SHARED ${SOURCES})
-	SET_TARGET_PROPERTIES(gdl PROPERTIES PREFIX "")
-	SET_TARGET_PROPERTIES(gdl PROPERTIES OUTPUT_NAME GDL)
-	SET_TARGET_PROPERTIES(gdl PROPERTIES NO_SONAME TRUE)
-        SET_TARGET_PROPERTIES(gdl PROPERTIES SUFFIX ".so") # e.g. Mac defaults to .dylib which is not looked for by Python
-else(PYTHON_MODULE) #GDL.so
-	set(SOURCES ${SOURCES} gdl.cpp)
-	add_executable(gdl ${SOURCES})
+	add_library(pythongdl SHARED pythongdl.cpp)
+	SET_TARGET_PROPERTIES(pythongdl PROPERTIES PREFIX "")
+	SET_TARGET_PROPERTIES(pythongdl PROPERTIES OUTPUT_NAME GDL)
+	SET_TARGET_PROPERTIES(pythongdl PROPERTIES NO_SONAME TRUE)
+	target_link_libraries(pythongdl gnudatalanguage)
 endif(PYTHON_MODULE)
+add_executable(gdl gdl.cpp)
+target_link_libraries(gdl gnudatalanguage)
+if (OPENMP)
+	target_link_libraries(gdl -fopenmp)
+endif (OPENMP)
+if (READLINE)
+	target_link_libraries(gdl readline)
+endif (READLINE)
 
 if(USE_OPENMP)
 	set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
 endif(USE_OPENMP)
 
-add_dependencies(gdl plplot antlr whereami) # be sure that antlr is built before gdl
-target_link_libraries(gdl plplot antlr whereami) # link antlr against gdl. added librt for mmap (unix only, not osx, apparently)
+add_dependencies(gnudatalanguage plplot antlr whereami) # be sure that antlr is built before gdl
+target_link_libraries(gnudatalanguage plplot antlr whereami) # link antlr against gdl. added librt for mmap (unix only, not osx, apparently)
 if (MINGW)
-target_link_libraries(gdl ws2_32)
+target_link_libraries(gnudatalanguage ws2_32)
 endif (MINGW)
 if (NOT APPLE AND NOT OSX AND NOT MINGW)
-target_link_libraries(gdl rt) # link antlr against gdl. added librt for mmap (unix only, not osx, apparently)
+target_link_libraries(gnudatalanguage rt) # link antlr against gdl. added librt for mmap (unix only, not osx, apparently)
 endif (NOT APPLE AND NOT OSX AND NOT MINGW)
-
-target_link_libraries(gdl ${LIBRARIES})
+target_link_libraries(gnudatalanguage ${LIBRARIES})
 
 add_definitions(-DHAVE_CONFIG_H)
 
@@ -268,11 +274,11 @@ if(PYTHON_MODULE)
 	file( TO_CMAKE_PATH "${PYTHON_SITE_DIR}" PYTHON_SITE_DIR )
 	string( REGEX REPLACE "^${PYTHON_PREFIX}/" ""
 	       PYTHON_SITE_DIR "${PYTHON_SITE_DIR}")
-	install(TARGETS gdl DESTINATION ${PYTHON_SITE_DIR})
-else(PYTHON_MODULE)
-	install(TARGETS gdl DESTINATION ${CMAKE_INSTALL_PREFIX}/bin)
-	set_target_properties(gdl PROPERTIES INSTALL_RPATH_USE_LINK_PATH TRUE)
+	install(TARGETS pythongdl DESTINATION ${PYTHON_SITE_DIR})
 endif(PYTHON_MODULE)
+install(TARGETS gdl DESTINATION bin)
+set_target_properties(gdl PROPERTIES INSTALL_RPATH_USE_LINK_PATH TRUE)
+install(TARGETS gnudatalanguage DESTINATION lib)
 
 install(DIRECTORY ${CMAKE_SOURCE_DIR}/src/pro/ DESTINATION ${CMAKE_INSTALL_PREFIX}/${GDL_DATA_DIR}/lib
 	PATTERN CVS EXCLUDE
diff --git a/src/plplot/src/CMakeLists.txt b/src/plplot/src/CMakeLists.txt
index 2fa32ba..443bb25 100644
--- a/src/plplot/src/CMakeLists.txt
+++ b/src/plplot/src/CMakeLists.txt
@@ -176,9 +176,4 @@ message("pc_libplplot_COMPILE_FLAGS = ${pc_libplplot_COMPILE_FLAGS}")
 #aux_source_directory(${CMAKE_CURRENT_SOURCE_DIR} PLPLOTSOURCES)
 include_directories(${CMAKE_SOURCE_DIR} ${CMAKE_SOURCE_DIR}/src/plplot ${CMAKE_SOURCE_DIR}/src/plplot/include)
 
-if(PYTHON_MODULE)
-	add_library(plplot SHARED ${plplot_LIB_SRCS})
-	install(TARGETS plplot DESTINATION ${CMAKE_INSTALL_PREFIX}/lib)
-else(PYTHON_MODULE)
-	add_library(plplot STATIC ${plplot_LIB_SRCS})
-endif(PYTHON_MODULE)
+add_library(plplot STATIC ${plplot_LIB_SRCS})
diff --git a/src/pythongdl.cpp b/src/pythongdl.cpp
index b02fb75..833673d 100644
--- a/src/pythongdl.cpp
+++ b/src/pythongdl.cpp
@@ -44,6 +44,16 @@
 
 void LibInit(); // defined in libinit.cpp
 
+//initialize wxWidgets system
+#ifdef HAVE_LIBWXWIDGETS
+#include "gdlwidget.hpp"
+#ifndef __WXMAC__ 
+wxIMPLEMENT_APP_NO_MAIN( wxAppGDL);
+#else
+wxIMPLEMENT_APP_NO_MAIN( wxApp);
+#endif
+#endif
+
 using namespace std;
 
 // everything is executed within this interpreter
