How to configure CMake, googleTest, XCode and an external library to work together


In this post I give a list of useful tips to make CMake, googleTest, XCode and an external library work together.

Make install

When you compile a library, like VXL or ITK with unix makefiles, you can use make install after make. This way you can use find_package(<package_name>).

List all variables after find_package

When writing your own and you use CMakeLists.txt and you use find_package(<package_name>), it might be useful to list all variables. It makes much easier to find library and include paths variables.

get_cmake_property(_variableNames VARIABLES)
foreach (_variableName ${_variableNames})
  message(STATUS "${_variableName}=${${_variableName}}")
endforeach() #_)

Other

Variables listing all files:

file(GLOB_RECURSE sources_code code/*.cc code/*.cpp code/*.h)
file(GLOB_RECURSE sources_test test/*.cc code/*.cpp test/*.h)

Printing variables:

MESSAGE( STATUS "sources_code:         " ${sources_code} )
MESSAGE( STATUS "sources_test:         " ${sources_test} )

Adding executables. Remember that in each executable you can have just one main().

add_executable (myproject_code ${sources_code})
add_executable (myproject_test ${sources_test})

Overwriting non-intuitive division of code into source groups visible in an IDE, like XCode

source_group("" FILES ${sources_code})
source_group("" FILES ${sources_test})

Cmake
Cmake tutorial
GoogleTest
VXL

[top]