# How to maintain code generator parallelism in cross-builds?

**URL:** <https://discourse.cmake.org/t/how-to-maintain-code-generator-parallelism-in-cross-builds/4375>\
**Category:** Code\
**Created:** [October 31, 2021, 4:02pm UTC](https://discourse.cmake.org/t/how-to-maintain-code-generator-parallelism-in-cross-builds/4375 "2021-10-31T16:02:41Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![alex](https://discourse.cmake.org/user_avatar/discourse.cmake.org/alex/32/125_2.png) [@alex](https://discourse.cmake.org/u/alex)\
**Post date:** [October 31, 2021, 4:02pm UTC](https://discourse.cmake.org/t/how-to-maintain-code-generator-parallelism-in-cross-builds/4375/1 "2021-10-31T16:02:41Z")

</div>

So here’s a build scenario I’m trying to work through… I’m building `N` distinct code generators each producing one of `N` different sources. Everything works as expected when compiling for host. However,

1. The code generators are very slow when run through an emulator, so cross-compiling everything with a single toolchain is no good.
2. Doing an `export` + `find_package` dance breaks parallelism between building the code generators and building their outputs (and other things in the cross build).
3. The approach in (2) requires manually rerunning two builds during development (instead of just one), which is tedious.
4. Using `ExternalProject` solves (3), but:  
a. The superbuild binary directory does the wrong thing when running `ctest` or `cmake --install`, and  
b. It still doesn’t solve the parallelism issue.

Does anyone know of an approach that works just as well for cross-builds as it does for host-builds?

---

<div class="post-metadata">

**Author:** ![alex](https://discourse.cmake.org/user_avatar/discourse.cmake.org/alex/32/125_2.png) [@alex](https://discourse.cmake.org/u/alex)\
**Post date:** [November 2, 2021, 7:53pm UTC](https://discourse.cmake.org/t/how-to-maintain-code-generator-parallelism-in-cross-builds/4375/2 "2021-11-02T19:53:23Z")

</div>

I was able to solve (4a) with the following shims:

```auto
##
# Create shims to make the super-build directory behave like the cross-build directory

# Don't let CMake generate a cmake_install.cmake file
set(CMAKE_SKIP_INSTALL_RULES YES)

ExternalProject_Get_Property(cross-build BINARY_DIR)
file(CONFIGURE OUTPUT "cmake_install.cmake"
     CONTENT [[include("${BINARY_DIR}/cmake_install.cmake")]])

# Don't let CMake generate a CTestTestfile.cmake file (don't uncomment!)
# enable_testing()

file(RELATIVE_PATH ctest_dir "${CMAKE_CURRENT_BINARY_DIR}" "${BINARY_DIR}")
file(CONFIGURE OUTPUT "CTestTestfile.cmake"
     CONTENT [[subdirs("${ctest_dir}")]])

```
