[mlpack-git] master: Gather all library dependencies in one place. (504c5e6)

gitdub at mlpack.org gitdub at mlpack.org
Tue Sep 13 10:52:29 EDT 2016


Repository : https://github.com/mlpack/mlpack
On branch  : master
Link       : https://github.com/mlpack/mlpack/compare/12a10f428c07dd409d52684932655842a8eddb29...8d6d3919faf8596778b6db8c8865262fec9c394b

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

commit 504c5e6a4d9c514a93a3960fab75e0b9d4202274
Author: Ryan Curtin <ryan at ratml.org>
Date:   Tue Sep 13 10:52:29 2016 -0400

    Gather all library dependencies in one place.


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

504c5e6a4d9c514a93a3960fab75e0b9d4202274
 CMakeLists.txt            | 21 +++++++++++++++++----
 src/mlpack/CMakeLists.txt | 13 +++----------
 2 files changed, 20 insertions(+), 14 deletions(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index b7bf2e6..ffab60a 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -65,8 +65,14 @@ if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
   set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -lm")
   set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -lm")
   set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} -lm")
+  set(MLPACK_LIBRARIES ${MLPACK_LIBRARIES} "m")
 endif()
 
+# For clock_gettime().
+if (UNIX AND NOT APPLE)
+  set(MLPACK_LIBRARIES ${MLPACK_LIBRARIES} "rt")
+endif ()
+
 # Debugging CFLAGS.  Turn optimizations off; turn debugging symbols on.
 if(DEBUG)
   add_definitions(-DDEBUG)
@@ -79,8 +85,10 @@ if(DEBUG)
     find_package(LibDL)
     if(LIBBFD_FOUND AND LIBDL_FOUND)
       set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -rdynamic")
-      include_directories(${LIBBFD_INCLUDE_DIRS})
-      include_directories(${LIBDL_INCLUDE_DIRS})
+      set(MLPACK_INCLUDE_DIRS ${MLPACK_INCLUDE_DIRS} ${LIBBFD_INCLUDE_DIRS}
+          ${LIBDL_INCLUDE_DIRS})
+      set(MLPACK_LIBRARIES ${MLPACK_LIBRARIES} ${LIBBFD_LIBRARIES}
+          ${LIBDL_LIBRARIES})
       add_definitions(-DHAS_BFD_DL)
     else()
       message(WARNING "No libBFD and/or libDL has been found!")
@@ -194,7 +202,8 @@ if (WIN32)
 endif ()
 
 # Include directories for the previous dependencies.
-include_directories(${ARMADILLO_INCLUDE_DIRS})
+set(MLPACK_INCLUDE_DIRS ${MLPACK_INCLUDE_DIRS} ${ARMADILLO_INCLUDE_DIRS})
+set(MLPACK_LIBRARIES ${MLPACK_LIBRARIES} ${ARMADILLO_LIBRARIES})
 
 # Unfortunately this configuration variable is necessary and will need to be
 # updated as time goes on and new versions are released.
@@ -207,7 +216,6 @@ find_package(Boost 1.49
       serialization
     REQUIRED
 )
-include_directories(${Boost_INCLUDE_DIRS})
 
 link_directories(${Boost_LIBRARY_DIRS})
 
@@ -219,6 +227,10 @@ if (MSVC)
   set(Boost_LIBRARIES "")
 endif ()
 
+set(MLPACK_INCLUDE_DIRS ${MLPACK_INCLUDE_DIRS} ${Boost_INCLUDE_DIRS})
+set(MLPACK_LIBRARIES ${MLPACK_LIBRARIES} ${Boost_LIBRARIES})
+set(MLPACK_LIBRARY_DIRS ${MLPACK_LIBRARY_DIRS} ${Boost_LIBRARY_DIRS})
+
 # For Boost testing framework (will have no effect on non-testing executables).
 # This specifies to Boost that we are dynamically linking to the Boost test
 # library.
@@ -237,6 +249,7 @@ endif ()
 include(CMake/TargetDistclean.cmake OPTIONAL)
 
 include_directories(${CMAKE_SOURCE_DIR})
+include_directories(${MLPACK_INCLUDE_DIRS})
 
 # On Windows, things end up under Debug/ or Release/.
 if (WIN32)
diff --git a/src/mlpack/CMakeLists.txt b/src/mlpack/CMakeLists.txt
index a283c6b..73f7e88 100644
--- a/src/mlpack/CMakeLists.txt
+++ b/src/mlpack/CMakeLists.txt
@@ -19,7 +19,8 @@ if (BUILD_TESTS)
   add_subdirectory(tests)
 endif ()
 
-# MLPACK_SRCS is set in the subdirectories.
+# MLPACK_SRCS is set in the subdirectories.  The dependencies (MLPACK_LIBRARIES)
+# are set in the root CMakeLists.txt.
 add_library(mlpack ${MLPACK_SRCS})
 
 # Generate export symbols for Windows, instead of adding __declspec(dllimport)
@@ -33,21 +34,13 @@ if (NOT BUILD_SHARED_LIBS)
 endif ()
 
 target_link_libraries(mlpack
-  ${ARMADILLO_LIBRARIES}
-  ${Boost_LIBRARIES}
-)
+  ${MLPACK_LIBRARIES})
 set_target_properties(mlpack
   PROPERTIES
   VERSION 2.0
   SOVERSION 2
 )
 
-# Make sure the linker can find the needed library.
-# rt: clock_gettime()
-if(UNIX AND NOT APPLE)
-    target_link_libraries(mlpack rt)
-endif()
-
 # Backtrace for Linux need those libs.
 if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
   if(LIBBFD_FOUND AND LIBDL_FOUND AND DEBUG)




More information about the mlpack-git mailing list