Top-level CMakeLists.txt

Admin私のストア

Configure each section of the top-level CMakeLists.txt.

In the Preamble section, set the CMake version and project settings.

cmake_minimum_required(VERSION cmake_version)
project(CppRestApi VERSION project_persion)

Versions are generally specified in the format Major.Minor.Patch.

Include the CTest and CTestUseLaunchers modules to run ctest.

include(CTest)
include(CTestUseLaunchers)

Set the rpath using the @loader_path and $ORIGIN variables. Include the GNUInstallDirs module, which sets up the general directory structure of a package, and specify the rpath to the libs directory.

include(GNUInstallDirs)

set(CMAKE_INSTALL_RPATH base_path libs_path)

This completes the Preamble section settings.

The Project wide setup section configures the overall settings for your project.

Builds as shared libraries by default.

option(BUILD_SHARED_LIBS "Build using shared libraries" ON)

Specify the module path of the cmake file that sets dependencies and package installation settings. After setting the module path, the project calls the cmake file with include(DirectoryName.cmake) and executes it in the scope.

list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}/cmake/libs)
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}/cmake/tests)

Set the C++ version, compiler specific features, and project configuration (Debug, Release, Profile).

CMAKE_CONFIGURATION_TYPES is for multi-configuration generators, CMAKE_BUILD_TYPE is for single-configuration generators.

Sets compilation options for each configuration. Uses CMAKE_<CONFIG>_POSTFIX to copy include/config/web_config_<CONFIG>.hpp.in and include/config/db_config_<CONFIG>.hpp.in to build/include/config/web_config.hpp and build/include/config/db_config.hpp during configuration. In the case of multiple generators, the configuration is determined at build time. You can use generator expressions to specify the contents of config.hpp.in to values that match the configuration, but CppRestApi uses Profile configuration.

From the Dependencies section onwards, subprojects will be imported using the add_subdirectory function.

Back to blog

Leave a comment

Please note, comments need to be approved before they are published.