CopperSpice Overview
CopperSpice Project Files

Building a project using CMake requires at least one CMakeLists.txt file in the root of your project. If your source files are located in a subdirectory it is common to use a separate CMake build file in the src subdirectory. This is the second file shown in the table below.

If there are additional subdirectories below the main source directory the CMake file is usually named after the folder. This is the third file shown in the table below.

Directory File Purpose
myApp CMakeLists.txt Modified per project, contains a list of source files and libraries
myApp/src CMakeLists.txt Modified per project, contains a list of source files and libraries
myApp/src/subfolder subfolder.txt Modified per project, contains a list of source files and libraries

This is a fictitious project intended to show the syntax for building a CopperSpice project. For a full working program review the KitchenSink demo build files which is available on github and from our CopperSpice download page.

CMake Build Files

Using our sample HelloLunch project the contents of the root level CMakeLists.txt is shown below.

cmake_minimum_required(VERSION 3.16 FATAL_ERROR)
project(HelloLunch)
include(CheckCXXCompilerFlag)
include(CheckCXXSourceCompiles)
include(CheckIncludeFile)
include(CheckIncludeFiles)
include(CheckTypeSize)
find_package(CopperSpice REQUIRED)
set(PACKAGE "HelloLunch")
set(PACKAGE_NAME "HelloLunch")
set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_INCLUDE_DIRECTORIES_BEFORE ON)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_STANDARD 17)
# location for binary files
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
add_subdirectory(src)


The following CMakeLists.txt is located in the src subdirectory along with your source files.

list(APPEND HelloLunch_INCLUDES
${CMAKE_CURRENT_SOURCE_DIR}/lunch.h
)
list(APPEND HelloLunch_SOURCES
${CMAKE_CURRENT_SOURCE_DIR}/main.cpp
${CMAKE_CURRENT_SOURCE_DIR}/lunch.cpp
${CMAKE_CURRENT_SOURCE_DIR}/lunch.ui
${CMAKE_CURRENT_SOURCE_DIR}/lunch_de.ts
${CMAKE_CURRENT_SOURCE_DIR}/lunch_fr.ts
qrc_hellolunch.cpp
)
# run rcc to generate qrc output
COPPERSPICE_RESOURCES(
${CMAKE_CURRENT_SOURCE_DIR}/../hellolunch.qrc
)
# run uic to generate ui_*.h source files
COPPERSPICE_RESOURCES(
${CMAKE_CURRENT_SOURCE_DIR}/lunch.ui
)
# qm files will be placed in the resource folder
set(TS_OUTPUT_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../resources)
# run lrelease to generate qm files
COPPERSPICE_RESOURCES(
${CMAKE_CURRENT_SOURCE_DIR}/../resources/lunch_de.ts
${CMAKE_CURRENT_SOURCE_DIR}/../resources/lunch_fr.ts
)
add_executable(HelloLunch
${HelloLunch_SOURCES}
)
target_include_directories(HelloLunch
PRIVATE
${CMAKE_SOURCE_DIR}/src
)
target_link_libraries(HelloLunch
CopperSpice::CsCore
CopperSpice::CsGui
)
if(CMAKE_SYSTEM_NAME MATCHES "Windows")
# disable console on windows
target_link_libraries(HelloLunch -lnetapi32 -lmpr -mwindows)
endif()
install(TARGETS HelloLunch DESTINATION .)

CMake Build Process

To configure, comile, link, and install HelloLunch use the following commands. We suggest saving these to a bash script.

mkdir build
cd build
cmake -G "Ninja" -DCMAKE_PREFIX_PATH=[path_to_copperspice] \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_INSTALL_PREFIX=[deploy_path] \
..
ninja install
Parameter Example Information
-DCMAKE_PREFIX_PATH /c/cs_lib/cmake/copperspice typically a path to the CopperSpice CMake export files
-DCMAKE_BUILD_TYPE optional parameter, default is Release
-DCMAKE_INSTALL_PREFIX /c/projects/HelloLunch/deploy path where HelloLunch will be installed
Last Parameter [dot][dot] path to HelloLunch project root directory

Other Build Examples

Refer to the Building KitchenSink documentation which contains the suggested script to build and install the KitchenSink project.