Cmake Hello World How-To with qDecoder

How to use cmake to build a simple C++ project that uses an external library you built with cmake 

By Robin Rowe

HOLLYWOOD, CA (LinuxMovies) 2015/10/22 – Cmake is a cross-platform build system compatible with Linux, Windows and Mac. Figuring out how to write a CmakeLists.txt file can be confusing, so here’s a quick how-to.

A useful yet small CGI library called qQecoder is great for reading data from web forms into your C++ program. Download the qDecoder source and place in the directory lib/libqdecoder/src or anywhere that makes sense to you.

There’s no CmakeLists.txt file with qDecoder, so let’s create one.

# libqdecoder
# Copyright 2015/7/19
# License MIT or BSD
cmake_minimum_required(VERSION 2.8)
#version number
set(CMake_qdecoder_VERSION_MAJOR 1)
set(CMake_qdecoder_VERSION_MINOR 0)
set(CMake_qdecoder_VERSION_PATCH 0)
file(GLOB qdecoder_SRC
add_library( qdecoder STATIC ${qdecoder_SRC} )

Next, let’s create a project that will use Qdecoder. Place your C++ project in a directory called HelloWorld/src or anywhere that makes sense to you. Create there the CmakeLists.txt file below. Simply search-and-replace HelloWorld with the name of your project.

# HelloWorld
# A simple Cmake build system for a project that uses Qdecoder HTTP library
# Copyright 2015/7/19
# License MIT or BSD
cmake_minimum_required (VERSION 2.8)
project (CMakeHelloWorld)
#version number
set(CMakeHelloWorld_VERSION_MAJOR 1)
set(CMakeHelloWorld_VERSION_MINOR 0)
set(CMakeHelloWorld_VERSION_PATCH 0)
file(GLOB HelloWorld_SRC
set(qdecoder ${CMAKE_SOURCE_DIR}/../../lib/libqdecoder/src)
add_subdirectory(${qdecoder} qdecoder/build)
add_executable(HelloWorld ${HelloWorld_SRC})
target_link_libraries(HelloWorld qdecoder)
 ${CMAKE_COMMAND} -E cmake_echo_color --cyan "Removing CMakeCache.txt"
 COMMAND -rm CMakeCache.txt)
install (
 TARGETS CMakeHelloWorld 
 DESTINATION /var/www/html/

Leave a Reply

Your email address will not be published. Required fields are marked *