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?