Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
valgur opened this issue Apr 22, 2024 · 0 comments
Assignees
Milestone

Comments

@valgur
Copy link
Contributor

valgur commented Apr 22, 2024

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: conan-io/conan-center-index#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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants