[mlpack-git] master: use WINDOWS_EXPORT_ALL_SYMBOLS (6f9a29c)

gitdub at mlpack.org gitdub at mlpack.org
Sat Apr 16 07:22:59 EDT 2016


Repository : https://github.com/mlpack/mlpack
On branch  : master
Link       : https://github.com/mlpack/mlpack/compare/213a04d31645134b61aa7d3702360bb34796d7de...aa7e51352127e809c9be9c1ec5cd94cb35f2fbd3

>---------------------------------------------------------------

commit 6f9a29c60ad8430c4c76088979c5cc559c7a4151
Author: Michel Zou <xantares09 at hotmail.com>
Date:   Fri Apr 15 22:36:03 2016 +0200

    use WINDOWS_EXPORT_ALL_SYMBOLS


>---------------------------------------------------------------

6f9a29c60ad8430c4c76088979c5cc559c7a4151
 CMakeLists.txt                  |  1 +
 src/mlpack/CMakeLists.txt       | 21 +++++++++++++--------
 src/mlpack/core/math/random.cpp |  7 ++++---
 src/mlpack/core/math/random.hpp |  8 +++++---
 src/mlpack/core/util/log.hpp    | 12 +++++++-----
 5 files changed, 30 insertions(+), 19 deletions(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 64ff308..2c101b0 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -11,6 +11,7 @@ enable_cxx11()
 
 # First, define all the compilation options.
 # We default to debugging mode for developers.
+option(BUILD_SHARED_LIBS "Shared/static libs" ON)
 option(DEBUG "Compile with debugging information" ON)
 option(PROFILE "Compile with profiling information" ON)
 option(ARMA_EXTRA_DEBUG "Compile with extra Armadillo debugging symbols." OFF)
diff --git a/src/mlpack/CMakeLists.txt b/src/mlpack/CMakeLists.txt
index 64b5111..8a7fc73 100644
--- a/src/mlpack/CMakeLists.txt
+++ b/src/mlpack/CMakeLists.txt
@@ -1,4 +1,5 @@
 include_directories(..) # <mlpack/[whatever]>
+include_directories(${CMAKE_CURRENT_BINARY_DIR}) # mlpack_export.h
 
 # Add core.hpp to list of sources.
 set(MLPACK_SRCS ${MLPACK_SRCS} "${CMAKE_CURRENT_SOURCE_DIR}/core.hpp")
@@ -19,14 +20,15 @@ if (BUILD_TESTS)
 endif ()
 
 # MLPACK_SRCS is set in the subdirectories.
-# We don't use a DLL (shared) on Windows because it's a nightmare.  We can't
-# easily generate the .def file and we won't put __declspec(dllexport) next to
-# every function signature.
-if (WIN32)
-  add_library(mlpack ${MLPACK_SRCS})
-else ()
-  add_library(mlpack SHARED ${MLPACK_SRCS})
+add_library(mlpack ${MLPACK_SRCS})
+
+set_target_properties(mlpack PROPERTIES WINDOWS_EXPORT_ALL_SYMBOLS ON)
+include(GenerateExportHeader)
+generate_export_header(mlpack)
+if (NOT BUILD_SHARED_LIBS)
+  add_definitions(-DMLPACK_STATIC_DEFINE)
 endif ()
+
 target_link_libraries(mlpack
   ${ARMADILLO_LIBRARIES}
   ${Boost_LIBRARIES}
@@ -63,7 +65,10 @@ add_custom_target(mlpack_headers)
 add_custom_command(TARGET mlpack_headers POST_BUILD
   COMMENT "Moving header files to include/mlpack/"
   COMMAND ${CMAKE_COMMAND} ARGS -E
-    make_directory ${CMAKE_BINARY_DIR}/include/mlpack/)
+    make_directory ${CMAKE_BINARY_DIR}/include/mlpack/
+  COMMAND ${CMAKE_COMMAND} ARGS -E
+    copy ${CMAKE_CURRENT_BINARY_DIR}/mlpack_export.h
+         ${CMAKE_BINARY_DIR}/include/mlpack)
 
 # Then copy each of the header files over to that directory.
 foreach(incl_file ${INCLUDE_FILES})
diff --git a/src/mlpack/core/math/random.cpp b/src/mlpack/core/math/random.cpp
index 8fc4c2e..cb56baf 100644
--- a/src/mlpack/core/math/random.cpp
+++ b/src/mlpack/core/math/random.cpp
@@ -4,16 +4,17 @@
  * Declarations of global random number generators.
  */
 #include <random>
+#include <mlpack_export.h>
 
 namespace mlpack {
 namespace math {
 
 // Global random object.
-std::mt19937 randGen;
+MLPACK_EXPORT std::mt19937 randGen;
 // Global uniform distribution.
-std::uniform_real_distribution<> randUniformDist(0.0, 1.0);
+MLPACK_EXPORT std::uniform_real_distribution<> randUniformDist(0.0, 1.0);
 // Global normal distribution.
-std::normal_distribution<> randNormalDist(0.0, 1.0);
+MLPACK_EXPORT std::normal_distribution<> randNormalDist(0.0, 1.0);
 
 } // namespace math
 } // namespace mlpack
diff --git a/src/mlpack/core/math/random.hpp b/src/mlpack/core/math/random.hpp
index f0c3e8d..03c274f 100644
--- a/src/mlpack/core/math/random.hpp
+++ b/src/mlpack/core/math/random.hpp
@@ -6,6 +6,8 @@
 #ifndef MLPACK_CORE_MATH_RANDOM_HPP
 #define MLPACK_CORE_MATH_RANDOM_HPP
 
+#include <mlpack_export.h>
+
 #include <mlpack/prereqs.hpp>
 #include <random>
 
@@ -13,11 +15,11 @@ namespace mlpack {
 namespace math /** Miscellaneous math routines. */ {
 
 // Global random object.
-extern std::mt19937 randGen;
+extern MLPACK_EXPORT std::mt19937 randGen;
 // Global uniform distribution.
-extern std::uniform_real_distribution<> randUniformDist;
+extern MLPACK_EXPORT std::uniform_real_distribution<> randUniformDist;
 // Global normal distribution.
-extern std::normal_distribution<> randNormalDist;
+extern MLPACK_EXPORT std::normal_distribution<> randNormalDist;
 
 /**
  * Set the random seed used by the random functions (Random() and RandInt()).
diff --git a/src/mlpack/core/util/log.hpp b/src/mlpack/core/util/log.hpp
index 7c40d35..1db69ed 100644
--- a/src/mlpack/core/util/log.hpp
+++ b/src/mlpack/core/util/log.hpp
@@ -9,6 +9,8 @@
 
 #include <string>
 
+#include <mlpack_export.h>
+
 #include "prefixedoutstream.hpp"
 #include "nulloutstream.hpp"
 
@@ -63,21 +65,21 @@ class Log
   // symbols.
 #ifdef DEBUG
   //! Prints debug output with the appropriate tag: [DEBUG].
-  static util::PrefixedOutStream Debug;
+  static MLPACK_EXPORT util::PrefixedOutStream Debug;
 #else
   //! Dumps debug output into the bit nether regions.
-  static util::NullOutStream Debug;
+  static MLPACK_EXPORT util::NullOutStream Debug;
 #endif
 
   //! Prints informational messages if --verbose is specified, prefixed with
   //! [INFO ].
-  static util::PrefixedOutStream Info;
+  static MLPACK_EXPORT util::PrefixedOutStream Info;
 
   //! Prints warning messages prefixed with [WARN ].
-  static util::PrefixedOutStream Warn;
+  static MLPACK_EXPORT util::PrefixedOutStream Warn;
 
   //! Prints fatal messages prefixed with [FATAL], then terminates the program.
-  static util::PrefixedOutStream Fatal;
+  static MLPACK_EXPORT util::PrefixedOutStream Fatal;
 
   //! Reference to cout, if necessary.
   static std::ostream& cout;




More information about the mlpack-git mailing list