conan icon indicating copy to clipboard operation
conan copied to clipboard

[bug] Cannot force generated Find*.cmake modules to fail from the packaged CMake modules

Open valgur opened this issue 1 year ago • 0 comments

Describe the bug

I am in the process of adding compatibility with the official FindOpenMP.cmake CMake module to the llvm-openmp package on CCI: https://github.com/conan-io/conan-center-index/pull/22353

Everything works as expected, except two small details for "module" mode output from the CMakeDeps generator:

  • find_package(OpenMP MODULE REQUIRED COMPONENTS Fortran) and find_package(OpenMP <some high version> MODULE REQUIRED) don't fail.
  • The version set by the custom CMake module gets overridden - the official FindOpenMP sets the version to the OpenMP API standard version supported by the implementation.

Both of these issues are caused by the following block at the end of FindOpenMP.cmake from CMakeDeps:

# Only the first installed configuration is included to avoid the collision
foreach(_BUILD_MODULE ${llvm-openmp_BUILD_MODULES_PATHS_RELEASE} )
    message(${OpenMP_MESSAGE_MODE} "Conan: Including build module from '${_BUILD_MODULE}'")
    include(${_BUILD_MODULE})
endforeach()

include(FindPackageHandleStandardArgs)
set(OpenMP_FOUND 1)
set(OpenMP_VERSION "18.1.3")

find_package_handle_standard_args(OpenMP
                                  REQUIRED_VARS OpenMP_VERSION
                                  VERSION_VAR OpenMP_VERSION)
mark_as_advanced(OpenMP_FOUND OpenMP_VERSION)

I would recommend adjusting the logic there to do the following instead:

unset(OpenMP_FOUND)
unset(OpenMP_VERSION)

# Only the first installed configuration is included to avoid the collision
foreach(_BUILD_MODULE ${llvm-openmp_BUILD_MODULES_PATHS_RELEASE} )
    message(${OpenMP_MESSAGE_MODE} "Conan: Including build module from '${_BUILD_MODULE}'")
    include(${_BUILD_MODULE})
endforeach()

include(FindPackageHandleStandardArgs)
if(NOT DEFINED OpenMP_FOUND)
    set(OpenMP_FOUND 1)
endif()
if(NOT DEFINED OpenMP_VERSION)
    set(OpenMP_VERSION "18.1.3")
endif()

find_package_handle_standard_args(OpenMP
                                  REQUIRED_VARS OpenMP_VERSION
                                  VERSION_VAR OpenMP_VERSION)
mark_as_advanced(OpenMP_FOUND OpenMP_VERSION)

How to reproduce it

Uncomment https://github.com/conan-io/conan-center-index/pull/22353/files#diff-6fca027d0646da5134891fc8afe91b18d63ee958917d15643746aa5c54855787R10-R14 and build the package.

valgur avatar Apr 22 '24 07:04 valgur