Welcome to JCM’s documentation!

jgd-cmake-modules

CMake library of CMake modules to easily and consistently develop proper CMake projects.

Pages

Indices

Sample

CMakeLists.txt
cmake_minimum_required(VERSION 3.24)
project(libsingle VERSION 0.0.0 LANGUAGES CXX)

find_package(jgd-cmake-modules CONFIG REQUIRED)
find_package(ClangFormat)
if(LIBSINGLE_ENABLE_DOCS)
  find_package(Doxygen REQUIRED COMPONENTS doxygen)
endif()

include(JcmAllModules)
jcm_setup_project()

jcm_source_subdirectories(
  ADD_SUBDIRS
  WITH_TESTS_DIR
  WITH_DOCS_DIR)

jcm_create_clang_format_targets(
  SOURCE_TARGETS libsingle::libsingle)

jcm_install_config_file_package(
  INSTALL_LICENSES
  CONFIGURE_PACKAGE_CONFIG_FILES
  TARGETS libsingle::libsingle)
libsingle/CMakeLists.txt
jcm_configure_file(
  IN_FILE libsingle_config.hpp.in
  OUT_FILE_VAR configured_header)

jcm_add_library(
  OUT_TARGET target
  PUBLIC_HEADERS widget.hpp factory.hpp
  PRIVATE_HEADERS "${configured_header}"
  SOURCES widget.cpp factory.cpp)

# a subdirectory that's "complex" enough to warrant a separate CMakeLists.txt file.
add_subdirectory(material)

target_compile_features(${target} PRIVATE cxx_std_17)

jcm_add_test_executable(
  NAME widget-unit-test
  SOURCES widget.test.cpp
  LIBS libsingle::libsingle)
libsingle/material/CMakeLists.txt
include(JcmTargetSources)

jcm_add_target_sources(
  TARGET libsingle::libsingle
  PUBLIC_HEADERS steal.hpp
  SOURCES steal.cpp)
tests/CMakeLists.txt
jcm_add_test_executable(
  NAME ${PROJECT_NAME}-integration-test
  SOURCES test.cpp
  LIBS libsingle::libsingle)
docs/CMakeLists.txt
jcm_create_doxygen_target(
  README_MAIN_PAGE
  SOURCE_TARGETS libsingle::libsingle
  EXCLUDE_REGEX "export_macros.hpp$")
cmake/libsingle-config.cmake.in
@PACKAGE_INIT@

include(CMakeFindDependencyMacro)
find_dependency(jgd-cmake-modules CONFIG REQUIRED)

include(JcmBasicPackageConfig)
jcm_basic_package_config(@PROJECT_NAME@)

Examples

This project uses its own modules, and acts as its own example!

Additionally, the tests/ directory has sample projects that use jgd-cmake-modules. Each project acts as an example of using jgd-cmake-modules and the Canonical Project Structure.