I have created a CMakeLists.txt for cross compiling my C project. I have enabled many warning options and need many -D options as well. While adding these to target_compile_options() I have added quotes to make it like a string with spaces (also to avoid ‘;’ semi-colon).
I have also specified my arm-gcc compiler which is in a different path. The generated makefile has the settings the way I need.
My problem is that when generating makefile, it is adding quotes to the build command and bash gives an error command not found because of the quotes.
So for example the final make build command should be (without quotes):
You’ve shown us the results, but not the CMake logic you used to create them. Without that, it’s hard to say what’s really happening or offer advice on how to achieve what you want. Please put together a minimal, complete example that demonstrates your problem.
Many of the variables in your CROSS Compiling options section need to be set before the first call to project(). They shouldn’t be specified by the project, they should be in a toolchain file. Putting them as you have here will result in CMake making all its initial toolchain decisions based on the default system compiler, not the one you’re trying to use. You will continue hitting problems if you don’t move most of them out to a toolchain file.
I moved the “Cross Compiling options” variables to another file “gcc-arm-none-eabi.cmake” in the same directory and modified the CMakeLists.txt as follows:
-- The C compiler identification is unknown
-- The CXX compiler identification is GNU 11.4.0
CMake Error at CMakeLists.txt:3 (project):
The CMAKE_C_COMPILER:
/opt/arm-gnu-toolchain/bin/arm-none-eabi-gcc -mcpu=cortex-m7 -mthumb -specs=nano.specs -specs=nosys.specs
is not a full path to an existing compiler tool.
Tell CMake where to find the compiler by setting either the environment
variable "CC" or the CMake cache entry CMAKE_C_COMPILER to the full path to
the compiler, or to the compiler name if it is in the PATH.
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Configuring incomplete, errors occurred!
See also "/mnt/d/dev/test/build/CMakeFiles/CMakeOutput.log".
See also "/mnt/d/dev/test/build/CMakeFiles/CMakeError.log".
The PATH variable in my home bashrc contains the PATH to the toolchain. I also modified the PATH is /etc/profile to add toolchain path but that is also does not help.
Did I miss something while making the toolchain file?
Is there something else that I should have done ?
In addition to the various corrections @hsattler has mentioned in his posts, you should also use the separate file as a toolchain file in the proper way. Rather than using include() before the project() command, pass that file with the --toolchain option on the cmake command line (there are a couple of other ways, but that’s the easiest). I recommend you have a read of the cmake-toolchains(7) manual, especially the Cross Compiling section.