Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Correctly search C++14 on older cmake
authorMartin Quinson <martin.quinson@ens-rennes.fr>
Sat, 12 Jan 2019 16:50:12 +0000 (17:50 +0100)
committerMartin Quinson <martin.quinson@ens-rennes.fr>
Sat, 12 Jan 2019 19:43:48 +0000 (20:43 +0100)
We need to first ask cmake whether it knows about a given feature
before testing whether the compiler has that feature. In particular,
only cmake 3.8 and higher knows about the cxx_std_14 feature.

Since we use the IN_LIST operator to test whether cmake knows a given
feature, we need to bump our CMake minimal version to 3.5. That's a
huge bump from the previous 2.8 requirement, but that version is
provided on Ubuntu Xenial (16.04), our oldest build slave.

Note that cxx_std_14 as a CMAKE_CXX_KNOWN_FEATURES was introduced by
cmake 3.8 only, while versions between 3.5 and 3.8 only had individual
features composing C++14, not the global 'cxx_std_14'. But that's OK.
People should use recent tools to get better/all features.

CMakeLists.txt
ChangeLog

index d930151..c9786cf 100644 (file)
@@ -1,4 +1,4 @@
-cmake_minimum_required(VERSION 2.8.8)
+cmake_minimum_required(VERSION 3.5)
 message(STATUS "Cmake version ${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}.${CMAKE_PATCH_VERSION}")
 set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_HOME_DIRECTORY}/tools/cmake/Modules)
 
 message(STATUS "Cmake version ${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}.${CMAKE_PATCH_VERSION}")
 set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_HOME_DIRECTORY}/tools/cmake/Modules)
 
@@ -768,20 +768,32 @@ if(enable_java)
   include(${CMAKE_HOME_DIRECTORY}/tools/cmake/Java.cmake)
 endif()
 
   include(${CMAKE_HOME_DIRECTORY}/tools/cmake/Java.cmake)
 endif()
 
-# Python binding, generated with pybind11
-find_package(pybind11 2.2.0)
-if(NOT PYTHONLIBS_FOUND)
+# Python binding (with pybind11)
+################
+
+# Our usage of pybind11::overload_cast mandates C++14
+get_property(known_features GLOBAL PROPERTY CMAKE_CXX_KNOWN_FEATURES)
+if ("cxx_std_14" IN_LIST known_features)
+  find_package(pybind11 2.2.0)
+  if(NOT PYTHONLIBS_FOUND)
+    set(pybind11_FOUND OFF)
+  endif()
+else()
+  message(STATUS "No support for C++14 detected, don't even search for pybind11.")
   set(pybind11_FOUND OFF)
 endif()
   set(pybind11_FOUND OFF)
 endif()
+unset(known_features)
+
 option(enable_python "Whether the Python bindings are activated." ${pybind11_FOUND}) # ON by default if dependencies are met
 
 if("${CMAKE_SYSTEM}" MATCHES "FreeBSD" AND enable_model-checking AND enable_python)
 option(enable_python "Whether the Python bindings are activated." ${pybind11_FOUND}) # ON by default if dependencies are met
 
 if("${CMAKE_SYSTEM}" MATCHES "FreeBSD" AND enable_model-checking AND enable_python)
-  message(WARNING "FreeBSD + Model-Checking + Python = too much for now. Disabling python")
+  message(WARNING "FreeBSD + Model-Checking + Python = too much for now. Disabling python.")
   set(enable_python FALSE)
 endif()
 
 if(enable_python)
   if(pybind11_FOUND)
   set(enable_python FALSE)
 endif()
 
 if(enable_python)
   if(pybind11_FOUND)
+    message(STATUS "Found pybind11, with C++14.")
     pybind11_add_module(python-bindings src/bindings/python/simgrid_python.cpp)
     target_compile_features(python-bindings PRIVATE cxx_std_14)
     target_link_libraries(python-bindings PUBLIC simgrid)
     pybind11_add_module(python-bindings src/bindings/python/simgrid_python.cpp)
     target_compile_features(python-bindings PRIVATE cxx_std_14)
     target_link_libraries(python-bindings PUBLIC simgrid)
index 6700246..1dc467f 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -7,6 +7,7 @@ Core:
  - Replace our own code to display a backtrace (that was forking addr2line)
    with the Boost.Stacktrace library.
    You won't see your backtraces without this optional dependency.
  - Replace our own code to display a backtrace (that was forking addr2line)
    with the Boost.Stacktrace library.
    You won't see your backtraces without this optional dependency.
+ - Bump cmake dependency to 3.5 (provided by Ubuntu 16.04).
 
 MSG:
  - Drop MSG_process_create_from_stdfunc() from the API.
 
 MSG:
  - Drop MSG_process_create_from_stdfunc() from the API.