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.8 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, build, and install HelloLunch use the following commands.

cmake -G "Ninja" -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=[target_path] -DCMAKE_PREFIX_PATH=[path_to_copperspice] .
ninja install
Parameter Example Information
-DCMAKE_BUILD_TYPE optional, default is Release
-DCMAKE_INSTALL_PREFIX /c/projects/MyApp/deploy path where your project will be installed or deployed, location where ap is run
-DCMAKE_INSTALL_PATH /c/cs_lib/cmake/copperspice path to CopperSpice CMake install scripts
Last Parameter [dot] path to MyApp source code

Another Build Example

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