This is a kitchen sink of CMake tips and tricks for now. This will be cleaned up once we have completed the end to end test.

  • Add this to look in /lib64
    set(FIND_LIBRARY_USE_LIB64_PATHS ON)

  • Put all your custom locators in cmake/Modules and add this to you main CMakeLists.txt
    set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/Modules/")

  • CMake lacks a clean; so do "out-of-source" builds. In your top folder, create a build folder (and add this to your .gitignore). Then cd into the build folder and do a cmake .. (and then make).
    rm -rf build; mkdir build; cd build; cmake  ..; make

  • How do we switch between optimized and debug builds?
    One can switch between build types by running cmake with the following:
    cmake -DCMAKE_BUILD_TYPE={Debug, RelWithDebInfo, Release} ..

    By default, these are the flags that are used for the different modes by default.
    RelWithDebInfo corresponds to: -O2 -g
    Release corresponds to: -O3 -DNDEBUG

  • How do we choose to build for a different architecture/compiler?
    The easiest way to switch the compiler is to 

    export CXX=`patch to compiler`
    and then run cmake again and to pick up the new compiler. We may have to completely remove the build folder first there is some caching involved.

  • No labels