mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-01-16 20:19:57 +00:00
Add unity build option
Each component and each MW-subsystem will be used as a single compilation unit.
This commit is contained in:
parent
c8c0e5de38
commit
9089df3080
2 changed files with 69 additions and 18 deletions
|
@ -73,6 +73,8 @@ option(OGRE_STATIC "Link static build of Ogre and Ogre Plugins into the binarie
|
||||||
option(BOOST_STATIC "Link static build of Boost into the binaries" FALSE)
|
option(BOOST_STATIC "Link static build of Boost into the binaries" FALSE)
|
||||||
option(SDL2_STATIC "Link static build of SDL into the binaries" FALSE)
|
option(SDL2_STATIC "Link static build of SDL into the binaries" FALSE)
|
||||||
|
|
||||||
|
option(OPENMW_UNITY_BUILD "Use fewer compilation units to speed up compile time" FALSE)
|
||||||
|
|
||||||
# Apps and tools
|
# Apps and tools
|
||||||
option(BUILD_BSATOOL "build BSA extractor" OFF)
|
option(BUILD_BSATOOL "build BSA extractor" OFF)
|
||||||
option(BUILD_ESMTOOL "build ESM inspector" ON)
|
option(BUILD_ESMTOOL "build ESM inspector" ON)
|
||||||
|
|
|
@ -1,25 +1,74 @@
|
||||||
|
function(enable_unity_build UB_SUFFIX SOURCE_VARIABLE_NAME)
|
||||||
|
set(files ${SOURCE_VARIABLE_NAME})
|
||||||
|
# Generate a unique filename for the unity build translation unit
|
||||||
|
set(unit_build_file ${CMAKE_CURRENT_BINARY_DIR}/ub_${UB_SUFFIX}.cpp)
|
||||||
|
# Exclude all translation units from compilation
|
||||||
|
set_source_files_properties(${files} PROPERTIES HEADER_FILE_ONLY true)
|
||||||
|
# Open the ub file
|
||||||
|
FILE(WRITE ${unit_build_file} "// Unity Build generated by CMake\n")
|
||||||
|
# Add include statement for each translation unit
|
||||||
|
foreach(source_file ${files} )
|
||||||
|
FILE( APPEND ${unit_build_file} "#include <${source_file}>\n")
|
||||||
|
endforeach(source_file)
|
||||||
|
# Complement list of translation units with the name of ub
|
||||||
|
set(${SOURCE_VARIABLE_NAME} ${${SOURCE_VARIABLE_NAME}} ${unit_build_file} PARENT_SCOPE)
|
||||||
|
endfunction(enable_unity_build)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
macro (add_openmw_dir dir)
|
macro (add_openmw_dir dir)
|
||||||
set (files)
|
set (files)
|
||||||
|
set (cppfiles)
|
||||||
foreach (u ${ARGN})
|
foreach (u ${ARGN})
|
||||||
|
|
||||||
|
# Add cpp and hpp to OPENMW_FILES
|
||||||
file (GLOB ALL "${dir}/${u}.[ch]pp")
|
file (GLOB ALL "${dir}/${u}.[ch]pp")
|
||||||
foreach (f ${ALL})
|
foreach (f ${ALL})
|
||||||
list (APPEND files "${f}")
|
list (APPEND files "${f}")
|
||||||
list (APPEND OPENMW_FILES "${f}")
|
list (APPEND OPENMW_FILES "${f}")
|
||||||
endforeach (f)
|
endforeach (f)
|
||||||
|
|
||||||
|
# Add cpp to unity build
|
||||||
|
file (GLOB ALL "${dir}/${u}.cpp")
|
||||||
|
foreach (f ${ALL})
|
||||||
|
list (APPEND cppfiles "${f}")
|
||||||
|
endforeach (f)
|
||||||
|
|
||||||
endforeach (u)
|
endforeach (u)
|
||||||
|
|
||||||
|
if (OPENMW_UNITY_BUILD)
|
||||||
|
enable_unity_build(${dir} "${cppfiles}")
|
||||||
|
list (APPEND OPENMW_FILES ${CMAKE_CURRENT_BINARY_DIR}/ub_${dir}.cpp)
|
||||||
|
endif()
|
||||||
|
|
||||||
source_group ("apps\\openmw\\${dir}" FILES ${files})
|
source_group ("apps\\openmw\\${dir}" FILES ${files})
|
||||||
endmacro (add_openmw_dir)
|
endmacro (add_openmw_dir)
|
||||||
|
|
||||||
macro (add_component_dir dir)
|
macro (add_component_dir dir)
|
||||||
set (files)
|
set (files)
|
||||||
|
set (cppfiles)
|
||||||
|
|
||||||
foreach (u ${ARGN})
|
foreach (u ${ARGN})
|
||||||
file (GLOB ALL "${dir}/${u}.[ch]pp")
|
file (GLOB ALL "${dir}/${u}.[ch]pp")
|
||||||
|
|
||||||
foreach (f ${ALL})
|
foreach (f ${ALL})
|
||||||
list (APPEND files "${f}")
|
list (APPEND files "${f}")
|
||||||
list (APPEND COMPONENT_FILES "${f}")
|
list (APPEND COMPONENT_FILES "${f}")
|
||||||
endforeach (f)
|
endforeach (f)
|
||||||
|
|
||||||
|
# Add cpp to unity build
|
||||||
|
file (GLOB ALL "${dir}/${u}.cpp")
|
||||||
|
foreach (f ${ALL})
|
||||||
|
list (APPEND cppfiles "${f}")
|
||||||
|
endforeach (f)
|
||||||
|
|
||||||
endforeach (u)
|
endforeach (u)
|
||||||
|
|
||||||
|
if (OPENMW_UNITY_BUILD)
|
||||||
|
enable_unity_build(${dir} "${cppfiles}")
|
||||||
|
list (APPEND COMPONENT_FILES ${CMAKE_CURRENT_BINARY_DIR}/ub_${dir}.cpp)
|
||||||
|
endif()
|
||||||
|
|
||||||
source_group ("components\\${dir}" FILES ${files})
|
source_group ("components\\${dir}" FILES ${files})
|
||||||
endmacro (add_component_dir)
|
endmacro (add_component_dir)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue