diff --git a/CMake/VTKmWrappers.cmake b/CMake/VTKmWrappers.cmake index ac4872197..ebb5e780a 100644 --- a/CMake/VTKmWrappers.cmake +++ b/CMake/VTKmWrappers.cmake @@ -464,6 +464,16 @@ function(vtkm_library) set(VTKm_LIB_type SHARED) endif() + # Skip unity builds unless explicitly asked + foreach(source IN LISTS VTKm_LIB_SOURCES VTKm_LIB_DEVICE_SOURCES) + get_source_file_property(is_candidate ${source} UNITY_BUILD_CANDIDATE) + if (NOT is_candidate) + list(APPEND non_unity_sources ${source}) + endif() + endforeach() + + set_source_files_properties(${non_unity_sources} PROPERTIES SKIP_UNITY_BUILD_INCLUSION ON) + add_library(${lib_name} ${VTKm_LIB_type} ${VTKm_LIB_SOURCES} @@ -615,8 +625,10 @@ function(vtkm_add_instantiations instantiations_list) math(EXPR counter "${counter} + 1") endforeach(instantiation) - set_source_files_properties(${_instantiations_list} - PROPERTIES SKIP_UNITY_BUILD_INCLUSION ON + # Force unity builds here + set_source_files_properties(${_instantiations_list} PROPERTIES + SKIP_UNITY_BUILD_INCLUSION OFF + UNITY_BUILD_CANDIDATE ON ) set(${instantiations_list} ${_instantiations_list} PARENT_SCOPE) endfunction(vtkm_add_instantiations) diff --git a/CMakeLists.txt b/CMakeLists.txt index d039b8e09..99b3efe32 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -24,6 +24,14 @@ set(CMAKE_CXX_EXTENSIONS OFF) set(VTKm_CMAKE_MODULE_PATH ${VTKm_SOURCE_DIR}/CMake) set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${VTKm_CMAKE_MODULE_PATH}) +# While disabled system-wide, VTK-m uses UNITY builds in some modules +set(CMAKE_UNITY_BUILD OFF) + +# By default effectively disable unity builds +if (NOT DEFINED CMAKE_UNITY_BUILD_BATCH_SIZE) + set(CMAKE_UNITY_BUILD_BATCH_SIZE 1) +endif() + # Determine VTK-m version include(Utilities/Git/Git.cmake) include(VTKmDetermineVersion) diff --git a/docs/changelog/EnableUnityBuild.md b/docs/changelog/EnableUnityBuild.md new file mode 100644 index 000000000..4f8adbfbb --- /dev/null +++ b/docs/changelog/EnableUnityBuild.md @@ -0,0 +1,12 @@ +## Enable Unity build ## + +VTK-m now partially supports unity builds in a subset its sources files which +are known to take the longer time/memory to build. Particularly, this enables +you to speedup compilation in VTK-m not memory intensive builds (HIP, CUDA) in a +system with sufficient resources. + +We use `BATCH` unity builds type and the number of source files per batch can be +controlled by the canonical _CMake_ variable: `CMAKE_UNITY_BUILD_BATCH_SIZE`. + +Unity builds requires _CMake_ >= 3.16, if using a older version, unity build +will be disabled a regular build will be performed. diff --git a/vtkm/filter/CMakeLists.txt b/vtkm/filter/CMakeLists.txt index a46fdffbe..fc9829d56 100644 --- a/vtkm/filter/CMakeLists.txt +++ b/vtkm/filter/CMakeLists.txt @@ -234,8 +234,6 @@ set(gradient_sources_device vtkm_pyexpander_generated_file(ClipWithFieldExternInstantiations.h) vtkm_pyexpander_generated_file(ClipWithImplicitFunctionExternInstantiations.h) -set_source_files_properties(Contour.cxx ExtractStructured.cxx PROPERTIES SKIP_UNITY_BUILD_INCLUSION ON) - add_library(vtkm_filter INTERFACE) vtkm_library( @@ -270,12 +268,14 @@ vtkm_library( USE_VTKM_JOB_POOL ) -set_property(TARGET +set_target_properties( vtkm_filter_common vtkm_filter_extra vtkm_filter_contour vtkm_filter_gradient - PROPERTY UNITY_BUILD_MODE GROUP + PROPERTIES + UNITY_BUILD ON + UNITY_BUILD_MODE BATCH ) target_link_libraries(vtkm_filter_common PUBLIC vtkm_worklet)