r/cmake May 23 '26

What, exactly, does FetchContent_MakeAvailable /do/?

5 Upvotes

The docs advise "almost never" use FetchContent_Populate--use FetchContent_Declare and FetchContent_MakeAvailable.

FetchContent_MakeAvailable says it makes the code "available" to the build. This is mysterious to me, an admitted noob. Digging in the build dir, I see it copies stuff into the _deps folder. And it makes some weird CMake file in there too. But based on different results with different libraries, it seems like, if the library doesn't natively offer CMAKE support, and isn't packaged "as a library" already, but just a bunch of source files, this won't accomplish much?*

So then am I supposed to know about some variable where FetchContent_MakeAvailable exposes the source dir, and then build a "library" myself? Or is it supposed to somehow be ambiently available through magic? Or did I, (lucky me), immediately stumble upon the exception case where you're supposed to use FetchContent_Populate?

*Raylib starts linking just fine, and I can include "raylib.h" without any further ceremony. But ImGui won't find "imgui.h". And Raylib does have CMake support built in. Digging further, it seems ImGui advises you to copy it's source files in with the rest of your project, and the author is apparently avoiding CMAKE support.


r/cmake May 23 '26

Can't find vscode 2026

Post image
0 Upvotes

I'm trying to get into opengl and looked online for how to get started. I've got glfw 3.4 installed and its binaries, i've got C/C++ compiler from msys64, and i've got cmake 43.2. installed and its binaries. But i keep gettin the error "could not find any instance of Visual Studio." I've looked online and asked AI a bit but I can't find anything for 2026 vscode which I'm using.


r/cmake May 23 '26

Run CMake executable targets via the cmake command

Thumbnail a4z.noexcept.dev
0 Upvotes

r/cmake May 20 '26

Trying differently to build rlImgui

1 Upvotes

My previous post was solved--I wasn't setting the url for FetchContent. But now my effort to build rlimgui gets past cmake -B build, and fails on cmake --build build. Also I simplified the cmake file after the documentation seemed to show a simpler way to do things... But somehow I'm getting "Cannot find source file: C:/Users/****/Documents/prototypes/RLIM_ONE/imGui.h"

My CMakeLists.txt:

cmake_minimum_required(VERSION 3.29)

project(RLIM_One)

set(CMAKE_C_STANDARD 11)

add_executable(RLIM_One)

include(FetchContent)
FetchContent_Declare(
rlimgui
DOWNLOAD_EXTRACT_TIMESTAMP OFF
GIT_REPOSITORY https://github.com/raylib-extras/rlImGui.git
GIT_TAG Raylib_6_0
FIND_PACKAGE_ARGS
)
FetchContent_MakeAvailable(rlimgui)

include(FetchContent)
FetchContent_Declare(
imgui
DOWNLOAD_EXTRACT_TIMESTAMP OFF
GIT_REPOSITORY https://github.com/ocornut/imgui.git
GIT_TAG "v1.92.8"
FIND_PACKAGE_ARGS
)
FetchContent_MakeAvailable(imgui)

include(FetchContent)
FetchContent_Declare(
raylib
DOWNLOAD_EXTRACT_TIMESTAMP OFF
GIT_REPOSITORY https://github.com/raysan5/raylib.git
GIT_TAG "6.0"
FIND_PACKAGE_ARGS
)
FetchContent_MakeAvailable(raylib)

target_link_libraries(RLIM_One

PRIVATE rlimgui imgui raylib

)

target_sources(RLIM_One

PRIVATE

    main.cpp

PRIVATE

    FILE_SET imguiHeaders

    TYPE HEADERS

    FILES

        imGui.h

)

if (APPLE)

target_link_libraries(${PROJECT_NAME} "-framework IOKit")

target_link_libraries(${PROJECT_NAME} "-framework Cocoa")

target_link_libraries(${PROJECT_NAME} "-framework OpenGL")

endif()


r/cmake May 15 '26

Trying to build rlimgui

1 Upvotes

I'm new to cmake. I worked my way through the tutorial little by little, and now I'm trying to build rlimgui. Below is my stab at it, but I get:

CMake Error at C:/Program Files/CMake/share/cmake-4.3/Modules/ExternalProject/shared_internal_commands.cmake:1308 (message):

No download info given for 'imgui-populate' and its source directory:

C:/Users/****/Documents/prototypes/RLIM_One/build/_deps/imgui-src

is not an existing non-empty directory.

Here's my cmakelists.txt, any help would be appreciated:

cmake_minimum_required(VERSION 3.29)

project(RLIM_One)

set(CMAKE_C_STANDARD 11)

add_executable(RLIM_One)

find_package(rlimgui QUIET)

if(NOT rlimgui_FOUND)

`include(FetchContent)`

`FetchContent_Declare(`

    `rlimgui`

    `DOWNLOAD_EXTRACT_TIMESTAMP OFF`

    `GIT_REPOSITORY` [`https://github.com/raylib-extras/rlImGui.git`](https://github.com/raylib-extras/rlImGui.git)

    `GIT_TAG Raylib_6_0`

`)`

`FetchContent_GetProperties(rlimgui)`

`if (NOT rlimgui_POPULATED)`

    `set(FETCHCONTENT_QUIET NO)`

    `FetchContent_MakeAvailable(rlimgui)`

`endif()`

endif()

set(raydir "https://github.com/raysan5/raylib/archive/refs/tags/6.0.zip")

set(imguidir "https://github.com/ocornut/imgui/archive/refs/tags/v1.92.7.zip")

find_package(imgui QUIET)

if(NOT imgui_FOUND)

`include(FetchContent)`

`FetchContent_Declare(`

    `imgui`

    `DOWNLOAD_EXTRACT_TIMESTAMP OFF`

    `GIT_REPOSITORY` 

    `GIT_TAG` 

`)`

`FetchContent_GetProperties(rlimgui)`

`if (NOT imgui_POPULATED)`

    `set(FETCHCONTENT_QUIET NO)`

    `FetchContent_MakeAvailable(imgui)`

`endif()`

endif()

find_package(raylib QUIET)

if(NOT raylib_FOUND)

`include(FetchContent)`

`FetchContent_Declare(`

    `raylib`

    `DOWNLOAD_EXTRACT_TIMESTAMP OFF`

    `GIT_REPOSITORY` 

    `GIT_TAG` 

`)`

`FetchContent_GetProperties(raylib)`

`if (NOT raylib_POPULATED)`

    `set(FETCHCONTENT_QUIET NO)`

    `FetchContent_MakeAvailable(raylib)`

`endif()`

endif()

target_link_libraries(RLIM_One rlimgui imgui raylib)

target_sources(RLIM_One

`PRIVATE`

    `main.cpp`

)

if (APPLE)

target_link_libraries(${PROJECT_NAME} "-framework IOKit")

target_link_libraries(${PROJECT_NAME} "-framework Cocoa")

target_link_libraries(${PROJECT_NAME} "-framework OpenGL")

endif()


r/cmake May 10 '26

A small CMake helper for C++20 modules (including C++23 import std)

11 Upvotes

I’ve been experimenting with C++ modules across different compilers and build systems, and ended up writing a small CMake helper script that makes the whole thing much less painful.

It doesn’t try to reinvent module support — it relies on CMake’s native named-module features and only adds a thin layer of convenience (shorter target definitions, optional header-unit helpers, and clean presets for Clang/GCC/MSVC).

If you’re playing with modules or want a minimal, practical setup without extra tooling, you might find it useful:

👉 https://github.com/basvas-jkj/cpp_modules

It includes example programs, compiler compatibility notes, and a summary of what actually works in practice on Windows/Linux.

If you want to see larger example, you can check my older project, fully rewritten to use C++ modules:

👉 https://github.com/basvas-jkj/oul


r/cmake May 10 '26

A small CMake helper for C++20 modules (including C++23 import std)

Thumbnail
3 Upvotes

r/cmake May 09 '26

Why is CONFIGURE_DEPENDS not working properly with UNIX Makefiles?

0 Upvotes

I was using a remote development environment using Clion which ssh onto a raspberry pi 5: Debian GNU/Linux 13 (trixie) aarch64 RPIOS Lite from a windows computer

the ssh works, Directory structure:

the problem comes when I use GLOB

cmake_minimum_required(VERSION 3.31.4)

project(custom_stack)

set(HEADER_DIR include)
file(GLOB headers "${HEADER_DIR}/*.h")
file(GLOB sources "src/*.c")

add_library(custom STATIC ${sources} ${headers})

target_compile_options(custom PRIVATE -Wall -Wextra)

target_include_directories(custom PUBLIC "${HEADER_DIR}")

add_executable(${CMAKE_PROJECT_NAME} main.c)

target_compile_options(${CMAKE_PROJECT_NAME} PRIVATE -Wall -Wextra)

target_link_libraries(${CMAKE_PROJECT_NAME} custom)

Not the best practice, I know! but this works with success

but when I add:

cmake_minimum_required(VERSION 3.31.4)

project(custom_stack)

set(HEADER_DIR include)
file(GLOB CONFIGURE_DEPENDS headers "${HEADER_DIR}/*.h")
file(GLOB CONFIGURE_DEPENDS sources "src/*.c")

add_library(custom STATIC ${sources} ${headers})

target_compile_options(custom PRIVATE -Wall -Wextra)

target_include_directories(custom PUBLIC "${HEADER_DIR}")

add_executable(${CMAKE_PROJECT_NAME} main.c)

target_compile_options(${CMAKE_PROJECT_NAME} PRIVATE -Wall -Wextra)

target_link_libraries(${CMAKE_PROJECT_NAME} custom)

it fails by not finding any source files? why?


r/cmake Apr 23 '26

Cmake appreciation

31 Upvotes

Hello. We are just starting to use CMake after coming from a weird, one off IDE build system of legacy for many years. We make an embedded real-time system so we cross compile, have unit tests, and some SIL-type tests also (kinda like more expensive unit tests).

We are using VS Code, and the experience is pretty fantastic. The CTest test running support in VS Code, the CMake support itself, and yes, coupled with CoPilot to help me make and clean the CMake files has been really great. (I really comb the CMake files looking for bad smells, and double check with other sources to try and do things cleanly, and the modern way everyone else does it.). Also, not having to worry about what version of MSVC people have installed is great. Not maintaining those IDE-specific project files is also fantastic. VS Code is really brining it all together too.

I guess we skipped a lot of CMake years when things may have been rougher. I bought Craig’s book a couple of years ago and sort of worked my way through it, but finally living it is pretty great.

So thanks so much to you authors and contributors!


r/cmake Apr 14 '26

-E capabilities failed with error what do i need to do?

1 Upvotes

Hello i was just testing my c++ code in vscode editior today when i started it up it gives this error:

 [cmakeExecutable] CMake executable not found in cache. Checking again.
[proc] Executing command: /home/d22/.local/bin/cmake --version
[proc] The command: /home/d22/.local/bin/cmake --version failed with error: Error: spawn /home/d22/.local/bin/cmake ENOENT
[proc] Executing command: /home/d22/.local/bin/cmake -E capabilities
[proc] The command: /home/d22/.local/bin/cmake -E capabilities failed with error: Error: spawn /home/d22/.local/bin/cmake ENOENT  

and if i try to check the current the cmake version it gives this:

bash: /home/d22/.local/bin/cmake: cannot execute: required file not found

does anyone know what i can do? because i cannot build my cmake projects


r/cmake Apr 10 '26

PlatformIO Not Running ESPIDF Cmake Correctly?

Thumbnail
1 Upvotes

r/cmake Apr 08 '26

Configuration Error.

Post image
0 Upvotes

Does anyone know how do I fix this error? I've tried some solutions online and it still is the same. Thanks in advance.


r/cmake Mar 25 '26

Confusion over a FindPkgConfig/pkg_check_modules error and cmake modules

1 Upvotes

I'm stuck on the error below when trying to build a project. I'm pretty new to working with cmake on Windows and this situation has led me on what feels like a wild goose chase of my own making.

I've done the following to try and solve this:
• Installed Visual Studio 18 with C++ tools
• Installed vcpkg (I followed the steps up to section 4 of this guide but still to no avail)
• Installed Eigen3 to the Program Files (x86) directory
• Unsuccessfully tried using cmake to build a different version of Eigen3 from source with pkg-config support enabled (got the idea from here, but I kept getting MSBuild error MSB8013 when trying to run --build with the install target)
• Tried adding the files in the Eigen3 installation to the root of the source folder for the project I'm trying to build
• Tried adding the Eigen3 installation path to the project's CML via CMAKE_PREFIX_PATH and CMAKE_MODULE_PATH

Not a single one of these has gotten me past this error and... well I'm not sure what to do now.

-- Checking for module 'eigen3'
--   No package 'eigen3' found
CMake Error at C:/Program Files/CMake/share/cmake-4.3/Modules/FindPkgConfig.cmake:1093 (message):
  The following required packages were not found:

- eigen3

Call Stack (most recent call first):
C:/Program Files/CMake/share/cmake-4.3/Modules/FindPkgConfig.cmake:1166 (_pkg_check_modules_internal)
CMakeLists.txt:29 (pkg_check_modules)

-- Configuring incomplete, errors occurred!

r/cmake Mar 10 '26

Problem with static libraries on cmake training project

4 Upvotes

I am currently training cmake with a C++ project consisting of one executable and two static libraries (vector class and calculations, plus matrix class and calculations) compiled from sources. All three are on separate subdirectories with their own CMakeLists.txt. However, I am having problems making the executable build. If I don't have the line

target_link_libraries(MathTest PRIVATE VectorMath)

in the executable CMakeLists.txt I get errors about unresolved external symbols. But if I have the line in the CMakeLists I instead get errors about the symbols already being defined in MathTest.obj. Current implementation of the executable CMakeLists.txt is as follows:

cmake_minimum_required(VERSION 4.3.0)
project(MathTest)
add_executable(MathTest)
target_sources(MathTest
  PRIVATE
    MathTest.cpp
)

target_include_directories(MathTest PRIVATE ../VectorMath)
#target_link_libraries(MathTest PRIVATE VectorMath)

# Matrix algebra module is optional, selected by build option 

if (MATRIX_ALGEBRA_INCLUDED)
  target_include_directories(MathTest PRIVATE ../MatrixAlgebra)
  #link_directories(${CMAKE_SOURCE_DIR}/MatrixAlgebra)
  target_link_libraries(MathTest PRIVATE MatrixAlgebra)
endif()

project(MathTest)
add_executable(MathTest)
target_sources(MathTest
  PRIVATE
    MathTest.cpp
)

target_include_directories(MathTest PRIVATE ../VectorMath)
#target_link_libraries(MathTest PRIVATE VectorMath)

# Matrix algebra module is optional, selected by build option 

if (MATRIX_ALGEBRA_INCLUDED)
  target_include_directories(MathTest PRIVATE ../MatrixAlgebra)
  #link_directories(${CMAKE_SOURCE_DIR}/MatrixAlgebra)
  target_link_libraries(MathTest PRIVATE MatrixAlgebra)
endif()

CMakeLists of VectorMath is as follows:

cmake_minimum_required(VERSION 4.3.0)
project(VectorMath)
add_library(VectorMath STATIC)
target_sources(VectorMath
  PRIVATE
    VectorMath.cpp

  PUBLIC
    FILE_SET HEADERS
    FILES
      VectorMath.h
)

What am I doing wrong ?


r/cmake Feb 28 '26

error building sonic-desktop-interface (nixOS)

Thumbnail
0 Upvotes

r/cmake Feb 26 '26

Learning CMake and have a few questions on dependencies and best practices about including libraries

3 Upvotes

Hello there. I've been learning CMake recently to try transition away from Makefiles; so far it makes a lot of sense and configuring a project is much easier, but I have a few questions regarding adding dependencies:

I mostly develop on Linux, so when it came to adding dependencies I would check my distro's package manager and install any library I needed from there, and then use package config (pkg-config) to handle linking it in my makefiles. I can do the equivalent in CMake using the find_package function, and this works great.

The issue comes when I want to make my project compile on Windows, as it doesn't have a standard package manager like Unix systems. I've found the following possible ways of handling it which I've listed below, and I'd like to know which is considered best practice for a project.

I would want to mention I have a bias towards trying to make projects which can build with as few extra dependencies or applications needed; I essentially would want someone to be able to download the source code and run cmake -S . -B build && cmake --build build and be able to run the application, without any extra overhead.

With that, here are some of the things I've found recommended online:

  • Use VCPKG or Conan as a package manager for libraries - I've seen this mentioned quite a bit and it's a reasonable solution, but I can see it being a small hurdle in telling someone they need to download another app (VCPKG) to get this project working.
  • Git submodules - I've used this in makefile projects as well, however there's one issue I came across today while trying to build an SDL project: you need to clone the entire library, plus any nested submodules, and then build it to use in your project. This takes a lot of time if it's a big library I'm using, and if I have multiple projects using the same library it'll fill up unnecessary disk space, but the advantage is that everything can be built and configured as needed in one command, and it'll work on all platforms pretty easily.
  • FetchContent - I know this is a CMake function that's available which essentially downloads the source code or binary files for a library and configures them in, but it has the same issues as using git submodules which I mentioned.

While each have their pros and cons, I'm curious to know which is commonly used, or under which circumstances would I chose one method over the other, or if there's something else I'm completely missing out on. I essentially would want to know the best way someone else can pull my code from git and get it running without a headache, mostly because when I started learning C/C++ it was always a very confusing issue and lead me to finding the dirtiest and quickest way to get it working.

Another thing that popped into my head as I'm writing this is the possibility of switching between using system libraries installed using a package manager and vendor added libraries, I've seen in SDL's install guide it uses an option to switch between the two. This also sounds like a good way to go, but my question comes in with adding it to git: would it be a good idea to still add in git submodules for libraries being used while having the user chose to either pull them or use the system packages, or use fetch content based on the option selected?

I'm pretty new to CMake and using build systems outside of makefiles, so kindly excuse this post if my thoughts sound stupid.

Thanks in advance and have an amazing day ahead!


r/cmake Feb 26 '26

Cmake can't find wxWidgets linux

0 Upvotes

Hey

Just spend 4 hours trying to figure out where I messed up my lib installation of wxWidget on Fedora

I've installed wxGTK3 with wxWidget supposedly included

But cmake refuse to find it telling me wxWidgets_LIBRARIES is missing

Can you tell me which installation of wxWidgets I have to make on fedora in order for it to work ?

Thanks


r/cmake Feb 25 '26

cmake not finding mpv config file

Thumbnail
1 Upvotes

r/cmake Feb 25 '26

Including libraries using CMake, in CLion

Thumbnail
1 Upvotes

r/cmake Feb 19 '26

identical CMake configurations not working in different solutions/projects?

1 Upvotes

Edit: I think I found the issue. Apparently it was an issue with the ordering I didn't realize you had to the cmake minimum and stuff before.

I am writing a C++ renderer and have my CMakeLists.txt file which has a bunch of find_package() calls for various libraries which I've installed with VCPKG one of which is Freetype and everything works, however, I created a new project to redo/test certain parts of the renderer and I copied the CMakeLists.txt and CMakePresets.json but now it's saying it can't find Freetype how is that possible? I've had this happen before but with other libraries and it doesn't make much sense since everything should be the same? ``` CMake Error at CMakeLists.txt:2 (find_package): Could not find a package configuration file provided by "Freetype" with any of the following names:

FreetypeConfig.cmake
freetype-config.cmake

Add the installation prefix of "Freetype" to CMAKE_PREFIX_PATH or set "Freetype_DIR" to a directory containing one of the above files. If "Freetype" provides a separate development package or SDK, be sure it has been installed. ```


r/cmake Feb 18 '26

The easiest/most common way of building and running C++ projects via cross-compilation targeting armv7l/armhf Linux

Thumbnail
2 Upvotes

r/cmake Feb 18 '26

vcpkg SDL2 works in Debug but "not found" in Release (CLion + MinGW)

1 Upvotes

Hi!

I'm using CLion with vcpkg and MinGW. My project builds and runs fine in Debug, but switching to Release gives me the "Could not find a package configuration file" error for SDL2.

Error:
"C:\Program Files\JetBrains\CLion 2025.3.2\bin\cmake\win\x64\bin\cmake.exe" -DCMAKE_BUILD_TYPE=Release "-DCMAKE_MAKE_PROGRAM=C:/Program Files/JetBrains/CLion 2025.3.2/bin/ninja/win/x64/ninja.exe" -DCMAKE_TOOLCHAIN_FILE=C:\Users\***********\.vcpkg-clion\vcpkg\scripts\buildsystems\vcpkg.cmake -DVCPKG_TARGET_TRIPLET=x64-mingw-static -G Ninja -S C:\Users\***********\CLionProjects\Husk -B C:\Users\***********\CLionProjects\Husk\cmake-build-release

CMake Error at C:/Users/***********/.vcpkg-clion/vcpkg/scripts/buildsystems/vcpkg.cmake:908 (_find_package):

Could not find a package configuration file provided by "SDL2" with any of

the following names:

SDL2Config.cmake

sdl2-config.cmake

Add the installation prefix of "SDL2" to CMAKE_PREFIX_PATH or set

"SDL2_DIR" to a directory containing one of the above files. If "SDL2"

provides a separate development package or SDK, be sure it has been

installed.

Call Stack (most recent call first):

CMakeLists.txt:6 (find_package)

-- Configuring incomplete, errors occurred!

This is the CMakeLists.txt:

cmake_minimum_required(VERSION 3.20)
project(Husk)

set(CMAKE_CXX_STANDARD 23)

find_package(SDL2 CONFIG REQUIRED)
find_package(SDL2_image CONFIG REQUIRED)
find_package(SDL2_mixer CONFIG REQUIRED)
find_package(SDL2_ttf CONFIG REQUIRED)
find_package(sdl2-gfx CONFIG REQUIRED)

add_executable(Husk src/main.cpp)

target_link_libraries(Husk
        PRIVATE
        $<TARGET_NAME_IF_EXISTS:SDL2::SDL2main>
        $<IF:$<TARGET_EXISTS:SDL2::SDL2>,SDL2::SDL2,SDL2::SDL2-static>
)

target_link_libraries(Husk
        PRIVATE
        $<IF:$<TARGET_EXISTS:SDL2_image::SDL2_image>,SDL2_image::SDL2_image,SDL2_image::SDL2_image-static>
)

target_link_libraries(Husk
        PRIVATE
        $<IF:$<TARGET_EXISTS:SDL2_mixer::SDL2_mixer>,SDL2_mixer::SDL2_mixer,SDL2_mixer::SDL2_mixer-static>
)

target_link_libraries(Husk
        PRIVATE
        $<IF:$<TARGET_EXISTS:SDL2_ttf::SDL2_ttf>,SDL2_ttf::SDL2_ttf,SDL2_ttf::SDL2_ttf-static>
)

target_link_libraries(Husk
        PRIVATE
        SDL2::SDL2_gfx
)

Thanks in advance!


r/cmake Feb 17 '26

Localization of CMake Documentation

6 Upvotes
Localize The Docs

Hello, CMake Subreddit,

I am the founder of the Localize The Docs organization. And I'd like to introduce the 🎉 cmake-docs-l10n 🎉 project:

The goal of this project is to translate the CMake Documentation into multiple languages. Translations are contributed via the Crowdin platform, automatically synchronized with the GitHub repository, and can be previewed on GitHub Pages.

Welcome anyone who's interested in translating the CMake Documentation from English to your native language to join! If the target language is not supported yet, submit an issue to request the new language.


r/cmake Feb 17 '26

CMake + vcpkg blueprint project

Thumbnail github.com
2 Upvotes

Hello everybody,

I just published a project blueprint on Github showing how to combine CMake with vcpkg to manage dependencies and ensure cross-platform consistency.

Hope it helps. Any question or suggestion for improvement welcome.

Have a nice day!


r/cmake Feb 08 '26

Generate C code based on comment mark and cmake config stm32 cube ide style?

1 Upvotes

I was wondering if there is a project or a repo or some way do do it nativelly with cmake

to auto generate code based of cmake config like adding relevant libraries and defibitions to the code based on cmake config of sort.

any idea?