Search code examples
cmakemakefilegtkmm

Why are the build folders empty after running cmake command?


I am trying to follow the tutorial but I can't figure out why my build_debug and build_release are empty and nothing is compiled when I run the cmake -DCMAKE_BUILD_TYPE=Debug ../ followed by make

and I am trying to compile the following

#include <gtkmm.h>
int main(int argc, char * argv[])
{
    auto app = Gtk::Application::create("org.gtkmm.example");
    return 0;
}

as for the contents of the parent CMakeLists.txt

cmake_minimum_required(VERSION 3.26)
project(exmaple)
find_package(PkgConfig)
pkg_check_modules(GTKMM gtkmm-4.0)
add_subdirectory(src)

and the child CMakelists.txt in src

link_directories(
    ${GTKMM_LIBRARY_DIRS}  )

include_directories(
    ${GTKMM_INCLUDE_DIRS}  )

add_executable(app
    main.cpp)

target_link_libraries(app 
    ${GTKMM_LIBRARIES}  )

after running cmake -DCMAKE_BUILD_TYPE=Debug ../ both build folders are empty. The directory tree looks like this:

.
├── build_debug
├── build_release
├── CMakeCache.txt
├── CMakeFiles
│   ├── 3.26.1
│   │   ├── CMakeCCompiler.cmake
│   │   ├── CMakeCXXCompiler.cmake
│   │   ├── CMakeDetermineCompilerABI_C.bin
│   │   ├── CMakeDetermineCompilerABI_CXX.bin
│   │   ├── CMakeSystem.cmake
│   │   ├── CompilerIdC
│   │   │   ├── a.out
│   │   │   ├── CMakeCCompilerId.c
│   │   │   └── tmp
│   │   └── CompilerIdCXX
│   │       ├── a.out
│   │       ├── CMakeCXXCompilerId.cpp
│   │       └── tmp
│   ├── app.dir
│   │   ├── build.make
│   │   ├── cmake_clean.cmake
│   │   ├── compiler_depend.internal
│   │   ├── compiler_depend.make
│   │   ├── compiler_depend.ts
│   │   ├── DependInfo.cmake
│   │   ├── depend.make
│   │   ├── flags.make
│   │   ├── link.txt
│   │   ├── progress.make
│   │   └── src
│   │       ├── main.cpp.o
│   │       └── main.cpp.o.d
│   ├── cmake.check_cache
│   ├── CMakeConfigureLog.yaml
│   ├── CMakeDirectoryInformation.cmake
│   ├── Makefile2
│   ├── Makefile.cmake
│   ├── pkgRedirects
│   ├── progress.marks
│   └── TargetDirectories.txt
├── cmake_install.cmake
├── CMakeLists.txt
├── Makefile
└── src
    ├── app
    ├── CMakeFiles
    │   ├── app.dir
    │   │   ├── build.make
    │   │   ├── cmake_clean.cmake
    │   │   ├── compiler_depend.make
    │   │   ├── compiler_depend.ts
    │   │   ├── DependInfo.cmake
    │   │   ├── depend.make
    │   │   ├── flags.make
    │   │   ├── link.txt
    │   │   ├── main.cpp.o
    │   │   ├── main.cpp.o.d
    │   │   └── progress.make
    │   ├── CMakeDirectoryInformation.cmake
    │   └── progress.marks
    ├── cmake_install.cmake
    ├── CMakeLists.txt
    ├── main.cpp
    └── Makefile

15 directories, 50 files

Solution

  • You did an in-source build instead of an out-of-source build. You can specify where the build directory should be using the -B flag of the generate command, and the source directory using the -S flag of the generate command.

    Here's the table from the docs describing what happens if you specify none, some, or all of those flags:

    Command Line Source Dir Build Dir
    cmake src src cwd
    cmake build (existing) loaded build
    cmake -S src src cwd
    cmake -S src build src build
    cmake -S src -B build src build
    cmake -B build cwd build
    cmake -B build src src build
    cmake -B build -S src src build

    Seeing that you pre-created build_debug/ and build_release/, and that you're using -DCMAKE_BUILD_TYPE=..., which is only for single-config generators, what you probably meant to do was something along the lines of the following (with the current working directory being the root directory of your project (the one containing src/)):

    cmake -S . -B build_debug -DCMAKE_BUILD_TYPE=Debug ...
    cmake -S . -B build_release -DCMAKE_BUILD_TYPE=Release ...