I have a project with a structure as follows:
project
├── build
├── CMakeLists.txt
├── extern (git submodule)
│ └── mylib
│ ├── build
│ ├── CMakeLists.txt
│ └── src
└── src
└── main.c
mylib
has its own build system and it's a git submodule. I want to be able to run cmake --build build
in the top level project directory to build the file in project/src
, build mylib
and then link mylib
to the binary built in project
.
I use add_subdirectory(extern/mylib)
to allow cmake to see and attempt to build the files in extern/mylib
. However this does not work and I get the error:
CMake Error at extern/mylib/CMakeLists.txt:4 (project):
The CMAKE_C_COMPILER:
riscv64-unknown-elf-gcc
is not a full path and was not found in the PATH.
riscv64-unknown-elf-gcc
is definitely in my PATH as shown by successfully running riscv64-unknown-elf-gcc
in the terminal and verifying that the directory shown by which riscv64-unknown-elf-gcc
is inside my $PATH variable.
$ which riscv64-unknown-elf-gcc
/opt/riscv/bin/riscv64-unknown-elf-gcc
Is my approach wrong? How should I include this git submodule which my project is dependent on?
The same error is present for CMAKE_CXX_COMPILER
.
As pointed out by Tsyvarev, I had incorrectly set CMAKE_C_COMPILER after the project()
call in my CMakeLists.txt