10

In my root folder's CMakeLists.txt I have defined the possible configurations to be Debug and Release:

if(NOT CMAKE_CONFIGURATION_TYPES)
  set(CMAKE_CONFIGURATION_TYPES Debug Release)
  set(CMAKE_CONFIGURATION_TYPES "${CMAKE_CONFIGURATION_TYPES}" CACHE STRING "Reset the configurations to what we need" FORCE)
endif()

This works for most of the subprojects of the solution. However, I have two subprojects which don't differentiate between Debug and Release (they do some non-C++ stuff like Doxygen or Typescript compilation). In these subprojects' CmakeLists.txt I just wrote

project(typescript_compilation)

# Do not separate debug and release builds
set(CMAKE_CONFIGURATION_TYPES Release)

And this works if one first opens the Release configuration and then the Debug configuration in the IDE (Visual Studio). I then can switch between Release and Debug and the projects are available and only build once.

If, however, one opens the Debug configuration first after the Cmake generation, the sub-project cannot be loaded with the error

typescript_compilation.vcxproj : error: Cannot load project: project does not contain requested configuration Debug|x64. Please verify that the .sln file is valid and uses only existing project configurations.

So my way seems to be the wrong way to achieve this and the Debug mode only works if the Release mode has been opened and built first. What is the best Cmake way to build some projects only once?

thealchemist
  • 421
  • 4
  • 12
PhilLab
  • 4,777
  • 1
  • 25
  • 77
  • 1
    seems to be a difficult question :-D already posted the second bouty – PhilLab Jun 12 '20 at 13:32
  • two years late, but I'm curious to know more about the project setup. Is it correct that you have a CMake project which _solely_ does a task which is not related to building a cmake-supported language? If so, what's the rationale (what alternatives were considered / exist, and why weren't they chosen)? – starball Jul 18 '22 at 03:26
  • For example, is it possible / have you considered creating a .cmake file which does the same tasks via `add_custom_target` or `add_custom_command`? I think if configured to have a same output location for the "byproducts" of any configuration (Debug, Release), they would be shared without duplicate recomputation – starball Jul 18 '22 at 03:36
  • I'm not familiar with VS IDE (I only use the VS build tools). When you say "project", are you referring to VS's "project"s, or to cmake's concept of a "project"? – starball Jul 18 '22 at 03:43

0 Answers0