I use CMake build system. I have two projects. The problem is that they use different compilers. I don't want to separate them into different folders because they have common directories such as libraries, common headers and configuration files. Is it possible to force CMake build two project with different compilers? Is there a way to do it without specifying a path to the compiler binary in the CMakeLists.txt? Because this code will be in a public repository and I don't want there would be an absolute path to the compiler binary on my machine. By the way, maybe you know some open source projects that use CMake and consist of multiple projects that use different compilers? I would be glad to see how the problem is solved there. Hope for your help!
Asked
Active
Viewed 33 times
1
-
Not a full answer, but I believe you can use [`set_target_properties`](https://cmake.org/cmake/help/latest/command/set_target_properties.html) to set [`CMAKE_CPP_COMPILER`](https://cmake.org/cmake/help/latest/variable/CMAKE_LANG_COMPILER.html) on the relevant targets. – Brian61354270 Sep 01 '21 at 20:55
-
When you say project, do you mean target? Or are you actually trying to put multiple project() in the same CMakeLists.txt – Dorito Johnson Sep 01 '21 at 21:17
-
@DoritoJohnson, I mean target. Targets in different CMakeLists.txt files – zenno2 Sep 01 '21 at 21:20
-
1@Brian: That won't work. `CMAKE_CPP_COMPILER` is not a target property (or a property at all) and setting this property only has an effect, if set before the first `project()` command encountered. – fabian Sep 01 '21 at 21:28
-
@zenno2 Well you don't need to use an absolute path. You can hardcode the compiler in the CMakeLists as just the name of the compiler. set(CMAKE_CPP_COMPILER "gcc"). Not the best but it will work. – Dorito Johnson Sep 01 '21 at 21:33