Created
March 9, 2012 11:11
-
-
Save zah/2006104 to your computer and use it in GitHub Desktop.
CMake unity builds
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 <${CMAKE_CURRENT_SOURCE_DIR}/${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) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment