cmake interview questions
Top cmake frequently asked interview questions
I do cmake . && make all install
.
This works but installs to /usr/local
.
I need to install to a different prefix (for example, to /usr
).
What is the cmake
and make
command line to install to /usr
instead of /usr/local
?
Source: (StackOverflow)
The Question is simple and I hope the answer also. How do I define a preprocessor variable through cmake?
The equivalent code would be #define foo
.
Any help would be much appreciated.
Source: (StackOverflow)
How can I get CMAKE to generate an error on a particular condition. That is, I want something like this:
if( SOME_COND )
error( "You can't do that" )
endif()
Source: (StackOverflow)
In Cmake, there are several ways to specify the sourcefiles for a target.
One is to use globbing, for example:
FILE (GLOB dir/*)
Another one is to specify each file individually, and I guess there are even more ways to do this.
Which way is the best? Best as in, has more advantages than disadvantages.
Globbing seems easy, but I heard it has some downsides. I can't remember which.
Source: (StackOverflow)
I am working on an open source C++ project, for code that compiles on Linux and Windows. I use cmake to build the code on Linux. For ease of dev-setup and political reasons, I must stick to visual studio project files/editor on Windows (I can't switch to Code::Blocks, for example). I see instructions to generate visual studio files using cmake, as here.
Have you used cmake to generate visual studio files before? How has been your experience? Suppose I want to add a new file to my project. What is the workflow for this?
Source: (StackOverflow)
What are the differences between Autotools, Cmake and Scons?
What are the pros and cons of each of them?
Source: (StackOverflow)
I'm building a large library using CMake and I would like users to be able to selectively enable/disable certain parts of my build process.
How can I add command line options to my CMake build, e.g. so that users may type something like cmake --build-partone --nobuild-parttwo --dothis=true --dothat=false ..
Apparently the OPTION keyword will create variables that can be set from the CMake GUI, but I can't figure out how to do this from the command line.
Source: (StackOverflow)
I have seen a few (old) posts on the 'net about hacking together some support for pre-compiled headers in CMake. They all seem a bit all-over the place and everyone has their own way of doing it. What is the best way of doing it currently?
Source: (StackOverflow)
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. 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")
SET (CMAKE_C_FLAGS "-Wall -std=c99")
SET (CMAKE_C_FLAGS_DEBUG "-g")
SET (CMAKE_C_FLAGS_MINSIZEREL "-Os -DNDEBUG")
SET (CMAKE_C_FLAGS_RELEASE "-O4 -DNDEBUG")
SET (CMAKE_C_FLAGS_RELWITHDEBINFO "-O2 -g")
SET (CMAKE_CXX_COMPILER "/usr/bin/clang++")
SET (CMAKE_CXX_FLAGS "-Wall")
SET (CMAKE_CXX_FLAGS_DEBUG "-g")
SET (CMAKE_CXX_FLAGS_MINSIZEREL "-Os -DNDEBUG")
SET (CMAKE_CXX_FLAGS_RELEASE "-O4 -DNDEBUG")
SET (CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O2 -g")
SET (CMAKE_AR "/usr/bin/llvm-ar")
SET (CMAKE_LINKER "/usr/bin/llvm-ld")
SET (CMAKE_NM "/usr/bin/llvm-nm")
SET (CMAKE_OBJDUMP "/usr/bin/llvm-objdump")
SET (CMAKE_RANLIB "/usr/bin/llvm-ranlib")
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. not just adding them into a project's CMakeLists.txt)?
Also, is it necessary to use the llvm-*
programs rather than the system defaults when compiling using clang instead of gcc? What's the difference?
Source: (StackOverflow)
Just as make clean
deletes all the files that a makefile has produced, I would like to do the same with CMake. All too often I find myself manually going through directories removing files like cmake_install.cmake
and CMakeCache.txt
, and the CMakeFiles
folders.
Is there a command like cmake clean
to remove all these files automatically? Ideally this should follow the recursive structure defined within the current directory's CMakeLists.txt
file.
Source: (StackOverflow)
In a gcc
compiled project, how to specify debug vs. release C/C++ flags using CMAKE
and how to run cmake
for each target type and how to express that main app will be compiled with g++
and one nested library with gcc
?
Source: (StackOverflow)
Is it possible to compile a project in 32-bit with cmake and gcc on a 64-bit system? It probably is, but how do I do it?
When I tried it the "ignorant" way, without setting any parameters/flags/etc, just setting LD_LIBRARY_PATH to find the linked libraries in ~/tools/lib it seems to ignore it and only look in subdirectories named lib64.
Source: (StackOverflow)
When I try to run CMake generated makefile to compile my program, I get the error that range based for loops are not supported in c++ 98 mode
. I tried adding add_definitions(-std=c++0x)
to my CMakeLists.txt, but it did not help. I tried this too:
if(CMAKE_COMPILER_IS_GNUCXX)
add_definitions(-std=gnu++0x)
endif()
When I do g++ --version
, I get:
g++ (Ubuntu/Linaro 4.6.1-9ubuntu3) 4.6.1
I do not understand how I can activate C++ 11 features using CMake. Please help!
__ EDIT __
I forgot to mention that I have also tried SET(CMAKE_CXX_FLAGS "-std=c++0x")
, which also does not work.
Source: (StackOverflow)