[mlpack-git] master: Fix some comments, clean up how -lm is added too. (4c88348)

gitdub at mlpack.org gitdub at mlpack.org
Thu Jul 21 13:57:47 EDT 2016


Repository : https://github.com/mlpack/mlpack
On branch  : master
Link       : https://github.com/mlpack/mlpack/compare/82cf86500e8ad98b32db9fd9cceca4a844f4bb19...4c88348ddc9ad83940923f5253b902690673c4a3

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

commit 4c88348ddc9ad83940923f5253b902690673c4a3
Author: Ryan Curtin <ryan at ratml.org>
Date:   Thu Jul 21 13:57:47 2016 -0400

    Fix some comments, clean up how -lm is added too.


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

4c88348ddc9ad83940923f5253b902690673c4a3
 CMake/mlpack_coverage.in          | 32 ++++++++++++++++----------------
 CMakeLists.txt                    | 38 ++++++++++++++++++++++++--------------
 src/mlpack/CMakeLists.txt         |  1 +
 src/mlpack/methods/CMakeLists.txt |  1 +
 4 files changed, 42 insertions(+), 30 deletions(-)

diff --git a/CMake/mlpack_coverage.in b/CMake/mlpack_coverage.in
index 0d3710a..66aa034 100755
--- a/CMake/mlpack_coverage.in
+++ b/CMake/mlpack_coverage.in
@@ -1,5 +1,5 @@
 #!/bin/bash
-
+# This script gets the test coverage for mlpack_test.
 test_case="ALL"
 gcov_loc=""
 token=""
@@ -8,7 +8,7 @@ current_log_file=`date +'%Y.%h.%d:%H:%M:%S-coverage.log'`
 current_coverage_file=`date +'%Y.%h.%d:%H:%M:%S-coverage.info'`
 max_cov_count=50000
 
-# Extract arguments
+# Extract arguments.
 for i in "$@"
 do
 case $i in
@@ -61,12 +61,12 @@ if [ "$clean" = true ]; then
   find ./ -name "*.gcda" -type f -delete
 fi
 
-# initial pass
-echo "Generating primary coverage report"
+# Initial pass.
+echo "Generating primary coverage report."
 [[ -d ./coveragehistory/ ]] || mkdir coveragehistory
 lcov -b . -c -i -d ./ -o .coverage.wtest.base > ./coveragehistory/$current_log_file
 
-# Run the tests
+# Run the tests.
 if [ "$test_case" = "ALL" ]; then
   echo "Running all the tests..."
   @CMAKE_BINARY_DIR@/bin/mlpack_test
@@ -75,7 +75,7 @@ elif ! [ "$test_case" = "" ]; then
   @CMAKE_BINARY_DIR@/bin/mlpack_test --run_test=$test_case
 fi
 
-# Generate coverage based on executed tests
+# Generate coverage based on executed tests.
 echo "Computing coverage..."
 if [ "$gcov_loc" = "" ];
 then lcov -b . -c -d ./ -o .coverage.wtest.run >> ./coveragehistory/$current_log_file
@@ -84,41 +84,41 @@ else
 fi
 
 echo "Filtering coverage files..."
-# Merge coverage tracefiles
+# Merge coverage tracefiles.
 lcov -a .coverage.wtest.base -a .coverage.wtest.run  -o .coverage.total >> ./coveragehistory/$current_log_file
 
-# Filtering, extracting project files
+# Filtering, extracting project files.
 lcov -e .coverage.total "@CMAKE_CURRENT_SOURCE_DIR@/src/mlpack/*" -o .coverage.total.filtered >> ./coveragehistory/$current_log_file
 
-# Filtering, removing test-files and main.cpp
+# Filtering, removing test-files and main.cpp.
 lcov -r .coverage.total.filtered "@CMAKE_CURRENT_SOURCE_DIR@/src/mlpack/*/*_main.cpp" -o .coverage.total.filtered >> ./coveragehistory/$current_log_file
 lcov -r .coverage.total.filtered "@CMAKE_CURRENT_SOURCE_DIR@/src/mlpack/tests/*" -o .coverage.total.filtered >> ./coveragehistory/$current_log_file
 
-# Remove untestable files
+# Remove untestable files.
 lcov -r .coverage.total.filtered "@CMAKE_CURRENT_SOURCE_DIR@/src/mlpack/core/util/gitversion.hpp" -o .coverage.total.filtered >> ./coveragehistory/$current_log_file
 lcov -r .coverage.total.filtered "@CMAKE_CURRENT_SOURCE_DIR@/src/mlpack/core/util/arma_config.hpp" -o .coverage.total.filtered >> ./coveragehistory/$current_log_file
 
-# Extra:  Replace /build/ with /src/ to unify directories
+# Extra:  Replace /build/ with /src/ to unify directories.
 cat .coverage.total.filtered > .coverage.total
 
-# Extra: Clear up previous data, create html folder
+# Extra: Clear up previous data, create html folder.
 if [[ -d ./coverage/ ]] ; then
     rm -rf ./coverage/*
 else
     mkdir coverage
 fi
 
-# Step 9: Generate webpage
+# Step 9: Generate webpage.
 genhtml -o ./coverage/ .coverage.total
 
-# Extra: Preserve coverage file in coveragehistory folder
+# Extra: Preserve coverage file in coveragehistory folder.
 coverage_file=$current_coverage_file
 cp .coverage.total ./coveragehistory/$current_coverage_file
 
-# clean temp coverage files
+# Clean temporary coverage files.
 #rm .coverage.*
 
-# Upload the result to coveralls if token is provided
+# Upload the result to coveralls if token is provided.
 if ! [ "$token" = "" ]; then
   cpp-coveralls -n -r ../ -b ../ -l ./coveragehistory/$current_coverage_file -t "$token" --max-cov-count $max_cov_count
 fi
diff --git a/CMakeLists.txt b/CMakeLists.txt
index e793998..af49a09 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -27,7 +27,8 @@ option(BUILD_TESTS "Build tests." ON)
 option(BUILD_CLI_EXECUTABLES "Build command-line executables." ON)
 option(BUILD_SHARED_LIBS
     "Compile shared libraries (if OFF, static libraries are compiled)" ON)
-option(BUILD_WITH_COVERAGE "Build with COVTOOL" OFF)
+option(BUILD_WITH_COVERAGE
+    "Build with support for code coverage tools (gcc only)" OFF)
 enable_testing()
 
 # Include modules in the CMake directory.
@@ -44,6 +45,11 @@ if(CMAKE_COMPILER_IS_GNUCC OR "${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
   set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra")
 endif()
 
+# These support libraries are used if we need to link against something
+# specific.
+set(COMPILER_SUPPORT_LIBRARIES_MLPACK "")
+set(COMPILER_SUPPORT_LIBRARIES "")
+
 # If using clang, we have to link against libc++ depending on the
 # OS (at least on some systems). Further, gcc sometimes optimizes calls to
 # math.h functions, making -lm unnecessary with gcc, but it may still be
@@ -63,19 +69,18 @@ if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
      # select the right stdlib.
     if(${MACOSX_VERSION} LESS 9)
       set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -stdlib=libc++")
-      set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -stdlib=libc++")
-      set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} -stdlib=libc++")
+      set(CMAKE_SHARED_LINKER_FLAGS
+          "${CMAKE_SHARED_LINKER_FLAGS} -stdlib=libc++")
+      set(CMAKE_MODULE_LINKER_FLAGS
+          "${CMAKE_MODULE_LINKER_FLAGS} -stdlib=libc++")
       set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++")
      endif()
   endif()
 
-  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")
+  # Link everything with -lm.
+  set(COMPILER_SUPPORT_LIBRARIES ${COMPILER_SUPPORT_LIBRARIES} "m")
 endif()
 
-set(COMPILER_SUPPORT_LIBRARIES "")
-
 # Setup build for test coverage
 if(BUILD_WITH_COVERAGE)
   # Currently coverage only works with GNU g++
@@ -85,12 +90,16 @@ if(BUILD_WITH_COVERAGE)
     find_program(LCOV lcov)
 
     if(NOT GCOV)
-      message(FATAL_ERROR "gcov not found! Aborting...")
+      message(FATAL_ERROR
+          "gcov not found! gcov is required when BUILD_WITH_COVERAGE=ON.")
     endif()
 
-    set(COMPILER_SUPPORT_LIBRARIES "supc++")
-    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --coverage -fno-inline -fno-inline-small-functions -fno-default-inline -fprofile-arcs -fkeep-inline-functions")
-    message(WARNING "Adding debug options for coverage")
+    set(COMPILER_MLPACK_SUPPORT_LIBRARIES
+        ${COMPILER_SUPPORT_MLPACK_LIBRARIES} "supc++")
+    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --coverage -fno-inline \
+        -fno-inline-small-functions -fno-default-inline -fprofile-arcs \
+        -fkeep-inline-functions")
+    message(STATUS "Adding debug compile options for code coverage.")
     # Remove optimizations for better line coverage
     set(DEBUG ON)
 
@@ -98,10 +107,11 @@ if(BUILD_WITH_COVERAGE)
       configure_file(CMake/mlpack_coverage.in mlpack_coverage @ONLY)
       add_custom_target(mlpack_coverage DEPENDS mlpack_test COMMAND ${PROJECT_BINARY_DIR}/mlpack_coverage)
     else()
-      message(WARNING "'lcov' not found, local coverage report is disabled. Install 'lcov' and rerun cmake to generate local coverage report.")
+      message(WARNING "'lcov' not found; local coverage report is disabled. "
+          "Install 'lcov' and rerun cmake to generate local coverage report.")
     endif()
   else()
-    message(FATAL_ERROR "Coverage will only work with GNU environment.")
+    message(FATAL_ERROR "BUILD_WITH_COVERAGE can only work with GNU environment.")
   endif()
 endif()
 
diff --git a/src/mlpack/CMakeLists.txt b/src/mlpack/CMakeLists.txt
index 9d55c5e..94cfecb 100644
--- a/src/mlpack/CMakeLists.txt
+++ b/src/mlpack/CMakeLists.txt
@@ -42,6 +42,7 @@ target_link_libraries(mlpack
   ${Boost_LIBRARIES}
   ${LIBXML2_LIBRARIES}
   ${COMPILER_SUPPORT_LIBRARIES}
+  ${COMPILER_MLPACK_SUPPORT_LIBRARIES}
 )
 
 set_target_properties(mlpack
diff --git a/src/mlpack/methods/CMakeLists.txt b/src/mlpack/methods/CMakeLists.txt
index 39aa62f..dbbd231 100644
--- a/src/mlpack/methods/CMakeLists.txt
+++ b/src/mlpack/methods/CMakeLists.txt
@@ -8,6 +8,7 @@ if (BUILD_CLI_EXECUTABLES)
   )
   target_link_libraries(mlpack_${name}
     mlpack
+    ${COMPILER_SUPPORT_LIBRARIES}
   )
   install(TARGETS mlpack_${name} RUNTIME DESTINATION bin)
 endif ()




More information about the mlpack-git mailing list