Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
allow to specify on cmake command line whether we want LTO
authorMartin Quinson <martin.quinson@loria.fr>
Sun, 20 Sep 2015 08:08:38 +0000 (10:08 +0200)
committerMartin Quinson <martin.quinson@loria.fr>
Sun, 20 Sep 2015 08:08:38 +0000 (10:08 +0200)
tools/cmake/Flags.cmake
tools/cmake/Option.cmake
tools/cmake/PrintArgs.cmake

index 638c322..4bc9996 100644 (file)
@@ -46,26 +46,42 @@ if(enable_compile_optimizations AND CMAKE_COMPILER_IS_GNUCC
 endif()
 
 # Configure LTO
 endif()
 
 # Configure LTO
-# TODO, provide an option to manually choose whether to use LTO
 # NOTE, cmake 3.0 has a INTERPROCEDURAL_OPTIMIZATION target
 #       property for this (http://www.cmake.org/cmake/help/v3.0/prop_tgt/INTERPROCEDURAL_OPTIMIZATION.html)
 # NOTE, cmake 3.0 has a INTERPROCEDURAL_OPTIMIZATION target
 #       property for this (http://www.cmake.org/cmake/help/v3.0/prop_tgt/INTERPROCEDURAL_OPTIMIZATION.html)
-set(enable_lto OFF)
-if(enable_compile_optimizations
-    AND CMAKE_COMPILER_IS_GNUCC
-    AND (NOT enable_model-checking))
-  if(WIN32)
-    if (COMPILER_C_VERSION_MAJOR_MINOR STRGREATER "4.8")
-      # On windows, we need 4.8 or higher to enable lto because of http://gcc.gnu.org/bugzilla/show_bug.cgi?id=50293
-      #
-      # We are experiencing assertion failures even with 4.8 on MinGW.
-      # Push the support forward: will see if 4.9 works when we test it.
+if(enable_lto) # User wants LTO. Try if we can do that
+  set(enable_lto OFF)
+  if(enable_compile_optimizations
+      AND CMAKE_COMPILER_IS_GNUCC
+      AND (NOT enable_model-checking))
+    if(WIN32)
+      if (COMPILER_C_VERSION_MAJOR_MINOR STRGREATER "4.8")
+        # On windows, we need 4.8 or higher to enable lto because of http://gcc.gnu.org/bugzilla/show_bug.cgi?id=50293
+        #
+        # We are experiencing assertion failures even with 4.8 on MinGW.
+        # Push the support forward: will see if 4.9 works when we test it.
+        set(enable_lto ON)
+      endif()
+    elseif(LINKER_VERSION STRGREATER "2.22")
       set(enable_lto ON)
     endif()
       set(enable_lto ON)
     endif()
-  elseif(LINKER_VERSION STRGREATER "2.22")
-    set(enable_lto ON)
   endif()
   endif()
+  if(enable_lto)
+    message("-- LTO seems usable.")
+  else()
+    if(NOT enable_compile_optimizations)
+      message("-- LTO disabled: Compile-time optimizations turned off.")
+    else() 
+      if(enable_model-checking)
+        message("-- LTO disabled when compiling with model-checking.")
+      else()
+        message("-- LTO does not seem usable -- try updating your build chain.")
+      endif() 
+    endif()
+  endif()
+else()
+  message("-- LTO disabled on the command line.")
 endif()
 endif()
-if(enable_lto)
+if(enable_lto) # User wants LTO, and it seems usable. Go for it
   set(optCFLAGS "${optCFLAGS} -flto ")
   # See https://gcc.gnu.org/wiki/LinkTimeOptimizationFAQ#ar.2C_nm_and_ranlib:
   # "Since version 4.9 gcc produces slim object files that only contain
   set(optCFLAGS "${optCFLAGS} -flto ")
   # See https://gcc.gnu.org/wiki/LinkTimeOptimizationFAQ#ar.2C_nm_and_ranlib:
   # "Since version 4.9 gcc produces slim object files that only contain
index 760c89b..4c3bb53 100644 (file)
@@ -50,6 +50,7 @@ mark_as_advanced(enable_print_message)
 option(enable_model-checking "Turn this on to experiment with our prototype of model-checker (hinders the simulation's performance even if turned off at runtime)" off)
 option(enable_lib_static "" off)
 option(enable_lib_in_jar "Whether the native libraries are bundled in a Java jar file" on)
 option(enable_model-checking "Turn this on to experiment with our prototype of model-checker (hinders the simulation's performance even if turned off at runtime)" off)
 option(enable_lib_static "" off)
 option(enable_lib_in_jar "Whether the native libraries are bundled in a Java jar file" on)
+option(enable_lto "Whether we should try to activate the LTO (link time optimisation)" on)
 option(enable_jedule "Jedule output of SimDAG." off)
 option(enable_debug "Turn this off to remove all debug messages at compile time (faster, but no debug activatable)" on)
 option(enable_msg_deprecated "This option enables the use of deprecated MSG functions" off)
 option(enable_jedule "Jedule output of SimDAG." off)
 option(enable_debug "Turn this off to remove all debug messages at compile time (faster, but no debug activatable)" on)
 option(enable_msg_deprecated "This option enables the use of deprecated MSG functions" off)
index ebbdf1a..57e2725 100644 (file)
@@ -102,6 +102,7 @@ message("")
 message("        CFlags ......................: ${CMAKE_C_FLAGS}")
 message("        CXXFlags ....................: ${CMAKE_CXX_FLAGS}")
 message("        LDFlags .....................: ${CMAKE_C_LINK_FLAGS}")
 message("        CFlags ......................: ${CMAKE_C_FLAGS}")
 message("        CXXFlags ....................: ${CMAKE_CXX_FLAGS}")
 message("        LDFlags .....................: ${CMAKE_C_LINK_FLAGS}")
+message("        with LTO ....................: ${enable_lto}")
 message("")
 
 if (HAVE_NS3)
 message("")
 
 if (HAVE_NS3)