data_to_c: CMake: Speed-up data_to_c

This moves the logic to create the parent folder to data_to_c itself
rather than having cmake do it, preventing several thousand cmake instances
to be started.

see pr#141404 for details/benchmarks

Pull Request: https://projects.blender.org/blender/blender/pulls/141404
This commit is contained in:
Ray Molenkamp
2025-07-15 02:08:14 +02:00
committed by Ray molenkamp
parent 32a6e14d41
commit 097531ccbf
2 changed files with 15 additions and 3 deletions

View File

@@ -999,7 +999,6 @@ function(data_to_c
add_custom_command(
OUTPUT ${file_to}
COMMAND ${CMAKE_COMMAND} -E make_directory ${_file_to_path}
COMMAND "$<TARGET_FILE:datatoc>" ${file_from} ${file_to}
DEPENDS ${file_from} datatoc)
@@ -1026,7 +1025,6 @@ function(data_to_c_simple
add_custom_command(
OUTPUT ${_file_to}
COMMAND ${CMAKE_COMMAND} -E make_directory ${_file_to_path}
COMMAND "$<TARGET_FILE:datatoc>" ${_file_from} ${_file_to}
DEPENDS ${_file_from} datatoc)
@@ -1055,7 +1053,6 @@ function(glsl_to_c
add_custom_command(
OUTPUT ${_file_to} ${_file_meta}
COMMAND ${CMAKE_COMMAND} -E make_directory ${_file_to_path}
COMMAND "$<TARGET_FILE:glsl_preprocess>" ${_file_from} ${_file_tmp} ${_file_meta}
COMMAND "$<TARGET_FILE:datatoc>" ${_file_tmp} ${_file_to}
DEPENDS ${_file_from} datatoc glsl_preprocess)

View File

@@ -10,6 +10,8 @@
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <filesystem>
#include <iostream>
// #define VERBOSE
@@ -63,6 +65,19 @@ int main(int argc, char **argv)
printf("Making C file <%s>\n", argv[2]);
#endif
/* We make the required directories here rather than having the build system
* do the work for us, as having cmake do it leads to several thousand cmake
* instances being launched, leading to significant overhead, see pr #141404
* for details. */
std::filesystem::path parent_dir = std::filesystem::path(argv[2]).parent_path();
std::error_code ec;
if (!std::filesystem::create_directories(parent_dir, ec)) {
if (ec) {
std::cerr << "Unable to create " << parent_dir << " : " << ec.message() << std::endl;
exit(1);
}
}
argv_len = int(strlen(argv[1]));
for (i = 0; i < argv_len; i++) {
if (argv[1][i] == '.') {