[mlpack-git] master: Use target_compile_features() on newer CMake versions. (20f8bc0)

gitdub at mlpack.org gitdub at mlpack.org
Sun Jun 5 15:07:43 EDT 2016


Repository : https://github.com/mlpack/mlpack
On branch  : master
Link       : https://github.com/mlpack/mlpack/compare/80685304929965115306ba609504840a9f665066...1dc68833e22ba1bbd5b738f5855bcfdfed310ab1

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

commit 20f8bc08afb6f4a445d07dc95896625fde552507
Author: Ryan Curtin <ryan at ratml.org>
Date:   Sun Jun 5 15:06:23 2016 -0400

    Use target_compile_features() on newer CMake versions.


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

20f8bc08afb6f4a445d07dc95896625fde552507
 CMake/NewCXX11.cmake      | 14 ++++++++++++++
 CMakeLists.txt            | 19 +++++++++++++------
 src/mlpack/CMakeLists.txt |  5 +++++
 3 files changed, 32 insertions(+), 6 deletions(-)

diff --git a/CMake/NewCXX11.cmake b/CMake/NewCXX11.cmake
new file mode 100644
index 0000000..0934606
--- /dev/null
+++ b/CMake/NewCXX11.cmake
@@ -0,0 +1,14 @@
+# This file should be incorporated into the main CMakeLists.txt when CMake 3.1
+# becomes the minimum required version (we should at least wait until late 2016
+# or early 2017 for this).
+target_compile_features(mlpack PUBLIC
+    cxx_decltype
+    cxx_alias_templates
+    cxx_auto_type
+    cxx_lambdas
+    cxx_constexpr
+    cxx_rvalue_references
+    cxx_static_assert
+    cxx_template_template_parameters
+    cxx_delegating_constructors
+)
diff --git a/CMakeLists.txt b/CMakeLists.txt
index b7bf2e6..e0525e1 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -1,13 +1,20 @@
 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_ERROR "No C++11 compiler available!")
+# Ensure that we have a C++11 compiler.  In newer versions of CMake, this is
+# done with target_compile_features() when the mlpack library target is added in
+# src/mlpack/CMakeLists.txt.
+if (${CMAKE_MAJOR_VERSION} LESS 3 OR
+    (${CMAKE_MAJOR_VERSION} EQUAL 3 AND ${CMAKE_MINOR_VERSION} LESS 1))
+  # Older versions of CMake do not support target_compile_features(), so we have
+  # to use something kind of hacky.
+  include(CMake/CXX11.cmake)
+  check_for_cxx11_compiler(HAS_CXX11)
+  if(NOT HAS_CXX11)
+    message(FATAL_ERROR "No C++11 compiler available!")
+  endif()
+  enable_cxx11()
 endif()
-enable_cxx11()
 
 # First, define all the compilation options.
 # We default to debugging mode for developers.
diff --git a/src/mlpack/CMakeLists.txt b/src/mlpack/CMakeLists.txt
index 0a044a3..be5cbca 100644
--- a/src/mlpack/CMakeLists.txt
+++ b/src/mlpack/CMakeLists.txt
@@ -22,6 +22,11 @@ endif ()
 # MLPACK_SRCS is set in the subdirectories.
 add_library(mlpack ${MLPACK_SRCS})
 
+if (NOT (${CMAKE_MAJOR_VERSION} LESS 3 OR
+        (${CMAKE_MAJOR_VERSION} EQUAL 3 AND ${CMAKE_MINOR_VERSION} LESS 1)))
+  include(../../CMake/NewCXX11.cmake)
+endif ()
+
 # Generate export symbols for Windows, instead of adding __declspec(dllimport)
 # and __declspec(dllexport) everywhere.  However, those modifiers are still
 # necessary for global variables (of which there are a few in mlpack).




More information about the mlpack-git mailing list