EzDevInfo.com

cmake interview questions

Top cmake frequently asked interview questions

What is cmake equivalent of 'configure --prefix=DIR && make all install '?

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)

define preprocessor macro through cmake

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)

Advertisements

Cause CMAKE to generate an error

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)

Best way to specify sourcefiles in CMake

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)

Using cmake to generate visual studio C++ project files

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)

Autotools vs. Cmake vs. Scons [closed]

What are the differences between Autotools, Cmake and Scons?

What are the pros and cons of each of them?


Source: (StackOverflow)

How do you add boost libraries in CMakeLists.txt

I need to add boost libraries into my CMakeLists.txt. How do you do it or how do add it?


Source: (StackOverflow)

CMake: Adding command line options

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)

Creating a directory in CMake

In CMake, I want to create a directory if it doesn't already exist. How can I do this?


Source: (StackOverflow)

Using pre-compiled headers with CMake

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)

Switching between GCC and Clang/LLVM using CMake

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)

Looking for a 'cmake clean' command to clear up cmake output

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)

Debug vs Release in CMAKE

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)

How to compile a 32-bit binary on a 64-bit linux machine with gcc/cmake

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)

How to activate C++ 11 in CMake?

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)