0

At the moment I'm compiling via

cmake --build . --config RelWithDebInfo

I'm not sure if this makes sense but it works. I would like to use the debugging of CMake which, afaik, can be set via DCMAKE_BUILD_TYPE=Debug. When I try to use this the compiling itself works:

cmake -DCMAKE_BUILD_TYPE=Debug .

but here I don't get an .exe file somewhere. I guess I miss the --build or --config option from before but how do I properly add them?

edit: Thanks to vre's input I'm coming along better. However, this is the output now:

C:\geant4\sim> cmake -DCMAKE_BUILD_TYPE=Debug .
-- Selecting Windows SDK version 10.0.22000.0 to target Windows 10.0.19042.
-- Configuring done
-- Generating done
CMake Warning:
  Manually-specified variables were not used by the project:

    CMAKE_BUILD_TYPE


-- Build files have been written to: C:/geant4/sim

why is the build type not used?

Ben
  • 1,432
  • 4
  • 20
  • 43
  • 1
    Working with CMake is a two step process. First you configure your project by running `cmake -DCMAKE_BUILD_TYPE=Debug .` Then you build your project by running `cmake --build . --config Debug` – vre Jul 05 '22 at 14:57
  • @vre Thanks a lot! The prefix "Debug" at the end of the build command, is it only the folder name? – Ben Jul 05 '22 at 15:00
  • 1
    No, that's the configuration to build. Out of the box CMake is aware of `Debug,Release,RelWithDebInfo` configurations (or call them build types). You may explicitely specify the build and source folders by using the `-B` and `-S` options, e.g. `cmake -S -B -DCMAKE_BUILD_TYPE=Debug` – vre Jul 05 '22 at 15:03
  • @vre Thanks again! When I use the above commands, I receive above output. Is this correct resp. does it make sense? Shouldn't the build type be considered? – Ben Jul 05 '22 at 15:05
  • 1
    It depends. When you use a single config generator it is definitely considered. But as you specified `Windows-10` tag you are probably using Visual Studio or MSVC. That is a multi config generator and you need to specify the --config when building from command line. See CMake online [docs](https://cmake.org/cmake/help/latest/manual/cmake.1.html) for the command line options. – vre Jul 05 '22 at 15:09
  • 1
    I always prefer explicitly setting the CMake generator, I suppose in your case this would be either "Visual Studio 16 2019" or "Visual Studio 17 2022" So the CMake command line would take another arg `-G "Visual Studio 16 2019"`. To specify the build architecture you would use another arg `-A`. For 32bit it is `-A Win32` and for 64bit it is `-A x64`. – vre Jul 05 '22 at 15:13
  • @vre Thanks for your help! Tbh, I'm a bit overwhelmed. Could you please provide me the entire syntax? Despite from that, I found " --config For multi-configuration tools, choose configuration . " but when I use " cmake --build . --config cfg " I receive " This project doesn't contain the Configuration and Platform combination of cfg|x64 " – Ben Jul 05 '22 at 15:16
  • For " cmake --build . --config -G "Visual Studio 17 2022" " I receive " CMake Error: Invalid value used with --config " – Ben Jul 05 '22 at 15:18
  • 1
    OK. The configuration call should be `cmake -S -B -G "Visual Studio 17 2022" -A x64` for the 64 bit build. The build call should be `cmake --build --config Debug`. MAke sure you delete the file `CMakeCache.txt` in the build folder when reconfiguring. I just noticed my `building from command line` phrase could be misinterpreted. – vre Jul 05 '22 at 15:20
  • Thanks a lot again! This works now. Is it possible to combine all these commands in a single terminal syntax? However, I am stuck the next point: https://stackoverflow.com/questions/72872030/abort-has-been-called – Ben Jul 05 '22 at 15:34
  • 1
    `CMAKE_BUILD_TYPE` is only relevant for single configuration generators. The Visual Studio generators are all multi configuration generators requiring you to pass `--config ` every time you use `cmake` with the build directories for things **other than (re)configuration**. – fabian Jul 05 '22 at 17:24
  • @fabian thanks for the input, I'll try to get a hold of it :) – Ben Jul 06 '22 at 05:08

0 Answers0