Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Make CMake not search for Python components on reconfigure

I added googletest to my build using FetchContent like this:

FetchContent_Declare(googletest
    GIT_REPOSITORY https://github.com/google/googletest
    GIT_TAG main
)

FetchContent_MakeAvailable(googletest)

But after I did this, each time CMake needs to rerun its configure/generate steps it takes about ~25 seconds. This is really interfering with my workflow when making iterative changes to the build.

C:\NSEW>cmake --build .
[0/2] Re-checking globbed directories...
[1/2] Re-running CMake...

   | It takes about 20 seconds until the following output is shown |

-- Could NOT find Python (missing: Python_EXECUTABLE Interpreter)
-- Found SFML 2.5.1 in C:/install/lib/cmake/SFML
-- Configuring done
-- Generating done
-- Build files have been written to: C:/NSEW
[0/2] Re-checking globbed directories...
ninja: no work to do.

googletest has an optional Python dependency but since Python isn't installed, CMake tries every possible installation path which takes very long. CMake appears to do this search on every reconfigure. How to stop CMake from doing this very slow search for a component I don't need?

I tried to set the cache variable Python_EXECUTABLE to NO / Python-NOTFOUND but that didn't seem to help.

like image 594
Dexter CD Avatar asked Oct 16 '25 23:10

Dexter CD


1 Answers

You can disable any non-REQUIRED find_package(PackageName) command using CMAKE_DISABLE_FIND_PACKAGE_<PackageName>. This variable has existed since at least CMake 3.0, so this will work in general.

You can set it just before FetchContent_MakeAvailable and then unset() it afterward. Otherwise, just set CMAKE_DISABLE_FIND_PACKAGE_Python=TRUE (and/or ...Python3) at the cmake command line.

like image 139
Alex Reinking Avatar answered Oct 18 '25 20:10

Alex Reinking



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!