Configure custom commands and targets (e.g., for generating docs) without compiler checks

Following the documentation I am able to define a custom commands and targets for generating documentation.

However, when integrated into my project’s CMakeLists.txt, the configuration stage performs checks that the compiler is able to compile a simple source file, which I’d like to avoid.

In some cases, developers may be working solely on writing and updating documentation, and it would be helpful to be able to build it without the needing the compiler, especially because it occupies a floating license for a period of time.

Is there a recommended way to isolate such targets from the main configuration process to prevent the compiler from being used?

By default, the project() command enables the C and CXX languages. If you don’t want that, you have to explicitly say so. Here’s an example of the start of a top level CMakeLists.txt file that does that:

cmake_minimum_required(VERSION 3.24)
project(some_proj LANGUAGES NONE)

I chose a fairly arbitrary version for the first line.

Thanks for that! Do you know if there are side effects from this? My project is a C project, so I’m not sure I want to remove this entirely. I suppose I could always add an option to conditionally set the language:

option(DOCS_ONLY "Build only documentation without compiler checks" OFF)

if(DOCS_ONLY)
    project(MyProject LANGUAGES NONE)
else()
    project(MyProject LANGUAGES C)
endif()

Another variation:

cmake_minimum_required(VERSION 3.24)
project(some_proj LANGUAGES NONE)

if(NOT DOCS_ONLY)
    enable_language(C)
endif()
1 Like