YCM-BUILD-SYSTEM-SUPPORT(7)

๐Ÿ“ฆ
version 0.13.0 ยท 2 versions
, in ubuntu noble, ubuntu questing

๐ŸŽ€ NAME ๐ŸŽ€

ycm-build-system-support โ€” YCM Build System Support. bestie it's the whole vibe of what YCM hands you for your build system ๐Ÿ’…


โœจ YCM BUILD SYSTEM SUPPORT โœจ

okay so YCM literally offers a lil bundle of macros and Find scripts you can drop straight into your build system. it's giving supportive friend energy. here's what's in the bag ๐Ÿซถ

  • Generic Modules โ€” these add whole new functionalities to CMake that might be useful in your project โœจ
  • Find Package Modules โ€” these are the ones that help you find software on the system ๐Ÿ”
  • Packaging Helper Modules โ€” these simplify the generation of a package that can be used by other packages ๐ŸŽ
  • Support for new CMake features in older CMake versions โ€” yes, backporting, we love to see it
  • Support for new features in CMake before these are actually released โ€” living in the future fr fr ๐Ÿ”ฎ
  • Support for 3rd party CMake modules โ€” the more the merrier

SEE ALSO:

if you wanna know about using YCM in your project, go read ycm-using(7) ๐Ÿ‘‘

YCM also offers functionalities to make a superbuild. the docs for that live somewhere else (iykyk).

SEE ALSO:

YCM Superbuild


๐ŸŒธ A PRACTICAL EXAMPLE ๐ŸŒธ

so like, imagine you made a package with a library in it, and it's called TemplatePkg. you want to package that library โ€” with versioning, installation rules for your header files AND your binary files, plus cmake files so other projects can find and use the library. iconic behaviour, honestly ๐Ÿ’…

here's the code you need to add to your CMakeLists.txt:

cmake_minimum_required(VERSION 3.12)
project(TemplatePkg
        LANGUAGES CXX
        VERSION 0.0.1)

include(GNUInstallDirs)

# Set the output dir for binaries
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_INSTALL_BINDIR})
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR})
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR})

# find and use YCM
find_package(YCM REQUIRED)

# Set a few
set(${PROJECT_NAME}_BUILD_LIBDIR ${CMAKE_INSTALL_LIBDIR})
set(${PROJECT_NAME}_BUILD_BINDIR ${CMAKE_INSTALL_BINDIR})
set(${PROJECT_NAME}_BUILD_INCLUDEDIR ${CMAKE_SOURCE_DIR}/src)

set(${PROJECT_NAME}_INSTALL_LIBDIR ${CMAKE_INSTALL_LIBDIR})
set(${PROJECT_NAME}_INSTALL_BINDIR ${CMAKE_INSTALL_BINDIR})
set(${PROJECT_NAME}_INSTALL_INCLUDEDIR ${CMAKE_INSTALL_INCLUDEDIR})

# add sources
add_subdirectory(src)

so far? nothing special, no cap. we declared our library, added source codes, and included YCM. that's it.

now we need to instruct CMake to install the library and generate CMake (FindTemplatePkg.cmake) have also been generated so that TemplatePkg can be found using CMake ๐Ÿ”ฅ

# include macro for installing packaging files and invoke it
include(InstallBasicPackageFiles)
install_basic_package_files(TemplatePkg
                            VARS_PREFIX ${PROJECT_NAME}
                            VERSION ${${PROJECT_NAME}_VERSION}
                            COMPATIBILITY SameMajorVersion
                            NO_CHECK_REQUIRED_COMPONENTS_MACRO)

this function generates ALL the configuration files that other packages need in order to locate and use the library compiled by TemplatePkg, and it adds the required installation rules for those files. obsessed ๐ŸŽ€

finally we add uninstall rules:

include(AddUninstallTarget)

and now you can compile the package by simply doing:

mkdir build
cd build
cmake ..
make
make install

this will install your package using /usr/local/ as the installation prefix. you can change that prefix by changing the CMAKE_INSTALL_PREFIX variable, like for example

cmake -DCMAKE_INSTALL_PREFIX:PATH=/opt/ycm ..

if you peek inside the build directory or <prefix>/lib you should see that make install has built the project and installed the header files and the library correctly. the file TemplatePkgConfig.cmake should be sitting in <prefix>/lib/cmake/TemplatePkg/. that file is what other packages will find when they call:

find_package(TemplatePkg)

example code can be downloaded from the TemplatePkg repository ๐Ÿ“ฆ


Copyright 2012-2021 Istituto Italiano di Tecnologia (IIT)


okay bestie that's the whole page ๐Ÿฆ‹ this was YCM version 0.13., dated Nov 05, 2023, and the page itself is YCM-BUILD-SYSTEM-SUPPORT(7). go forth and build, you absolute main character ๐Ÿ‘‘๐Ÿ’…โœจ

๐Ÿ“ฆ where this page comes from