![]() Set(CMAKE_SYSTEM_NAME Generic) # Or name of your OS if you have one Here is an example toolchain file for bare-metal ARM development with IAR: include(CMakeForceCompiler) You need to create a toolchain file, and use the CmakeForceCompiler module. Setting CMAKE_SYSTEM_NAME in the CMakeLists.txt is almost always an error. That toolchain file is also responsible for set a compiler. Cross-compilingĬross-compiling usually requires setting CMAKE_SYSTEM_NAME variable, and this setting should normally be done in the toolchain file. One need to pass the proper -G option to the cmake executable (or select the proper generator in CMake GUI). Incompatible generator cannot be fixed in CMakeLists.txt. A MinGW compiler usually requires MinGW Makefiles generator.Visual Studio generators work with cl compiler but cannot work with gcc.or you specify a compiler incompatible for chosen generator or platform. If on setting CMAKE_C_COMPILER in the command line CMake errors that a compiler cannot "compile a simple project", then something wrong in your environment. ![]() ![]() This approach is similar to the first one, but makes the project less flexible. (Only in rare cases) Set CMAKE_C_COMPILER variable before the project() call. CMake checks this variable when selects a default compiler. Set CC environment variable ( CXX for C++ compiler). That way CMake will use this compiler instead of default one and on the project() call it will adjust all flags for the specified compiler. Pass -DCMAKE_C_COMPILER= to cmake when configure the project. If you want, e.g., to use clang instead of defaulted gcc, then either: Nor this will work when replacing a native compiler with a cross-compiler. This approach will never work for replacement of cl compiler (used in Visual Studio) with gcc one. replacement of gcc with clang could work sometimes. When one sets CMAKE_C_COMPILER variable after the project() call, this only changes the compiler executable: default flags, features all remains set for the default compiler.ĪS RESULT: When the project is built, a build system calls the project-specified compiler executable but with parameters suitable for the default compiler.Īs one could guess, this approach would work only when one replaces a default compiler with a highly compatible one. When CMake executes the project() call, it looks for a default compiler executable and determines the way for use it: default compiler flags, default linker flags, compile features, etc.Īnd CMake stores path to that default compiler executable in the CMAKE_C_COMPILER variable. I see more and more people who set CMAKE_C_COMPILER and other compiler-related variables in the CMakeLists.txt after the project call and wonder why this approach breaks sometimes. The wiki doesn't provide reason why 3rd method should be avoided. This must be done before any language is set (ie: before any project() or enable_language() command).įor example: set(CMAKE_C_COMPILER "gcc-4.2") Set the appropriate CMAKE_FOO_COMPILER variable(s) to a valid compiler name or full path in a list file using set(). Set the appropriate CMAKE_FOO_COMPILER variable(s) to a valid compiler name or full path on the command-line using cmake -D.įor example: cmake -G "Your Generator" -D CMAKE_C_COMPILER=gcc-4.2 -D CMAKE_CXX_COMPILER=g++-4.2 path/to/your/source (Specifically, if you are trying to set Xcode's GCC_VERSION, this method confuses Xcode.)įor example: CC=gcc-4.2 CXX=/usr/bin/g++-4.2 cmake -G "Your Generator" path/to/your/source This method is not guaranteed to work for all generators. To select a specific compiler, you have several solutions, as exaplained in CMake wiki:įor C and C++, set the CC and CXX environment variables.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |