diff --git a/CMakeLists.txt b/CMakeLists.txt index 873a9a2be494828a776fc7e00cedf460fb867ec8..ccb9c84eff12d68373d52064555e4f332a223734 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -31,6 +31,9 @@ option(OGS_USE_CONAN "Should Conan package manager be used?" ON) set(OGS_CONAN_BUILD "missing" CACHE STRING "Possible values: all, missing, \ never or list of libs to build") option(OGS_DISABLE_CCACHE "Disables ccache compiler cache." OFF) +if(${CMAKE_VERSION} VERSION_GREATER_EQUAL 3.16) + option(OGS_USE_UNITY_BUILDS "Enables Unity builds for faster compilation." OFF) +endif() # Third-party libraries, names come from Conan package names set(OGS_LIBS diff --git a/scripts/cmake/Functions.cmake b/scripts/cmake/Functions.cmake index fc03396182db9920b24bffb563ca4356b8277fca..8ef50c4b226dd6f756590c4d872abc9f6ceec803 100644 --- a/scripts/cmake/Functions.cmake +++ b/scripts/cmake/Functions.cmake @@ -101,4 +101,9 @@ function(ogs_add_library targetName) if(OGS_USE_PCH AND NOT ${targetName} STREQUAL "ChemistryLib") cotire(${targetName}) endif() + + if(${CMAKE_VERSION} VERSION_GREATER_EQUAL 3.16) + set_target_properties(${targetName} PROPERTIES + UNITY_BUILD ${OGS_USE_UNITY_BUILDS}) + endif() endfunction() diff --git a/scripts/cmake/UnityBuildSettings.cmake b/scripts/cmake/UnityBuildSettings.cmake index e78f060a7336f9c000f9789233278f874cba1696..a88a922199e78c84dff87faa148f0795216fd4fc 100644 --- a/scripts/cmake/UnityBuildSettings.cmake +++ b/scripts/cmake/UnityBuildSettings.cmake @@ -1,8 +1,16 @@ -set_target_properties(BaseLib PROPERTIES UNITY_BUILD ON - UNITY_BUILD_BATCH_SIZE 8) -set_target_properties(GeoLib PROPERTIES UNITY_BUILD ON - UNITY_BUILD_BATCH_SIZE 40) -set_target_properties(MathLib PROPERTIES UNITY_BUILD ON - UNITY_BUILD_BATCH_SIZE 10) -set_target_properties(MeshLib PROPERTIES UNITY_BUILD ON - UNITY_BUILD_BATCH_SIZE 40) +if(NOT OGS_USE_UNITY_BUILDS OR ${CMAKE_VERSION} VERSION_LESS 3.16) + return() +endif() + +set_target_properties(BaseLib PROPERTIES UNITY_BUILD_BATCH_SIZE 8) +set_target_properties(GeoLib PROPERTIES UNITY_BUILD_BATCH_SIZE 40) +set_target_properties(MaterialLib PROPERTIES UNITY_BUILD_BATCH_SIZE 20) +set_target_properties(MathLib PROPERTIES UNITY_BUILD_BATCH_SIZE 10) +set_target_properties(MeshLib PROPERTIES UNITY_BUILD_BATCH_SIZE 20) +# set_target_properties(ProcessLib PROPERTIES UNITY_BUILD_BATCH_SIZE 80) # breaks! + +if(TARGET testrunner) + # breaks! + # set_target_properties(testrunner PROPERTIES UNITY_BUILD ON) + # set_target_properties(testrunner PROPERTIES UNITY_BUILD_BATCH_SIZE 2) +endif()