I have a CMake project that consists of several sub-projects added to the main project using add_subdirectory
function.
I use a custom compiler for which I created a helper file which sets the CMAKE_C_COMPILER
and CMAKE_ASM_COMPILER
to compile all the sub-projects.
The problem I am facing is that I need to add another sub-project which needs to use a different compiler and it seems that CMake can only use a single compiler for all sub-projects.
Is there a way to configure a different compiler for one of the sub-projects added by add_subdirectory()
command?
I tried to configure the CMAKE_C_COMPILER
variable for each sub-project, but somehow this variable seems to be cached and used for all the projects.
The beginning of each CMakeLists.txt sub-project:
include(cmake/Toolchain.cmake)
Part of cmake/Toolchain.cmake file:
set(CMAKE_C_COMPILER "${MY_COMPILER}")
set(CMAKE_ASM_COMPILER "${MY_ASSEMBLER}")
I expect my application to be compiled with the newly configured compiler but, instead it uses the old compiler.