[mlpack-svn] r17250 - in mlpack/trunk: . CMake

fastlab-svn at coffeetalk-1.cc.gatech.edu fastlab-svn at coffeetalk-1.cc.gatech.edu
Mon Oct 13 11:23:24 EDT 2014


Author: rcurtin
Date: Mon Oct 13 11:23:23 2014
New Revision: 17250

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


Added:
   mlpack/trunk/CMake/CXX11.cmake
Modified:
   mlpack/trunk/CMakeLists.txt

Added: mlpack/trunk/CMake/CXX11.cmake
==============================================================================
--- (empty file)
+++ mlpack/trunk/CMake/CXX11.cmake	Mon Oct 13 11:23:23 2014
@@ -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()
+

Modified: mlpack/trunk/CMakeLists.txt
==============================================================================
--- mlpack/trunk/CMakeLists.txt	(original)
+++ mlpack/trunk/CMakeLists.txt	Mon Oct 13 11:23:23 2014
@@ -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 @@
 # 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 @@
 # 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 @@
           "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-svn mailing list