Tuesday, April 7, 2020

CMake example

Below Cmake file illustrate "cc -I/usr/include/json-c/ -o Tutorial sample.c -ljson-c"

Create new file and name it as "CMakeLists.txt"
==================================

cmake_minimum_required(VERSION 3.10)

# set the project name
project(Tutorial)
# add the executable
add_executable(Tutorial sample.c)
# add libaries to compile
target_link_libraries(Tutorial json-c)
# add include directories
target_include_directories(Tutorial PRIVATE /usr/include/json-c/)

===================================

Good Practice: 
mkdir build; 
cd build; 
cmake ..
make

Look for executable file: Tutorial in build directory.