![]() So I'll stick to setting -DCMAKE_POLICY_DEFAULT_CMP0025=NEW in configure.pre_args. But that point is moot: it seems one cannot select a minimum version that way. Using a buildsystem generator makes your project more future-proof.Hah, that's you and Qt's Thiago who agree that CMake should be doing something about this, and as I expected the consensus among the CMake devs (in the form of a single person) is that there is no bug, projects just have to do the right thing, know all the little details on all platforms where they might be deployed, etc.Įvidently I would have made either the minimum version configurable, or else the whole init.cache thing optional. CMake itself also provides some nice features like dependency detection, library interface management, or integration with CTest, CDash and CPack. I would always recommend using CMake (or another buildsystem generator, but CMake is my personal preference) if you intend your project to be multi-platform or widely usable. If you have Windows developers used to Visual Studio and Unix developers who swear by GNU Make, CMake is (one of) the way(s) to go. So if you have a platform-independent project, CMake is a way to make it buildsystem-independent as well. ![]() From the same starting point, the same CMakeLists.txt file. It can produce Makefiles, it can produce Ninja build files, it can produce KDEvelop or Xcode projects, it can produce Visual Studio solutions. Make (or rather a Makefile) is a buildsystem - it drives the compiler and other build tools to build your code.ĬMake is a generator of buildsystems. Putting this all together you can write a shell wrapper which sets up the environment variables CC and CXX and then invokes cmake with the mentioned variable overrides.Īlso see this CMake FAQ on make override files. ![]() This variable is honored by the CMakeFindBinUtils module: $ cmake -D_CMAKE_TOOLCHAIN_PREFIX=llvm. įinally to force the use of the LLVM binutils, set the internal variable _CMAKE_TOOLCHAIN_PREFIX. Then invoke cmake in the following way: $ cmake -DCMAKE_USER_MAKE_RULES_OVERRIDE=~/ClangOverrides.txt. The suffix _INIT will make CMake initialize the corresponding *_FLAGS variable with the given value. SET (CMAKE_CXX_FLAGS_RELEASE_INIT "-O3 -DNDEBUG") SET (CMAKE_CXX_FLAGS_MINSIZEREL_INIT "-Os -DNDEBUG") SET (CMAKE_C_FLAGS_RELWITHDEBINFO_INIT "-O2 -g") SET (CMAKE_C_FLAGS_RELEASE_INIT "-O3 -DNDEBUG") SET (CMAKE_C_FLAGS_MINSIZEREL_INIT "-Os -DNDEBUG") Create a file ~/ClangOverrides.txt with the following contents: SET (CMAKE_C_FLAGS_INIT "-Wall -std=c99") The compiler specific flags can be overridden by putting them into a make override file and pointing the CMAKE_USER_MAKE_RULES_OVERRIDE variable to it. The CXX compiler identification is Clang not just adding them into a project's CMakeLists.txt)?Īlso, is it necessary to use the llvm-* programs rather than the system defaults when compiling using clang instead of gcc? What's the difference?ĬMake honors the environment variables CC and CXX upon detecting the C and C++ compiler to use: $ export CC=/usr/bin/clang Is there an easy way of switching between these and the default GCC variables, preferably as a system-wide change rather than project specific (i.e. SET (CMAKE_RANLIB "/usr/bin/llvm-ranlib") SET (CMAKE_OBJDUMP "/usr/bin/llvm-objdump") ![]() SET (CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O2 -g") SET (CMAKE_CXX_FLAGS_MINSIZEREL "-Os -DNDEBUG") SET (CMAKE_CXX_COMPILER "/usr/bin/clang++") SET (CMAKE_C_FLAGS_RELWITHDEBINFO "-O2 -g") SET (CMAKE_C_FLAGS_RELEASE "-O4 -DNDEBUG") SET (CMAKE_C_FLAGS_MINSIZEREL "-Os -DNDEBUG") I believe (please correct me if I'm mistaken!) that to use Clang I need to set the following: SET (CMAKE_C_COMPILER "/usr/bin/clang") I have a number of projects built using CMake and I'd like to be able to easily switch between using GCC or Clang/LLVM to compile them.
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |