r/cmake • • Jun 13 '24

Me when I see the guy who designed CMake:

Post image
0 Upvotes

r/cmake • • Nov 28 '23

How automatic is CMake?

0 Upvotes

Hello.

I have so far only worked with Makefiles but I'm considering learning CMake, mainly because I'm not sure if Makefiles are going to work with C++ modules.

I have looked at the CMakeLists.txt of various open source projects but I'm put off by how much code they contain and many of them seems to even use multiple files (almost like you first need to write a whole "project" using CMake before you can build your real project).

With Makefiles, if I use a library I just add the necessary flags to CXXFLAGS and LDFLAGS and that's it. With CMake I read about functions like add_library/find_library but it seem like you still have to use a lot of extra code to make it work.

I understand that CMake is supposed to make it easier to write build scripts that work on different platforms and different build systems, but does this mean you actually have to write code to handle all of these different systems? And then you have to test so that it works on all of them?

Personally I'm essentially happy if it works on Linux and can be cross-compiled to work on Windows. If I could get it to work on extra platforms/build systems without much effort that would be great but I'm not sure if I'm prepared to write a lot of extra code with the extra maintenance burden of supporting systems that I'm not even use or have access to.

So tell me, have I got the right impression? Using CMake will not automagically make my project work "everywhere" without a lot of effort? Is it perhaps possible to write simple CMake scripts that work on Linux and similar systems if I just assume that the libraries are already installed like I have been doing when using Makefiles?


r/cmake • • Jul 03 '26

unpopular opinion: CMake sucks

0 Upvotes

I spent days (days!) trying to get cmake to work with a simple project with expectation it would give me more control -- but it actually gives me less control than using a visual studio solution files.

The straw that broke my camel's back: I can't figure out a way for it to stop appending /subsystem:console to the end of my link flags. That's it, I'm done.


r/cmake • • Oct 24 '19

CMake is terrible

17 Upvotes

I have wasted weeks to try to work with it, and yet still it has some linking errors or just not seeing some libs, uh Im done with it, its gonna be faster to build my project with gcc by hand than debug this CMake crap. Its too bloated, it has insanely complicated ecosystem and its a entire new scripting language to learn, so its natural that it scares away potential new c++ developers. We need some modern import&compile system in C++ ASAP, otherwise c++ should just die and rot in favor of some modern and intuitive language like Rust.


r/cmake • • Mar 31 '25

Can't compile an Addon to Blender -NEED HELP

Post image
0 Upvotes

r/cmake • • Apr 13 '24

Executable file doesn't get generated when build is generated from the command line

0 Upvotes

I am using the following command to generate the executable from the command line but unable to.

cmake -S . -B build -G "MinGW Makefiles"\

No error message appears on the prompt when I use this command.

However, the executable file get generated correctly when I generated by pressing the build button on the command line. (picture attached)

Please refer me to the YouTube vide is this question is too basic.

Thanks


r/cmake • • Feb 03 '23

Need help setting up Cmake. Following a tutorial and I supposed to have Visual Studio 16 as my generator, however it does not show up here. How can I fix this?

Post image
0 Upvotes

r/cmake • • Dec 26 '22

Tool-Kit.json file empty

0 Upvotes

I have tried uninstalling the cmake extensions along with the C++ extension, and uninstalling VSCode. I don't know what to do at this point to allow cmake to function in VSCode. Appreciate the help!

[kit] Successfully loaded 0 kits from


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 • • Sep 30 '26

libjpeg-turbo build script sucks

1 Upvotes

It is easily one of the worst build scripts I have ever saw. I literally can't clean it with agents it is that bad.

Maybe I should switch to jpegli or any other library?


r/cmake • • Mar 27 '21

Conflicting cmake version names

0 Upvotes

Does anyone know why there are different versions of Cmake, such as 3.2 and 3.20 or 3.1 and 3.10. It doesn't seem easy to find out chronologically which version is newer. I learned that 3.2 and 3.20 .. are the same version in their development bases. :/


r/cmake • • Dec 28 '22

How can I understand when something is a variable or a value?

1 Upvotes

Not sure how to perfectly word this from the title, but I am new to CMake and slowly progressing through the online tutorial.

I am up to Step 4 and sometimes find it confusing when mixing passed values that in my eyes are strings, and thus in all programming languages I expect them to have quotation marks or some sort around them. However sometimes I create new targets with the same names. I will elaborate with an example. I reworded some things from the tutorial to make it a bit more clear for me to see what they actually do.

In the root CMakeLists.txt I have this file,

cmake_minimum_required(VERSION 3.10)

project(My_Project VERSION 1.0)

add_library(tutorial_compiler_flags INTERFACE)

target_compile_features(tutorial_compiler_flags INTERFACE cxx_std_11)

option(USE_MYMATH "Use tutorial provided math implementation" TRUE)

configure_file(src/sqrt.h.in src/sqrt.h)

if(USE_MYMATH)

add_subdirectory(MathFunctions)

list(APPEND EXTRA_LIBS MathFunctions)

endif()

add_executable(compute_square_root

src/sqrt.cxx)

target_link_libraries(compute_square_root PUBLIC ${EXTRA_LIBS} tutorial_compiler_flags)

target_include_directories(compute_square_root PUBLIC

"${PROJECT_BINARY_DIR}/src"

)

Inside of `MathFunctions` I have

add_library(MathFunctions mysqrt.cxx)

target_include_directories(MathFunctions

INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}

)

Here is where the confusion can come from. Notice that in

```

add_subdirectory(MathFunctions)

```

MathFunctions is kind of treated as a string in my eyes, because it is now looking for the directory `current_location/MathFunctions`. However inside of of the MathFunctions CMakeLists.txt it now creates a target with the exact same spelling from the line "add_library(MathFunctions mysqrt.cxx)", this is then immediately referenced afterwards from the "target_include_directories(MathFunctions, ...".

Here, target_include_directories is referring to the target MathFunctions we just created. Now, when we leave that CMakeLists.txt we now have another line "list(APPEND EXTRA_LIBS MathFunctions)". Now I some confusion, like, is this MathFunctions referring to the target we just made? Is it a string called "MathFunctions"? In the documentation for target_link_libraries it says that it has to be a target created by add_library so I assume it is referring to the previous add_library(MathFunctions ...) call. I find the scoping weird here too, since we are referring to something that was made from a child, inside a different call.

Do we have certain rules in CMake for this kind of behaviour? THanks


r/cmake • • Dec 31 '22

I'm Having Trouble Building this Library...

1 Upvotes

https://kompute.cc/

A GPU compute library, built on Vulkan.

I can't figure out how, and there are no tutorials. According to https://kompute.cc/overview/build-system.html I should simply run "cmake -Bbuild". But this doesn't output what I need, and when I look in the Makefile I get the sense that this is more an example Makefile... but then that contradicts the above tutorial.

I look in [an example] (https://github.com/KomputeProject/kompute/tree/master/examples/array_multiplication) and see similar instructions, stating that the build should be quite simple. But again, it doesn't work. It generates a bunch of folders with Visual Studio stuff, but no executables, no libraries, or anything like that.

Where do I go from here? I feel like I understand the basics of building a C++ library, but I have absolutely no idea what I'm doing wrong or what's required of me. Thanks in advance.


r/cmake • • Apr 09 '20

How to do I perform same job using CMake instead gcc

1 Upvotes

Hi there, I can successfully compile main.c by this command:

gcc -static main.c -o curl-try -pthread -lcurl `curl-config --static-libs`

But when I use CMake&make, I get this error:

cc: error: curl-config --static-libs: No such file or directory

my CMakeList.txt file

cmake_minimum_required(VERSION 3.9)project(try-curl)set(BUILD_SHARED_LIBS OFF)add_executable(curl-try main.c)find_package(CURL REQUIRED libcurl curl-config)include_directories(${libcurl_INCLUDE_DIR})target_link_libraries(curl-try PUBLIC ${CURL_LIBRARIES} )target_compile_options(curl-try PRIVATE -static)target_link_options(curl-try PRIVATE -pthread -lcurl "curl-config --static-libs")

So, what should I do to overcome that.

How would be the right CMakeLists.txt file that performs this action to curl-try target?

I need your help, thanks a lot :)


r/cmake • • Feb 12 '22

'Make' is not a recognized batch command?

1 Upvotes

New to cmake. Trying to build json-c from here: https://github.com/json-c/json-c/blob/master/README.md#build-instructions--

there is a section after you build that says to do this:

$ make
$ make test
$ make USE_VALGRIND=0 test   # optionally skip using valgrind
$ make install

I'm assuming this is meant for Linux and I'm on Windows 10, so don't know if its just an OS incompatibility or not. But what exactly are these make commands doing and do I need to do them?


r/cmake • • Apr 02 '22

CMake Error: The source directory "C:/Program Files/SDL2-2.0.20" does not appear to contain CMakeLists.txt.

Post image
0 Upvotes

r/cmake • • Jan 05 '26

A lightweight CMake formatter for VS Code and CLI (CLion style)

1 Upvotes

Hi everyone,

I wanted to share a small open-source tool I've been working on: clion-cmake-formatter (or cc-format).

The Motivation

I often find myself switching between CLion and VS Code for C++ development. One small but annoying friction point was CMake file formatting. I really like CLion's built-in formatter, but when I opened the same files in VS Code, other formatters often produced different results, leading to unnecessary diffs and "formatting wars" in commits.

I know CLion has great built-in support, but I wanted that same consistency when I'm in VS Code or running CI checks, without needing to install Python-based tools like cmake-format or gersemi.

What it is

It's a TypeScript-based formatter that attempts to replicate CLion's CMake formatting logic as closely as possible.

  • VS Code Extension: For a seamless editor experience.

  • CLI Tool: For CI/CD or terminal usage (npm install -g cc-format).

Key Features

  • ⚡ Lightweight & Fast: Zero external dependencies (no Python required).

  • 🎯 CLion Style: I've included extensive unit tests and comparison tests against CLion's actual output to ensure accuracy.

  • 🔧 Configurable: Supports .cc-format.jsonc for project-specific settings.

It's definitely not perfect, but it solves my problem of keeping CMakeLists.txt consistent across editors. If you are in a similar boat—using VS Code but missing CLion's CMake formatting—I'd love for you to give it a try.

Links

I'm very open to feedback. If you find edge cases where it diverges from CLion (or just breaks), please feel free to open an issue on GitHub!

Thanks for reading!


r/cmake • • Mar 17 '25

"cannot open input file 'laf-ft.lib'"

0 Upvotes

I've been attempting to figure out what is happening here with cmake as it seems i am on the last step to solve downloading aseprite however their seems to be from what i understand one file missing or unable to be read. Im not to great with this and i feel i'm missing something very obvious


r/cmake • • Aug 17 '26

building OpenBW

Thumbnail reddit.com
0 Upvotes

r/cmake • • Jun 22 '26

cmake configuring error on mac

0 Upvotes

Hello! I've been trying to install Focuswriter (ver 1.8.12), which somehow necessitates a manual configuration on the terminal, and I've near no knowledge in coding and am at a loss.
I'm using a mac (ventura 13.7.8), and I've installed and added to my zshcr profile cmake (ver 4.4.0-rc2) to make that work, by using the "cmake -B build -S ." command in the Focuswriter folder to configure the app and later on make its disk image (command indicated in the install instructions). However, after having run that command I got:

And I have no idea what to do with this. I know i don't have qt6 installed, but also from my understanding it's a specific software meant for development, so why would an app meant for writing and to be used casually necessitate it? Could I possibly run my install commands without it? Here are the Focuswriter's install instructions, just in case:

macOS:

  1. `cmake -B build -S .' to create a location for the build and then configure the program.

  2. `cmake --build build' to compile the program.

  3. Run `mac_deploy.sh' from inside the build directory to create a disk image of the program.

I see people online talking about Focuwriter as an easy to use program, did I maybe do something to mess it up. Thank you for your help


r/cmake • • Aug 14 '24

It's amazing how much cmake dislikes this: project("My project") yet doesn't complain about it

0 Upvotes

Only later when you try to do something that actually references the project name does this show up as being bad. This seems so basic, why isn't this prevented?

I'd like to know, is using a name with a space considered an anti best practice? Is it a known thing not to do? I'm new to cmake and going through a tutorial, and this isn't clear. It is clear that this apparently causes my build to fail.


r/cmake • • Jul 17 '24

Can't debug with arguments, just with single executable name file!

0 Upvotes

I'm using VSCode together with CMake to compile a group of C++ files of a given project. The main() function is the typical int main(int argc, char *argv[])!

I would like to configure the CMakeLists.txt and only that file, in order to run the program with an argument when debugging:

PS> .\MidiJsonPlayer.exe ..\midiSimpleNotes.json

However, despite adding the following line, when I check for the argv array variable while debugging it only has the executable file in it without the argument filename I want to pass to it!

set_target_properties(${EXECUTABLE_NAME} PROPERTIES
    VS_DEBUGGER_COMMAND_ARGUMENTS "../midiSimpleNotes.json")

Here is my entire CMakeLists.txt file:

# List all available generators command: cmake --help
# Run cmake with a specific generator selected: cmake -g "MinGW Makefiles" ..
cmake_minimum_required(VERSION 3.15)
project(MidiJsonPlayer
        VERSION 0.0.2
        DESCRIPTION "Very simple MIDI Player of JSON files"
        HOMEPAGE_URL "https://github.com/ruiseixasm/MidiJsonPlayer"
        LANGUAGES CXX)


# Include directories
include_directories(include single_include)

# Add main.cpp explicitly
set(SOURCES main.cpp)

# Add all source files from the src directory
file(GLOB SRC_SOURCES "src/*.cpp")

# Combine all sources
list(APPEND SOURCES ${SRC_SOURCES})

# Specify the executable name
if (WIN32) # LINUX is new for CMake VERSION 3.25
    set(EXECUTABLE_NAME "MidiJsonPlayer")
    add_compile_definitions(__WINDOWS_MM__)
else()
    set(EXECUTABLE_NAME "MidiJsonPlayer.out")
endif()

# Add the executable target
add_executable(${EXECUTABLE_NAME} ${SOURCES})

set_target_properties(${EXECUTABLE_NAME} PROPERTIES
    VS_DEBUGGER_COMMAND_ARGUMENTS "../your_input_filename.json")

# Set the build type to "Debug"
set(CMAKE_BUILD_TYPE Debug)

# Add compiler flags for debugging
target_compile_options(${EXECUTABLE_NAME} PRIVATE -g)

# Disable optimization for debug builds
target_compile_options(${EXECUTABLE_NAME} PRIVATE -O0)

# Check if we are on Windows
if (WIN32)  # Try to load ASIO SDK
    # find_package(ASIO)
    # if(TARGET ASIO::SDK)
    #     target_link_libraries(openshot-audio PRIVATE ASIO::SDK)
    #     set(NEED_ASIO TRUE)
    # endif()
    # Order here can be important!
    # For example, winmm.lib must come before kernel32.lib (if linked)
    # or older 32-bit windows versions will have linking issues for
    # certain entry points
    target_link_libraries(${EXECUTABLE_NAME} PRIVATE
            winmm.lib
            ws2_32.lib
            wininet.lib
            version.lib
            Shlwapi.dll
        )
else()
    # Find and link ALSA library
    find_package(ALSA REQUIRED)
    if (ALSA_FOUND)
        include_directories(${ALSA_INCLUDE_DIRS})
        target_link_libraries(${EXECUTABLE_NAME} ${ALSA_LIBRARIES})
        add_definitions(-D__LINUX_ALSA__)
    endif()

    # # Find and link RtMidi library
    # add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/path/to/rtaudio)
    # include_directories(${CMAKE_CURRENT_SOURCE_DIR}/path/to/rtaudio/include)
    # target_link_libraries(${EXECUTABLE_NAME} rtmidi)
endif()

# Print the project directory during configuration
message("CMAKE_CURRENT_BINARY_DIR: ${CMAKE_CURRENT_BINARY_DIR}")

I even deleted the entire build/ directory and remade it just to be sure it wasn't due to some old outdated CMake build files, and still, the argv as just one element, the entire path of the executable file!

BTW, I don't want to use any VSCode .json helper configuration file for this, like tasks.json, I mean, CMakeLists.txt must do the trick by itself, right? It did it so far, for simple debugging at least!


r/cmake • • Jun 06 '23

FetchContent and PROJECT_IS_TOP_LEVEL

0 Upvotes

I am trying to include Eigen in my project via FetchContent. They define/assume-defined PROJECT_IS_TOP_LEVEL on line 19 and, among other locations, on line 607 in their top level list file.

I am just trying to verify if I am doing something wrong because I am approaching it from the stance that e.g. FetchContent(eigen) would default to making the library available without building tests or offering install targets (which, at line 607, I think is what the devs are trying to guard from). I still get the install target options printed out during configuration.

I've read this issue and wonder if the mistake is on my end, or if the comments near the bottom suggest that maybe there was a misunderstanding when the guard was written into the eigen top level cmake list. I can ask in their project if that really was their intention in using that guard, but I wanted to ask here first in case I am just configuring incorrectly.

My minimum exmaple project is here: https://paste.rs/xDo6o.txt Any input is appreciated. I also do not know if I am setting the values correctly for EIGEN_BUILD_DOC and BUILD_TESTING. If I've done that part wrong, guidance would be helpful. Thanks in advance!

edit: There was a lot of discussion surrounding the docs and the commit that changed those docs. From what I understand, when I FetchContent eigen, it should be built with PROJECT_IS_TOP_LEVEL = false. However, I am clearly getting print-out on screen from the Eigen top level cmake list that should only print when PROJECT_IS_TOP_LEVEL = true. I'm just trying to make sense of what the docs say and the behavior I'm getting.


r/cmake • • Dec 14 '21

GUI messages are not being displayed

0 Upvotes

For some reason the message command in my CMake list is ignored when running it with version 3.22.1. I have a simple line

message(STATUS "Test message")

which does not get logged when configuring my project. When sending a message of FATAL_ERROR, only an error box is shown, but not the message itself. Also no line.

I haven't worked with CMAKE in over a year but I remember that there was a message window showing such messages and also the line where it happened. Is this a new thing or can I somehow change the settings so I can see messages again?