Disable OpenMP (without modifying CMakeLists.txt)

I am building a debug build of a project with an existing complicated set of cmake files:
https://sourceforge.net/projects/hugin/

I want to avoid OpenMP for the debug build. I strongly prefer to NOT accomplish that by editing the CMakeLists.txt or other cmake files provided in the project repository (even if I could figure out how to do it by editing those, which so far I can’t).

So the answer, in the earlier thread with the same name as this thread, doesn’t help me.

I am using a shell script to give the cmake command to prepare to build the project. What might I put in that command or preceding that command in that shell script to stop cmake from finding OpenMP or otherwise stop the build files it creates from using OpenMP

This is where Hugin looks for OpenMP:

# Check for OpenMP
IF(APPLE)
  #we need a special search routine for mac, see changes in file CMakeModules/FindOpenMPMac.cmake
  FIND_PACKAGE(OpenMPMac)
ELSE()
  FIND_PACKAGE(OpenMP)
ENDIF()
IF(OPENMP_FOUND)
  MESSAGE(STATUS "Compiler supports OpenMP. Activating support for it.")
  ADD_COMPILE_OPTIONS(${OpenMP_CXX_FLAGS})
  SET(HAVE_OPENMP TRUE)
  IF(OpenMP_CXX_FLAGS AND NOT MSVC)
    SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${OpenMP_CXX_FLAGS}")
    SET(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} ${OpenMP_CXX_FLAGS}")
    SET(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} ${OpenMP_CXX_FLAGS}")
  ENDIF()
ELSE()
  MESSAGE(WARNING "Compiler does not support OpenMP. OpenMP is required for multi-threaded processes. So only single threaded execution is compiled now.") 
ENDIF()

As you may see, the checks are unconditional. If OpenMP can be found, it’ll be activated. You could either make it unfindable (no idea how to do that) or modify this part (I’d just add an option and maybe try to contribute that back to the project?)

This variable should help you:

CMAKE_DISABLE_FIND_PACKAGE_<PackageName>

1 Like
Josef Angstenberger jtxa
March 12

This variable should help you:

CMAKE_DISABLE_FIND_PACKAGE_

That solved it. Please ignore the previous version of this reply (if you saw it before this edit). I had done something careless and was invoking the wrong project’s source code the whole time I thought I was testing your solution.

I added: -DCMAKE_DISABLE_FIND_PACKAGE_OpenMP=TRUE to the command line and that made it not use OpenMP