CMake tutorial, explain build configurations

hello community,

I am following the CMake book to learn about CMake. I have trouble to follow chapter 3: build configurations (https://riptutorial.com/cmake/example/26702/setting-a-release-debug-configuration)

In this part it is not very clear why these configurations are used, and how they work.

here is the script in cmake:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
CMAKE_MINIMUM_REQUIRED(VERSION 2.8.11)
SET(PROJ_NAME "myproject")
PROJECT(${PROJ_NAME})

# Configuration types
SET(CMAKE_CONFIGURATION_TYPES "Debug;Release" CACHE STRING "Configs" FORCE)
IF(DEFINED CMAKE_BUILD_TYPE AND CMAKE_VERSION VERSION_GREATER "2.8")
  SET_PROPERTY(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS  ${CMAKE_CONFIGURATION_TYPES})
ENDIF()

SET(${PROJ_NAME}_PATH_INSTALL     "/opt/project"                     CACHE PATH "This directory contains installation Path")
SET(CMAKE_DEBUG_POSTFIX "d")

# Install
#---------------------------------------------------#
INSTALL(TARGETS ${PROJ_NAME}
    DESTINATION  "${${PROJ_NAME}_PATH_INSTALL}/lib/${CMAKE_BUILD_TYPE}/"
    )



So, instead of building the project relative to my project folder, it installs into "/opt/" directory in linux. Why would I want to do that? And what if I am working with Windows, instead?

Since the application is build in "/opt/" isn't this similar to an installer for my software? When should I prefer to do that?

Should I use this concept also if I want relative path for debug/release directories like in Eclipse?


thank you!
Last edited on
It's not "wrong" to ask this question here, but you may get better answers in one of the CMake mailing lists: https://cmake.org/mailing-lists/
Topic archived. No new replies allowed.