[mlpack-git] master: Force C++11 support for future versions of mlpack. I wouldn't be surprised if this breaks the build in some places. (4621272)

gitdub at big.cc.gt.atl.ga.us gitdub at big.cc.gt.atl.ga.us
Thu Mar 5 22:01:26 EST 2015


Repository : https://github.com/mlpack/mlpack

On branch  : master
Link       : https://github.com/mlpack/mlpack/compare/904762495c039e345beba14c1142fd719b3bd50e...f94823c800ad6f7266995c700b1b630d5ffdcf40

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

commit 462127236437b27d945de27e96e7f2f8ef53ab24
Author: Ryan Curtin <ryan at ratml.org>
Date:   Mon Oct 13 15:23:23 2014 +0000

    Force C++11 support for future versions of mlpack.  I wouldn't be surprised if
    this breaks the build in some places.


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

462127236437b27d945de27e96e7f2f8ef53ab24
 CMake/CXX11.cmake | 45 +++++++++++++++++++++++++++++++++++++++++++++
 CMakeLists.txt    | 19 ++++++++++++++-----
 2 files changed, 59 insertions(+), 5 deletions(-)

diff --git a/CMake/CXX11.cmake b/CMake/CXX11.cmake
new file mode 100644
index 0000000..852559b
--- /dev/null
+++ b/CMake/CXX11.cmake
@@ -0,0 +1,45 @@
+# This is cloned from
+# https://github.com/nitroshare/CXX11-CMake-Macros
+# until C++11 support finally hits CMake stable (should be 3.1, I think).
+
+# Copyright (c) 2013 Nathan Osman
+
+# Permission is hereby granted, free of charge, to any person obtaining a copy
+# of this software and associated documentation files (the "Software"), to deal
+# in the Software without restriction, including without limitation the rights
+# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+# copies of the Software, and to permit persons to whom the Software is
+# furnished to do so, subject to the following conditions:
+
+# The above copyright notice and this permission notice shall be included in
+# all copies or substantial portions of the Software.
+
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+# THE SOFTWARE.
+
+# Determines whether or not the compiler supports C++11
+macro(check_for_cxx11_compiler _VAR)
+    message(STATUS "Checking for C++11 compiler")
+    set(${_VAR})
+    if((MSVC AND (MSVC10 OR MSVC11 OR MSVC12)) OR
+       (CMAKE_COMPILER_IS_GNUCXX AND NOT ${CMAKE_CXX_COMPILER_VERSION} VERSION_LESS 4.6) OR
+       (CMAKE_CXX_COMPILER_ID STREQUAL "Clang" AND NOT ${CMAKE_CXX_COMPILER_VERSION} VERSION_LESS 3.1))
+        set(${_VAR} 1)
+        message(STATUS "Checking for C++11 compiler - available")
+    else()
+        message(STATUS "Checking for C++11 compiler - unavailable")
+    endif()
+endmacro()
+
+# Sets the appropriate flag to enable C++11 support
+macro(enable_cxx11)
+    if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
+        set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x")
+    endif()
+endmacro()
+
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 82a97e9..42f0a23 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -1,6 +1,14 @@
 cmake_minimum_required(VERSION 2.8.5)
 project(mlpack C CXX)
 
+# Ensure that we have a C++11 compiler.
+include(CMake/CXX11.cmake)
+check_for_cxx11_compiler(HAS_CXX11)
+if(NOT HAS_CXX11)
+  message(FATAL "No C++11 compiler available!")
+endif(NOT HAS_CXX11)
+enable_cxx11()
+
 # First, define all the compilation options.
 # We default to debugging mode for developers.
 option(DEBUG "Compile with debugging information" ON)
@@ -55,6 +63,7 @@ endif(ARMA_EXTRA_DEBUG)
 # resides.
 #   ARMADILLO_LIBRARY - location of libarmadillo.so / armadillo.lib
 #   ARMADILLO_INCLUDE_DIR - directory containing <armadillo>
+#   ARMADILLO_INCLUDE_DIRS - directories necessary for Armadillo includes
 #   LIBXML2_INCLUDE_DIR - location of LibXml2 includes
 #   LIBXML2_LIBRARIES - locations of libxml2.so or libxml2.lib
 #   BOOST_ROOT - root of Boost installation
@@ -71,12 +80,12 @@ find_package(Armadillo 3.6.0 REQUIRED)
 # compile Armadillo with 64-bit words.
 if(CMAKE_SIZEOF_VOID_P EQUAL 8)
   # Can we open the configuration file?  If not, issue a warning.
-  if(NOT EXISTS "${ARMADILLO_INCLUDE_DIRS}/armadillo_bits/config.hpp")
+  if(NOT EXISTS "${ARMADILLO_INCLUDE_DIR}/armadillo_bits/config.hpp")
     message(WARNING "Armadillo configuration file "
-        "(${ARMADILLO_INCLUDE_DIRS}/armadillo_bits/config.hpp) does not exist!")
-  else(NOT EXISTS "${ARMADILLO_INCLUDE_DIRS}/armadillo_bits/config.hpp")
+        "(${ARMADILLO_INCLUDE_DIR}/armadillo_bits/config.hpp) does not exist!")
+  else(NOT EXISTS "${ARMADILLO_INCLUDE_DIR}/armadillo_bits/config.hpp")
     # We are on a 64-bit system.  Does Armadillo have ARMA_64BIT_WORD enabled?
-    file(READ "${ARMADILLO_INCLUDE_DIRS}/armadillo_bits/config.hpp" ARMA_CONFIG)
+    file(READ "${ARMADILLO_INCLUDE_DIR}/armadillo_bits/config.hpp" ARMA_CONFIG)
     string(REGEX MATCH
         "[\r\n][ ]*#define ARMA_64BIT_WORD"
         ARMA_HAS_64BIT_WORD_PRE
@@ -91,7 +100,7 @@ if(CMAKE_SIZEOF_VOID_P EQUAL 8)
           "MLPACK will still work without ARMA_64BIT_WORD defined, but will not "
           "scale to matrices with more than 4 billion elements.")
     endif(ARMA_HAS_64BIT_WORD EQUAL 0)
-  endif(NOT EXISTS "${ARMADILLO_INCLUDE_DIRS}/armadillo_bits/config.hpp")
+  endif(NOT EXISTS "${ARMADILLO_INCLUDE_DIR}/armadillo_bits/config.hpp")
 endif(CMAKE_SIZEOF_VOID_P EQUAL 8)
 
 # On Windows, Armadillo should be using LAPACK and BLAS but we still need to



More information about the mlpack-git mailing list