March 12, 2015

cmake add include path and library path

Some tips for cMake beginners. This is done on Linux.

How to use cMake

cmake generates a bunch of intermediate files, including the final Makefile. To make things clean, make a separate directory for the build process:

mkdir build
cd build
cmake ..

To re-run cmake after changing the CMakeLists.txt, do:

cd build
rm -rf *
cmake ..

Cross Compile to ARM

To cross compile to an embedded target, add the following lines to you CMakeLists.txt at the very top (after VERSION)
SET(CMAKE_C_COMPILER arm-none-linux-gnueabi-gcc)

Add include paths

include_directories("${PROJECT_SOURCE_DIR}/../" "${PROJECT_SOURCE_DIR}/build/" "${PROJECT_SOURCE_DIR}")

Add a library

FIND_LIBRARY(json json-c json)

1st parameter: output,  The variable that will hold the results of FIND_LIBRARY
2nd parameter: the library to look for (in this case,
3rd parameter: the path to look, starting with ${PROJECT_SOURCE_DIR}

The returned varilable can be used in the following statement to add the library to link time:

Assign a variable

SET(LIBS ${ubox} ${blobmsg_json} ${json})

assigns the concatenated value of ubox, blobmsg_json and json to the variable LIBS

No comments:

Post a Comment