From b339c12d199098543d3fa77bf0f10f1d60346984 Mon Sep 17 00:00:00 2001
From: Thomas Moulard <thomas.moulard@gmail.com>
Date: Wed, 13 Oct 2010 18:29:15 +0200
Subject: [PATCH] Fix import directive (default include path was wrong).

---
 include/CMakeLists.txt                        | 37 ++++++++++++++++---
 .../import-default-paths.h.cmake              |  2 +-
 src/CMakeLists.txt                            |  3 +-
 src/dgraph/import.cpp                         | 10 +++++
 4 files changed, 44 insertions(+), 8 deletions(-)

diff --git a/include/CMakeLists.txt b/include/CMakeLists.txt
index 6a8d219e..008cc9f4 100644
--- a/include/CMakeLists.txt
+++ b/include/CMakeLists.txt
@@ -1,8 +1,34 @@
-# Generate header with default script directory.
-SET(DG_IMPORT_DEFAULT_PATHS \"${CMAKE_INSTALL_PREFIX}/script\")
-CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/${PROJECT_NAME}/import-default-paths.h.cmake
-		       ${CMAKE_CURRENT_SOURCE_DIR}/${PROJECT_NAME}/import-default-paths.h)
+# Copyright 2010, Olivier Stasse, JRL, CNRS/AIST
+#
+# This file is part of dynamic-graph.
+# dynamic-graph is free software: you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public License
+# as published by the Free Software Foundation, either version 3 of
+# the License, or (at your option) any later version.
+#
+# dynamic-graph is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# General Lesser Public License for more details.  You should have
+# received a copy of the GNU Lesser General Public License along with
+# dynamic-graph. If not, see <http://www.gnu.org/licenses/>.
 
+# Add default script directory.
+#  It is used by the import directive of the sot shell to locate
+#  scripts.
+SET(DG_IMPORT_DEFAULT_PATHS
+	"${CMAKE_INSTALL_PREFIX}/share/dynamic-graph/script")
+
+CONFIGURE_FILE(
+	${PROJECT_NAME}/import-default-paths.h.cmake	
+	${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}/import-default-paths.h)
+INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}/import-default-paths.h
+       DESTINATION include/${PROJECT_NAME}
+       PERMISSIONS OWNER_READ GROUP_READ WORLD_READ OWNER_WRITE
+)
+
+
+# Headers list.
 SET(${PROJECT_NAME}_HEADERS
 contiifstream.h
 debug.h
@@ -16,7 +42,6 @@ interpreter-helper.h
 plugin-loader.h
 pool.h
 import.h
-import-default-paths.h
 
 exception-abstract.h
 exception-factory.h
@@ -60,4 +85,4 @@ ENDFOREACH(lHeader)
 INSTALL(FILES ${fullpath_${PROJECT_NAME}_HEADERS}
        DESTINATION include/${PROJECT_NAME}
        PERMISSIONS OWNER_READ GROUP_READ WORLD_READ OWNER_WRITE
-)
\ No newline at end of file
+)
diff --git a/include/dynamic-graph/import-default-paths.h.cmake b/include/dynamic-graph/import-default-paths.h.cmake
index 5b26156c..40184cf8 100644
--- a/include/dynamic-graph/import-default-paths.h.cmake
+++ b/include/dynamic-graph/import-default-paths.h.cmake
@@ -23,6 +23,6 @@
 # define DG_FACTORY_COMMAND_IMPORT_DEFAULT_PATHS_H
 
 /// Default script path as known by CMake at configure time.
-# define DG_IMPORT_DEFAULT_PATHS @DG_IMPORT_DEFAULT_PATHS@
+# define DG_IMPORT_DEFAULT_PATHS "@DG_IMPORT_DEFAULT_PATHS@"
 
 #endif //! SOT_FACTORY_COMMAND_IMPORT_DEFAULT_PATHS_H
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 26c3c3f2..0cb4a49d 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -5,6 +5,7 @@ SET(LIBRARY_NAME ${PROJECT_NAME})
 
 INCLUDE_DIRECTORIES(
 	${CMAKE_CURRENT_SOURCE_DIR}/../include
+	${CMAKE_CURRENT_BINARY_DIR}/../include
 )
 
 # Verbosity level
@@ -86,4 +87,4 @@ SET_TARGET_PROPERTIES(${plugin}
 
 INSTALL(TARGETS ${plugin}
 		DESTINATION lib/plugin)
-ENDFOREACH(plugin_file)
\ No newline at end of file
+ENDFOREACH(plugin_file)
diff --git a/src/dgraph/import.cpp b/src/dgraph/import.cpp
index 111d7b5d..e355e38f 100644
--- a/src/dgraph/import.cpp
+++ b/src/dgraph/import.cpp
@@ -37,6 +37,14 @@
 #include <dynamic-graph/exception-factory.h>
 #include <dynamic-graph/interpreter.h>
 
+// The default import paths has to be passed from the build system
+// as a -D flag for instance.
+// It contains the absolute path to the default directory where
+// the scripts will be searched.
+#ifndef DG_IMPORT_DEFAULT_PATHS
+# error "Default import path is not defined."
+#endif //! DG_IMPORT_DEFAULT_PATHS
+
 static const char* ENV_DG_PATH = "DG_PATH";
 
 namespace dynamicgraph
@@ -182,6 +190,7 @@ namespace dynamicgraph
 	    ("failed to import module ``%1%'' (import paths: %2%).");
 	  fmt % module;
 	  fmt % scriptDirectories;
+	  std::cout << fmt.str () << std::endl;
 	  DG_THROW ExceptionFactory
 	    (ExceptionFactory::READ_FILE, fmt.str ());
 	  return;
@@ -222,6 +231,7 @@ namespace dynamicgraph
 	  boost::format fmt (" (in line %1% of file ``%2%'')");
 	  fmt % lineIdx % filename;
 	  msg = msg + fmt.str();
+	  std::cout << msg << std::endl;
 	  throw;
 	}
 
-- 
GitLab