I have to build a slightly patched version of GCC for a project and than compile the rest of the project with it. I am wondering what is the best way to do this. I am currently using ExternalProject_Add
to build the compiler as a dependency for other binaries, but I don't know how to change the compiler for a part of the project.

- 168
- 5
-
The CMake guru of LLVM is facing the same problem. Maybe checkout his solution: http://lists.llvm.org/pipermail/llvm-dev/2016-August/104174.html – usr1234567 Aug 28 '16 at 14:33
2 Answers
Your best bet is probably to structure things as a superbuild. A top level project would have two subprojects built using ExternalProject_Add
. The compiler would be the first subproject and the second would be your actual project which could then make use of the compiler by making your real subproject depend on the compiler subproject.
A second alternative is discussed here where your actual project remains as the top level project, but the compiler is built as a sub-build invoked via external_process()
. I've used this approach for real world situations and while it does work, I'd personally still go with the superbuild approach if I had the choice since it's a bit cleaner and perhaps better understood by other developers.
Lastly, consider whether something like hunter might be able to take care of building your compiler for you. Depending on what/how you need to patch GCC, this may or may not be the most attractive approach.

- 1
- 1

- 9,238
- 5
- 56
- 85
I would use two CMake projects, one building your compiler, the other building your actual project with your built compiler. The CMake compiler is such an essential part of CMake, that changing is asking for trouble.
If you prefer having everything in one project, you can call your actual project with add_custom_command
and call for a sub-folder. As a user this would be more surprising, but could lead to a better integration.

- 21,601
- 16
- 108
- 128