[PATCH] D97513: Add ConfigVersion.cmake files
alexreinking created this revision. alexreinking added reviewers: chandlerc, gottesmm, pmccormick. Herald added subscribers: cota, teijeong, rdzhabarov, tatianashp, msifontes, jurahul, Kayjukh, grosul1, Joonsoo, liufengdb, aartbik, lucyrfox, mgester, arpith-jacob, antiagainst, shauheen, rriddle, mehdi_amini, mgorny. Herald added a reviewer: bollu. Herald added a reviewer: sscalpone. alexreinking requested review of this revision. Herald added subscribers: cfe-commits, stephenneuendorffer, nicolasvasilache. Herald added projects: clang, MLIR. When supplying a package with `Config.cmake` files, it is required to also supply a `ConfigVersion.cmake` file which defines compatibility with version numbers. If these files aren't distributed then supplying a version number will fail. But on the other hand, //not// supplying a version number can result in the wrong package being selected. For example, because the base LLVM package //does// supply `LLVMConfigVersion.cmake`, the following can occur: find_package(LLVM 11.0 REQUIRED) # Succeeds find_package(LLD 11.0) # Fails because there's no version config find_package(LLD) # Succeeds, finds version 10. This patch would not affect any existing uses of the CMake build/packages because the `ConfigVersion.cmake` file is ignored when no version is given and the status quo is that supplying a version fails. This patch also fixes a bug I opened a year ago here: https://bugs.llvm.org/show_bug.cgi?id=45027 Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D97513 Files: clang/cmake/modules/CMakeLists.txt clang/cmake/modules/ClangConfigVersion.cmake.in flang/cmake/modules/CMakeLists.txt flang/cmake/modules/FlangConfigVersion.cmake.in lld/CMakeLists.txt lld/cmake/modules/CMakeLists.txt lld/cmake/modules/LLDConfigVersion.cmake.in mlir/CMakeLists.txt mlir/cmake/modules/CMakeLists.txt mlir/cmake/modules/MLIRConfigVersion.cmake.in polly/CMakeLists.txt polly/cmake/CMakeLists.txt polly/cmake/PollyConfigVersion.cmake.in Index: polly/cmake/PollyConfigVersion.cmake.in === --- /dev/null +++ polly/cmake/PollyConfigVersion.cmake.in @@ -0,0 +1,13 @@ +set(PACKAGE_VERSION "@PACKAGE_VERSION@") + +# Polly is API-compatible only with matching major.minor versions +# and patch versions not less than that requested. +if("@POLLY_VERSION_MAJOR@.@POLLY_VERSION_MINOR@" VERSION_EQUAL +"${PACKAGE_FIND_VERSION_MAJOR}.${PACKAGE_FIND_VERSION_MINOR}" + AND NOT "@POLLY_VERSION_PATCH@" VERSION_LESS "${PACKAGE_FIND_VERSION_PATCH}") + set(PACKAGE_VERSION_COMPATIBLE 1) + if("@POLLY_VERSION_PATCH@" VERSION_EQUAL + "${PACKAGE_FIND_VERSION_PATCH}") +set(PACKAGE_VERSION_EXACT 1) + endif() +endif() Index: polly/cmake/CMakeLists.txt === --- polly/cmake/CMakeLists.txt +++ polly/cmake/CMakeLists.txt @@ -71,6 +71,10 @@ ${CMAKE_CURRENT_SOURCE_DIR}/PollyConfig.cmake.in ${POLLY_CONFIG_CMAKE_DIR}/PollyConfig.cmake @ONLY) +configure_file( + ${CMAKE_CURRENT_SOURCE_DIR}/PollyConfigVersion.cmake.in + ${POLLY_CONFIG_CMAKE_DIR}/PollyConfigVersion.cmake + @ONLY) file(GENERATE OUTPUT ${POLLY_CONFIG_CMAKE_DIR}/${POLLY_EXPORTS_FILE_NAME} @@ -120,6 +124,10 @@ ${CMAKE_CURRENT_SOURCE_DIR}/PollyConfig.cmake.in ${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/PollyConfig.cmake @ONLY) +configure_file( + ${CMAKE_CURRENT_SOURCE_DIR}/PollyConfigVersion.cmake.in + ${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/PollyConfigVersion.cmake + @ONLY) file(GENERATE OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/${POLLY_EXPORTS_FILE_NAME} CONTENT "${POLLY_EXPORTS}") @@ -128,6 +136,7 @@ install( FILES "${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/PollyConfig.cmake" +"${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/PollyConfigVersion.cmake" "${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/${POLLY_EXPORTS_FILE_NAME}" DESTINATION "${POLLY_INSTALL_PACKAGE_DIR}") endif () Index: polly/CMakeLists.txt === --- polly/CMakeLists.txt +++ polly/CMakeLists.txt @@ -5,6 +5,7 @@ # Where is LLVM installed? find_package(LLVM CONFIG REQUIRED) + set(PACKAGE_VERSION "${LLVM_PACKAGE_VERSION}") set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${LLVM_CMAKE_DIR}) include(HandleLLVMOptions) include(AddLLVM) @@ -48,6 +49,14 @@ set(POLLY_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}) set(POLLY_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}) +# Compute the Polly version from the LLVM version. +string(REGEX MATCH "([0-9]+)\\.([0-9]+)(\\.([0-9]+))?" POLLY_VERSION ${PACKAGE_VERSION}) +message(STATUS "Polly version: ${POLLY_VERSION}") + +set(POLLY_VERSION_MAJOR "${CMAKE_MATCH_1}") +set(POLLY_VERSION_MINOR "${CMAKE_MATCH_2}") +set(POLLY_VERSION_PATCH "${CMAKE_MATCH_4}") # Using 4 instead of 3 skips the dot before the patch number. + # Add path for custom modules set(CMAKE_MODULE_PATH ${C
[PATCH] D97513: Add ConfigVersion.cmake files
alexreinking added a comment. So with this patch, I tried to imitate the existing code as much as possible. However, I think it would be quite a bit better to use the `write_basic_package_version_file` command from `CMakePackageConfigHelpers`. It gained support for major + minor version compatibility matching in CMake 3.11. Since LLVM is on 3.13 now, I don't see a reason not to use this. Instead of the existing `configure_file` and `*ConfigVersion.cmake.in` combo, we would delete the template (`.in`) and just write: include(CMakePackageConfigHelpers) write_basic_package_version_file( ${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/PollyConfigVersion.cmake VERSION ${POLLY_VERSION} COMPATIBILITY SameMinorVersion ) If the subproject had proper calls to `project()`, like `project(Polly VERSION ${POLLY_VERSION})`, then `write_basic_package_version_file` would default its `VERSION` argument to `${PROJECT_VERSION}`. The template `ConfigVersion.cmake.in` files are also missing an architecture check, so it's possible that a 64-bit build of LLVM could get picked up by a project calling `find_package` while cross compiling to 32-bit. The ones generated by `write_basic_package_version_file` have this check. Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D97513/new/ https://reviews.llvm.org/D97513 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D97513: Add ConfigVersion.cmake files
alexreinking updated this revision to Diff 333657. alexreinking added a comment. Uses write_basic_package_version_file CHANGES SINCE LAST ACTION https://reviews.llvm.org/D97513/new/ https://reviews.llvm.org/D97513 Files: clang/cmake/modules/CMakeLists.txt flang/cmake/modules/CMakeLists.txt lld/CMakeLists.txt lld/cmake/modules/CMakeLists.txt mlir/CMakeLists.txt mlir/cmake/modules/CMakeLists.txt polly/CMakeLists.txt polly/cmake/CMakeLists.txt Index: polly/cmake/CMakeLists.txt === --- polly/cmake/CMakeLists.txt +++ polly/cmake/CMakeLists.txt @@ -67,10 +67,17 @@ # PollyConfig holds the target definitions and general settings, PollyExports # the imported locations +include(CMakePackageConfigHelpers) + configure_file( ${CMAKE_CURRENT_SOURCE_DIR}/PollyConfig.cmake.in ${POLLY_CONFIG_CMAKE_DIR}/PollyConfig.cmake @ONLY) +write_basic_package_version_file( + "${POLLY_CONFIG_CMAKE_DIR}/PollyConfigVersion.cmake" + VERSION "${POLLY_VERSION}" + COMPATIBILITY SameMinorVersion +) file(GENERATE OUTPUT ${POLLY_CONFIG_CMAKE_DIR}/${POLLY_EXPORTS_FILE_NAME} @@ -120,6 +127,11 @@ ${CMAKE_CURRENT_SOURCE_DIR}/PollyConfig.cmake.in ${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/PollyConfig.cmake @ONLY) +write_basic_package_version_file( + "${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/PollyConfigVersion.cmake" + VERSION "${POLLY_VERSION}" + COMPATIBILITY SameMinorVersion +) file(GENERATE OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/${POLLY_EXPORTS_FILE_NAME} CONTENT "${POLLY_EXPORTS}") @@ -128,6 +140,7 @@ install( FILES "${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/PollyConfig.cmake" +"${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/PollyConfigVersion.cmake" "${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/${POLLY_EXPORTS_FILE_NAME}" DESTINATION "${POLLY_INSTALL_PACKAGE_DIR}") endif () Index: polly/CMakeLists.txt === --- polly/CMakeLists.txt +++ polly/CMakeLists.txt @@ -5,6 +5,7 @@ # Where is LLVM installed? find_package(LLVM CONFIG REQUIRED) + set(PACKAGE_VERSION "${LLVM_PACKAGE_VERSION}") set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${LLVM_CMAKE_DIR}) include(HandleLLVMOptions) include(AddLLVM) @@ -48,6 +49,14 @@ set(POLLY_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}) set(POLLY_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}) +# Compute the Polly version from the LLVM version. +string(REGEX MATCH "([0-9]+)\\.([0-9]+)(\\.([0-9]+))?" POLLY_VERSION ${PACKAGE_VERSION}) +message(STATUS "Polly version: ${POLLY_VERSION}") + +set(POLLY_VERSION_MAJOR "${CMAKE_MATCH_1}") +set(POLLY_VERSION_MINOR "${CMAKE_MATCH_2}") +set(POLLY_VERSION_PATCH "${CMAKE_MATCH_4}") # Using 4 instead of 3 skips the dot before the patch number. + # Add path for custom modules set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} Index: mlir/cmake/modules/CMakeLists.txt === --- mlir/cmake/modules/CMakeLists.txt +++ mlir/cmake/modules/CMakeLists.txt @@ -17,6 +17,8 @@ get_property(MLIR_TRANSLATION_LIBS GLOBAL PROPERTY MLIR_TRANSLATION_LIBS) # Generate MlirConfig.cmake for the build tree. +include(CMakePackageConfigHelpers) + set(MLIR_CONFIG_CMAKE_DIR "${mlir_cmake_builddir}") set(MLIR_CONFIG_LLVM_CMAKE_DIR "${llvm_cmake_builddir}") set(MLIR_CONFIG_EXPORTS_FILE "\${MLIR_CMAKE_DIR}/MLIRTargets.cmake") @@ -28,6 +30,11 @@ ${CMAKE_CURRENT_SOURCE_DIR}/MLIRConfig.cmake.in ${mlir_cmake_builddir}/MLIRConfig.cmake @ONLY) +write_basic_package_version_file( + "${mlir_cmake_builddir}/MLIRConfigVersion.cmake" + VERSION "${MLIR_VERSION}" + COMPATIBILITY SameMinorVersion +) set(MLIR_CONFIG_CMAKE_DIR) set(MLIR_CONFIG_LLVM_CMAKE_DIR) set(MLIR_CONFIG_EXPORTS_FILE) @@ -63,6 +70,11 @@ ${CMAKE_CURRENT_SOURCE_DIR}/MLIRConfig.cmake.in ${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/MLIRConfig.cmake @ONLY) +write_basic_package_version_file( + "${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/MLIRConfigVersion.cmake" + VERSION "${MLIR_VERSION}" + COMPATIBILITY SameMinorVersion +) set(MLIR_CONFIG_CODE) set(MLIR_CONFIG_CMAKE_DIR) set(MLIR_CONFIG_LLVM_CMAKE_DIR) @@ -80,6 +92,7 @@ install(FILES ${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/MLIRConfig.cmake +${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/MLIRConfigVersion.cmake ${CMAKE_CURRENT_SOURCE_DIR}/AddMLIR.cmake DESTINATION ${MLIR_INSTALL_PACKAGE_DIR} COMPONENT mlir-cmake-exports) Index: mlir/CMakeLists.txt === --- mlir/CMakeLists.txt +++ mlir/CMakeLists.txt @@ -23,6 +23,8 @@ set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/lib${LLVM_LIBDIR_SUFFIX}") set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/bin") + + set(PACKAGE_VERSION "${LLVM_PACKAGE_VERSION}") endif() set(MLIR_MAIN_SRC_DIR ${CMAKE_CURRENT_SOURCE_DIR} ) @@ -33,6 +35,14 @@ set(MLIR_INCLUDE_DIR ${
[PATCH] D97513: Add ConfigVersion.cmake files
alexreinking updated this revision to Diff 333677. alexreinking added a comment. Use PACKAGE_VERSION instead CHANGES SINCE LAST ACTION https://reviews.llvm.org/D97513/new/ https://reviews.llvm.org/D97513 Files: clang/cmake/modules/CMakeLists.txt flang/cmake/modules/CMakeLists.txt lld/CMakeLists.txt lld/cmake/modules/CMakeLists.txt mlir/CMakeLists.txt mlir/cmake/modules/CMakeLists.txt polly/CMakeLists.txt polly/cmake/CMakeLists.txt Index: polly/cmake/CMakeLists.txt === --- polly/cmake/CMakeLists.txt +++ polly/cmake/CMakeLists.txt @@ -67,10 +67,17 @@ # PollyConfig holds the target definitions and general settings, PollyExports # the imported locations +include(CMakePackageConfigHelpers) + configure_file( ${CMAKE_CURRENT_SOURCE_DIR}/PollyConfig.cmake.in ${POLLY_CONFIG_CMAKE_DIR}/PollyConfig.cmake @ONLY) +write_basic_package_version_file( + "${POLLY_CONFIG_CMAKE_DIR}/PollyConfigVersion.cmake" + VERSION "${PACKAGE_VERSION}" + COMPATIBILITY SameMinorVersion +) file(GENERATE OUTPUT ${POLLY_CONFIG_CMAKE_DIR}/${POLLY_EXPORTS_FILE_NAME} @@ -120,6 +127,11 @@ ${CMAKE_CURRENT_SOURCE_DIR}/PollyConfig.cmake.in ${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/PollyConfig.cmake @ONLY) +write_basic_package_version_file( + "${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/PollyConfigVersion.cmake" + VERSION "${PACKAGE_VERSION}" + COMPATIBILITY SameMinorVersion +) file(GENERATE OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/${POLLY_EXPORTS_FILE_NAME} CONTENT "${POLLY_EXPORTS}") @@ -128,6 +140,7 @@ install( FILES "${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/PollyConfig.cmake" +"${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/PollyConfigVersion.cmake" "${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/${POLLY_EXPORTS_FILE_NAME}" DESTINATION "${POLLY_INSTALL_PACKAGE_DIR}") endif () Index: polly/CMakeLists.txt === --- polly/CMakeLists.txt +++ polly/CMakeLists.txt @@ -5,6 +5,7 @@ # Where is LLVM installed? find_package(LLVM CONFIG REQUIRED) + set(PACKAGE_VERSION "${LLVM_PACKAGE_VERSION}") set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${LLVM_CMAKE_DIR}) include(HandleLLVMOptions) include(AddLLVM) @@ -48,6 +49,14 @@ set(POLLY_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}) set(POLLY_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}) +# Compute the Polly version from the LLVM version. +string(REGEX MATCH "([0-9]+)\\.([0-9]+)(\\.([0-9]+))?" POLLY_VERSION ${PACKAGE_VERSION}) +message(STATUS "Polly version: ${POLLY_VERSION}") + +set(POLLY_VERSION_MAJOR "${CMAKE_MATCH_1}") +set(POLLY_VERSION_MINOR "${CMAKE_MATCH_2}") +set(POLLY_VERSION_PATCH "${CMAKE_MATCH_4}") # Using 4 instead of 3 skips the dot before the patch number. + # Add path for custom modules set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} Index: mlir/cmake/modules/CMakeLists.txt === --- mlir/cmake/modules/CMakeLists.txt +++ mlir/cmake/modules/CMakeLists.txt @@ -17,6 +17,8 @@ get_property(MLIR_TRANSLATION_LIBS GLOBAL PROPERTY MLIR_TRANSLATION_LIBS) # Generate MlirConfig.cmake for the build tree. +include(CMakePackageConfigHelpers) + set(MLIR_CONFIG_CMAKE_DIR "${mlir_cmake_builddir}") set(MLIR_CONFIG_LLVM_CMAKE_DIR "${llvm_cmake_builddir}") set(MLIR_CONFIG_EXPORTS_FILE "\${MLIR_CMAKE_DIR}/MLIRTargets.cmake") @@ -28,6 +30,11 @@ ${CMAKE_CURRENT_SOURCE_DIR}/MLIRConfig.cmake.in ${mlir_cmake_builddir}/MLIRConfig.cmake @ONLY) +write_basic_package_version_file( + "${mlir_cmake_builddir}/MLIRConfigVersion.cmake" + VERSION "${PACKAGE_VERSION}" + COMPATIBILITY SameMinorVersion +) set(MLIR_CONFIG_CMAKE_DIR) set(MLIR_CONFIG_LLVM_CMAKE_DIR) set(MLIR_CONFIG_EXPORTS_FILE) @@ -63,6 +70,11 @@ ${CMAKE_CURRENT_SOURCE_DIR}/MLIRConfig.cmake.in ${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/MLIRConfig.cmake @ONLY) +write_basic_package_version_file( + "${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/MLIRConfigVersion.cmake" + VERSION "${PACKAGE_VERSION}" + COMPATIBILITY SameMinorVersion +) set(MLIR_CONFIG_CODE) set(MLIR_CONFIG_CMAKE_DIR) set(MLIR_CONFIG_LLVM_CMAKE_DIR) @@ -80,6 +92,7 @@ install(FILES ${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/MLIRConfig.cmake +${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/MLIRConfigVersion.cmake ${CMAKE_CURRENT_SOURCE_DIR}/AddMLIR.cmake DESTINATION ${MLIR_INSTALL_PACKAGE_DIR} COMPONENT mlir-cmake-exports) Index: mlir/CMakeLists.txt === --- mlir/CMakeLists.txt +++ mlir/CMakeLists.txt @@ -23,6 +23,8 @@ set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/lib${LLVM_LIBDIR_SUFFIX}") set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/bin") + + set(PACKAGE_VERSION "${LLVM_PACKAGE_VERSION}") endif() set(MLIR_MAIN_SRC_DIR ${CMAKE_CURRENT_SOURCE_DIR} ) @@ -33,6 +35,14 @@ set(MLIR_INCLUDE_DIR ${
[PATCH] D97513: Add ConfigVersion.cmake files
alexreinking updated this revision to Diff 333683. alexreinking added a comment. Drop *ConfigVersion.cmake files from `CMakeFiles` tree CHANGES SINCE LAST ACTION https://reviews.llvm.org/D97513/new/ https://reviews.llvm.org/D97513 Files: clang/cmake/modules/CMakeLists.txt flang/cmake/modules/CMakeLists.txt lld/CMakeLists.txt lld/cmake/modules/CMakeLists.txt mlir/CMakeLists.txt mlir/cmake/modules/CMakeLists.txt polly/CMakeLists.txt polly/cmake/CMakeLists.txt Index: polly/cmake/CMakeLists.txt === --- polly/cmake/CMakeLists.txt +++ polly/cmake/CMakeLists.txt @@ -67,10 +67,17 @@ # PollyConfig holds the target definitions and general settings, PollyExports # the imported locations +include(CMakePackageConfigHelpers) + configure_file( ${CMAKE_CURRENT_SOURCE_DIR}/PollyConfig.cmake.in ${POLLY_CONFIG_CMAKE_DIR}/PollyConfig.cmake @ONLY) +write_basic_package_version_file( + "${POLLY_CONFIG_CMAKE_DIR}/PollyConfigVersion.cmake" + VERSION "${PACKAGE_VERSION}" + COMPATIBILITY SameMinorVersion +) file(GENERATE OUTPUT ${POLLY_CONFIG_CMAKE_DIR}/${POLLY_EXPORTS_FILE_NAME} @@ -128,6 +135,7 @@ install( FILES "${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/PollyConfig.cmake" +"${POLLY_CONFIG_CMAKE_DIR}/PollyConfigVersion.cmake" "${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/${POLLY_EXPORTS_FILE_NAME}" DESTINATION "${POLLY_INSTALL_PACKAGE_DIR}") endif () Index: polly/CMakeLists.txt === --- polly/CMakeLists.txt +++ polly/CMakeLists.txt @@ -5,6 +5,7 @@ # Where is LLVM installed? find_package(LLVM CONFIG REQUIRED) + set(PACKAGE_VERSION "${LLVM_PACKAGE_VERSION}") set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${LLVM_CMAKE_DIR}) include(HandleLLVMOptions) include(AddLLVM) @@ -48,6 +49,14 @@ set(POLLY_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}) set(POLLY_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}) +# Compute the Polly version from the LLVM version. +string(REGEX MATCH "([0-9]+)\\.([0-9]+)(\\.([0-9]+))?" POLLY_VERSION ${PACKAGE_VERSION}) +message(STATUS "Polly version: ${POLLY_VERSION}") + +set(POLLY_VERSION_MAJOR "${CMAKE_MATCH_1}") +set(POLLY_VERSION_MINOR "${CMAKE_MATCH_2}") +set(POLLY_VERSION_PATCH "${CMAKE_MATCH_4}") # Using 4 instead of 3 skips the dot before the patch number. + # Add path for custom modules set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} Index: mlir/cmake/modules/CMakeLists.txt === --- mlir/cmake/modules/CMakeLists.txt +++ mlir/cmake/modules/CMakeLists.txt @@ -17,6 +17,8 @@ get_property(MLIR_TRANSLATION_LIBS GLOBAL PROPERTY MLIR_TRANSLATION_LIBS) # Generate MlirConfig.cmake for the build tree. +include(CMakePackageConfigHelpers) + set(MLIR_CONFIG_CMAKE_DIR "${mlir_cmake_builddir}") set(MLIR_CONFIG_LLVM_CMAKE_DIR "${llvm_cmake_builddir}") set(MLIR_CONFIG_EXPORTS_FILE "\${MLIR_CMAKE_DIR}/MLIRTargets.cmake") @@ -28,6 +30,11 @@ ${CMAKE_CURRENT_SOURCE_DIR}/MLIRConfig.cmake.in ${mlir_cmake_builddir}/MLIRConfig.cmake @ONLY) +write_basic_package_version_file( + "${mlir_cmake_builddir}/MLIRConfigVersion.cmake" + VERSION "${PACKAGE_VERSION}" + COMPATIBILITY SameMinorVersion +) set(MLIR_CONFIG_CMAKE_DIR) set(MLIR_CONFIG_LLVM_CMAKE_DIR) set(MLIR_CONFIG_EXPORTS_FILE) @@ -80,6 +87,7 @@ install(FILES ${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/MLIRConfig.cmake +${mlir_cmake_builddir}/MLIRConfigVersion.cmake ${CMAKE_CURRENT_SOURCE_DIR}/AddMLIR.cmake DESTINATION ${MLIR_INSTALL_PACKAGE_DIR} COMPONENT mlir-cmake-exports) Index: mlir/CMakeLists.txt === --- mlir/CMakeLists.txt +++ mlir/CMakeLists.txt @@ -23,6 +23,8 @@ set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/lib${LLVM_LIBDIR_SUFFIX}") set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/bin") + + set(PACKAGE_VERSION "${LLVM_PACKAGE_VERSION}") endif() set(MLIR_MAIN_SRC_DIR ${CMAKE_CURRENT_SOURCE_DIR} ) @@ -33,6 +35,14 @@ set(MLIR_INCLUDE_DIR ${CMAKE_CURRENT_BINARY_DIR}/include) set(MLIR_TOOLS_DIR ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}) +# Compute the MLIR version from the LLVM version. +string(REGEX MATCH "([0-9]+)\\.([0-9]+)(\\.([0-9]+))?" MLIR_VERSION ${PACKAGE_VERSION}) +message(STATUS "MLIR version: ${MLIR_VERSION}") + +set(MLIR_VERSION_MAJOR "${CMAKE_MATCH_1}") +set(MLIR_VERSION_MINOR "${CMAKE_MATCH_2}") +set(MLIR_VERSION_PATCH "${CMAKE_MATCH_4}") # Using 4 instead of 3 skips the dot before the patch number. + list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules") include(AddMLIR) Index: lld/cmake/modules/CMakeLists.txt === --- lld/cmake/modules/CMakeLists.txt +++ lld/cmake/modules/CMakeLists.txt @@ -12,6 +12,8 @@ export(TARGETS ${LLD_EXPORTS} FILE ${lld_cmake_builddir}
[PATCH] D97513: Add ConfigVersion.cmake files
alexreinking updated this revision to Diff 333687. alexreinking added a comment. Remove unused version variables (that were used in a previous revision) CHANGES SINCE LAST ACTION https://reviews.llvm.org/D97513/new/ https://reviews.llvm.org/D97513 Files: clang/cmake/modules/CMakeLists.txt flang/cmake/modules/CMakeLists.txt lld/cmake/modules/CMakeLists.txt mlir/CMakeLists.txt mlir/cmake/modules/CMakeLists.txt polly/CMakeLists.txt polly/cmake/CMakeLists.txt Index: polly/cmake/CMakeLists.txt === --- polly/cmake/CMakeLists.txt +++ polly/cmake/CMakeLists.txt @@ -67,10 +67,17 @@ # PollyConfig holds the target definitions and general settings, PollyExports # the imported locations +include(CMakePackageConfigHelpers) + configure_file( ${CMAKE_CURRENT_SOURCE_DIR}/PollyConfig.cmake.in ${POLLY_CONFIG_CMAKE_DIR}/PollyConfig.cmake @ONLY) +write_basic_package_version_file( + "${POLLY_CONFIG_CMAKE_DIR}/PollyConfigVersion.cmake" + VERSION "${PACKAGE_VERSION}" + COMPATIBILITY SameMinorVersion +) file(GENERATE OUTPUT ${POLLY_CONFIG_CMAKE_DIR}/${POLLY_EXPORTS_FILE_NAME} @@ -128,6 +135,7 @@ install( FILES "${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/PollyConfig.cmake" +"${POLLY_CONFIG_CMAKE_DIR}/PollyConfigVersion.cmake" "${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/${POLLY_EXPORTS_FILE_NAME}" DESTINATION "${POLLY_INSTALL_PACKAGE_DIR}") endif () Index: polly/CMakeLists.txt === --- polly/CMakeLists.txt +++ polly/CMakeLists.txt @@ -5,6 +5,7 @@ # Where is LLVM installed? find_package(LLVM CONFIG REQUIRED) + set(PACKAGE_VERSION "${LLVM_PACKAGE_VERSION}") set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${LLVM_CMAKE_DIR}) include(HandleLLVMOptions) include(AddLLVM) Index: mlir/cmake/modules/CMakeLists.txt === --- mlir/cmake/modules/CMakeLists.txt +++ mlir/cmake/modules/CMakeLists.txt @@ -17,6 +17,8 @@ get_property(MLIR_TRANSLATION_LIBS GLOBAL PROPERTY MLIR_TRANSLATION_LIBS) # Generate MlirConfig.cmake for the build tree. +include(CMakePackageConfigHelpers) + set(MLIR_CONFIG_CMAKE_DIR "${mlir_cmake_builddir}") set(MLIR_CONFIG_LLVM_CMAKE_DIR "${llvm_cmake_builddir}") set(MLIR_CONFIG_EXPORTS_FILE "\${MLIR_CMAKE_DIR}/MLIRTargets.cmake") @@ -28,6 +30,11 @@ ${CMAKE_CURRENT_SOURCE_DIR}/MLIRConfig.cmake.in ${mlir_cmake_builddir}/MLIRConfig.cmake @ONLY) +write_basic_package_version_file( + "${mlir_cmake_builddir}/MLIRConfigVersion.cmake" + VERSION "${PACKAGE_VERSION}" + COMPATIBILITY SameMinorVersion +) set(MLIR_CONFIG_CMAKE_DIR) set(MLIR_CONFIG_LLVM_CMAKE_DIR) set(MLIR_CONFIG_EXPORTS_FILE) @@ -80,6 +87,7 @@ install(FILES ${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/MLIRConfig.cmake +${mlir_cmake_builddir}/MLIRConfigVersion.cmake ${CMAKE_CURRENT_SOURCE_DIR}/AddMLIR.cmake DESTINATION ${MLIR_INSTALL_PACKAGE_DIR} COMPONENT mlir-cmake-exports) Index: mlir/CMakeLists.txt === --- mlir/CMakeLists.txt +++ mlir/CMakeLists.txt @@ -23,6 +23,8 @@ set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/lib${LLVM_LIBDIR_SUFFIX}") set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/bin") + + set(PACKAGE_VERSION "${LLVM_PACKAGE_VERSION}") endif() set(MLIR_MAIN_SRC_DIR ${CMAKE_CURRENT_SOURCE_DIR} ) Index: lld/cmake/modules/CMakeLists.txt === --- lld/cmake/modules/CMakeLists.txt +++ lld/cmake/modules/CMakeLists.txt @@ -12,6 +12,8 @@ export(TARGETS ${LLD_EXPORTS} FILE ${lld_cmake_builddir}/LLDTargets.cmake) # Generate LLDConfig.cmake for the build tree. +include(CMakePackageConfigHelpers) + set(LLD_CONFIG_CMAKE_DIR "${lld_cmake_builddir}") set(LLD_CONFIG_LLVM_CMAKE_DIR "${llvm_cmake_builddir}") set(LLD_CONFIG_EXPORTS_FILE "${lld_cmake_builddir}/LLDTargets.cmake") @@ -23,6 +25,11 @@ ${CMAKE_CURRENT_SOURCE_DIR}/LLDConfig.cmake.in ${lld_cmake_builddir}/LLDConfig.cmake @ONLY) +write_basic_package_version_file( + "${lld_cmake_builddir}/LLDConfigVersion.cmake" + VERSION "${PACKAGE_VERSION}" + COMPATIBILITY SameMinorVersion +) set(LLD_CONFIG_CMAKE_DIR) set(LLD_CONFIG_LLVM_CMAKE_DIR) set(LLD_CONFIG_EXPORTS_FILE) @@ -59,6 +66,7 @@ install(FILES ${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/LLDConfig.cmake +${lld_cmake_builddir}/LLDConfigVersion.cmake DESTINATION ${LLD_INSTALL_PACKAGE_DIR} COMPONENT lld-cmake-exports) Index: flang/cmake/modules/CMakeLists.txt === --- flang/cmake/modules/CMakeLists.txt +++ flang/cmake/modules/CMakeLists.txt @@ -12,6 +12,8 @@ export(TARGETS ${FLANG_EXPORTS} FILE ${flang_cmake_builddir}/FlangTargets.cmake) # Generate FlangConfig.cmake for the build tree. +incl
[PATCH] D97513: Add ConfigVersion.cmake files
alexreinking updated this revision to Diff 333688. alexreinking added a comment. Update & wrap commit message CHANGES SINCE LAST ACTION https://reviews.llvm.org/D97513/new/ https://reviews.llvm.org/D97513 Files: clang/cmake/modules/CMakeLists.txt flang/cmake/modules/CMakeLists.txt lld/cmake/modules/CMakeLists.txt mlir/CMakeLists.txt mlir/cmake/modules/CMakeLists.txt polly/CMakeLists.txt polly/cmake/CMakeLists.txt Index: polly/cmake/CMakeLists.txt === --- polly/cmake/CMakeLists.txt +++ polly/cmake/CMakeLists.txt @@ -67,10 +67,17 @@ # PollyConfig holds the target definitions and general settings, PollyExports # the imported locations +include(CMakePackageConfigHelpers) + configure_file( ${CMAKE_CURRENT_SOURCE_DIR}/PollyConfig.cmake.in ${POLLY_CONFIG_CMAKE_DIR}/PollyConfig.cmake @ONLY) +write_basic_package_version_file( + "${POLLY_CONFIG_CMAKE_DIR}/PollyConfigVersion.cmake" + VERSION "${PACKAGE_VERSION}" + COMPATIBILITY SameMinorVersion +) file(GENERATE OUTPUT ${POLLY_CONFIG_CMAKE_DIR}/${POLLY_EXPORTS_FILE_NAME} @@ -128,6 +135,7 @@ install( FILES "${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/PollyConfig.cmake" +"${POLLY_CONFIG_CMAKE_DIR}/PollyConfigVersion.cmake" "${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/${POLLY_EXPORTS_FILE_NAME}" DESTINATION "${POLLY_INSTALL_PACKAGE_DIR}") endif () Index: polly/CMakeLists.txt === --- polly/CMakeLists.txt +++ polly/CMakeLists.txt @@ -5,6 +5,7 @@ # Where is LLVM installed? find_package(LLVM CONFIG REQUIRED) + set(PACKAGE_VERSION "${LLVM_PACKAGE_VERSION}") set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${LLVM_CMAKE_DIR}) include(HandleLLVMOptions) include(AddLLVM) Index: mlir/cmake/modules/CMakeLists.txt === --- mlir/cmake/modules/CMakeLists.txt +++ mlir/cmake/modules/CMakeLists.txt @@ -17,6 +17,8 @@ get_property(MLIR_TRANSLATION_LIBS GLOBAL PROPERTY MLIR_TRANSLATION_LIBS) # Generate MlirConfig.cmake for the build tree. +include(CMakePackageConfigHelpers) + set(MLIR_CONFIG_CMAKE_DIR "${mlir_cmake_builddir}") set(MLIR_CONFIG_LLVM_CMAKE_DIR "${llvm_cmake_builddir}") set(MLIR_CONFIG_EXPORTS_FILE "\${MLIR_CMAKE_DIR}/MLIRTargets.cmake") @@ -28,6 +30,11 @@ ${CMAKE_CURRENT_SOURCE_DIR}/MLIRConfig.cmake.in ${mlir_cmake_builddir}/MLIRConfig.cmake @ONLY) +write_basic_package_version_file( + "${mlir_cmake_builddir}/MLIRConfigVersion.cmake" + VERSION "${PACKAGE_VERSION}" + COMPATIBILITY SameMinorVersion +) set(MLIR_CONFIG_CMAKE_DIR) set(MLIR_CONFIG_LLVM_CMAKE_DIR) set(MLIR_CONFIG_EXPORTS_FILE) @@ -80,6 +87,7 @@ install(FILES ${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/MLIRConfig.cmake +${mlir_cmake_builddir}/MLIRConfigVersion.cmake ${CMAKE_CURRENT_SOURCE_DIR}/AddMLIR.cmake DESTINATION ${MLIR_INSTALL_PACKAGE_DIR} COMPONENT mlir-cmake-exports) Index: mlir/CMakeLists.txt === --- mlir/CMakeLists.txt +++ mlir/CMakeLists.txt @@ -23,6 +23,8 @@ set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/lib${LLVM_LIBDIR_SUFFIX}") set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/bin") + + set(PACKAGE_VERSION "${LLVM_PACKAGE_VERSION}") endif() set(MLIR_MAIN_SRC_DIR ${CMAKE_CURRENT_SOURCE_DIR} ) Index: lld/cmake/modules/CMakeLists.txt === --- lld/cmake/modules/CMakeLists.txt +++ lld/cmake/modules/CMakeLists.txt @@ -12,6 +12,8 @@ export(TARGETS ${LLD_EXPORTS} FILE ${lld_cmake_builddir}/LLDTargets.cmake) # Generate LLDConfig.cmake for the build tree. +include(CMakePackageConfigHelpers) + set(LLD_CONFIG_CMAKE_DIR "${lld_cmake_builddir}") set(LLD_CONFIG_LLVM_CMAKE_DIR "${llvm_cmake_builddir}") set(LLD_CONFIG_EXPORTS_FILE "${lld_cmake_builddir}/LLDTargets.cmake") @@ -23,6 +25,11 @@ ${CMAKE_CURRENT_SOURCE_DIR}/LLDConfig.cmake.in ${lld_cmake_builddir}/LLDConfig.cmake @ONLY) +write_basic_package_version_file( + "${lld_cmake_builddir}/LLDConfigVersion.cmake" + VERSION "${PACKAGE_VERSION}" + COMPATIBILITY SameMinorVersion +) set(LLD_CONFIG_CMAKE_DIR) set(LLD_CONFIG_LLVM_CMAKE_DIR) set(LLD_CONFIG_EXPORTS_FILE) @@ -59,6 +66,7 @@ install(FILES ${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/LLDConfig.cmake +${lld_cmake_builddir}/LLDConfigVersion.cmake DESTINATION ${LLD_INSTALL_PACKAGE_DIR} COMPONENT lld-cmake-exports) Index: flang/cmake/modules/CMakeLists.txt === --- flang/cmake/modules/CMakeLists.txt +++ flang/cmake/modules/CMakeLists.txt @@ -12,6 +12,8 @@ export(TARGETS ${FLANG_EXPORTS} FILE ${flang_cmake_builddir}/FlangTargets.cmake) # Generate FlangConfig.cmake for the build tree. +include(CMakePackageConfigHelpers) + set(FLANG
[PATCH] D97513: [CMake] Add ConfigVersion.cmake files
alexreinking updated this revision to Diff 333690. alexreinking retitled this revision from "Add ConfigVersion.cmake files" to "[CMake] Add ConfigVersion.cmake files". alexreinking added a comment. Herald added a project: LLVM. Herald added a subscriber: llvm-commits. As requested, move instances of `include(CMakePackageConfigHelpers)` to `AddLLVM.cmake`. CHANGES SINCE LAST ACTION https://reviews.llvm.org/D97513/new/ https://reviews.llvm.org/D97513 Files: clang/cmake/modules/CMakeLists.txt flang/cmake/modules/CMakeLists.txt lld/cmake/modules/CMakeLists.txt llvm/cmake/modules/AddLLVM.cmake llvm/cmake/modules/CMakeLists.txt mlir/CMakeLists.txt mlir/cmake/modules/CMakeLists.txt polly/CMakeLists.txt polly/cmake/CMakeLists.txt Index: polly/cmake/CMakeLists.txt === --- polly/cmake/CMakeLists.txt +++ polly/cmake/CMakeLists.txt @@ -71,6 +71,11 @@ ${CMAKE_CURRENT_SOURCE_DIR}/PollyConfig.cmake.in ${POLLY_CONFIG_CMAKE_DIR}/PollyConfig.cmake @ONLY) +write_basic_package_version_file( + "${POLLY_CONFIG_CMAKE_DIR}/PollyConfigVersion.cmake" + VERSION "${PACKAGE_VERSION}" + COMPATIBILITY SameMinorVersion +) file(GENERATE OUTPUT ${POLLY_CONFIG_CMAKE_DIR}/${POLLY_EXPORTS_FILE_NAME} @@ -128,6 +133,7 @@ install( FILES "${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/PollyConfig.cmake" +"${POLLY_CONFIG_CMAKE_DIR}/PollyConfigVersion.cmake" "${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/${POLLY_EXPORTS_FILE_NAME}" DESTINATION "${POLLY_INSTALL_PACKAGE_DIR}") endif () Index: polly/CMakeLists.txt === --- polly/CMakeLists.txt +++ polly/CMakeLists.txt @@ -5,6 +5,7 @@ # Where is LLVM installed? find_package(LLVM CONFIG REQUIRED) + set(PACKAGE_VERSION "${LLVM_PACKAGE_VERSION}") set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${LLVM_CMAKE_DIR}) include(HandleLLVMOptions) include(AddLLVM) Index: mlir/cmake/modules/CMakeLists.txt === --- mlir/cmake/modules/CMakeLists.txt +++ mlir/cmake/modules/CMakeLists.txt @@ -28,6 +28,11 @@ ${CMAKE_CURRENT_SOURCE_DIR}/MLIRConfig.cmake.in ${mlir_cmake_builddir}/MLIRConfig.cmake @ONLY) +write_basic_package_version_file( + "${mlir_cmake_builddir}/MLIRConfigVersion.cmake" + VERSION "${PACKAGE_VERSION}" + COMPATIBILITY SameMinorVersion +) set(MLIR_CONFIG_CMAKE_DIR) set(MLIR_CONFIG_LLVM_CMAKE_DIR) set(MLIR_CONFIG_EXPORTS_FILE) @@ -80,6 +85,7 @@ install(FILES ${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/MLIRConfig.cmake +${mlir_cmake_builddir}/MLIRConfigVersion.cmake ${CMAKE_CURRENT_SOURCE_DIR}/AddMLIR.cmake DESTINATION ${MLIR_INSTALL_PACKAGE_DIR} COMPONENT mlir-cmake-exports) Index: mlir/CMakeLists.txt === --- mlir/CMakeLists.txt +++ mlir/CMakeLists.txt @@ -23,6 +23,8 @@ set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/lib${LLVM_LIBDIR_SUFFIX}") set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/bin") + + set(PACKAGE_VERSION "${LLVM_PACKAGE_VERSION}") endif() set(MLIR_MAIN_SRC_DIR ${CMAKE_CURRENT_SOURCE_DIR} ) Index: llvm/cmake/modules/CMakeLists.txt === --- llvm/cmake/modules/CMakeLists.txt +++ llvm/cmake/modules/CMakeLists.txt @@ -128,7 +128,6 @@ @ONLY) # Generate LLVMConfigVersion.cmake for build tree (later copied to install tree). -include(CMakePackageConfigHelpers) write_basic_package_version_file( "${llvm_cmake_builddir}/LLVMConfigVersion.cmake" VERSION "${PACKAGE_VERSION}" Index: llvm/cmake/modules/AddLLVM.cmake === --- llvm/cmake/modules/AddLLVM.cmake +++ llvm/cmake/modules/AddLLVM.cmake @@ -1,6 +1,7 @@ include(LLVMProcessSources) include(LLVM-Config) include(DetermineGCCCompatible) +include(CMakePackageConfigHelpers) function(llvm_update_compile_flags name) get_property(sources TARGET ${name} PROPERTY SOURCES) Index: lld/cmake/modules/CMakeLists.txt === --- lld/cmake/modules/CMakeLists.txt +++ lld/cmake/modules/CMakeLists.txt @@ -23,6 +23,11 @@ ${CMAKE_CURRENT_SOURCE_DIR}/LLDConfig.cmake.in ${lld_cmake_builddir}/LLDConfig.cmake @ONLY) +write_basic_package_version_file( + "${lld_cmake_builddir}/LLDConfigVersion.cmake" + VERSION "${PACKAGE_VERSION}" + COMPATIBILITY SameMinorVersion +) set(LLD_CONFIG_CMAKE_DIR) set(LLD_CONFIG_LLVM_CMAKE_DIR) set(LLD_CONFIG_EXPORTS_FILE) @@ -59,6 +64,7 @@ install(FILES ${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/LLDConfig.cmake +${lld_cmake_builddir}/LLDConfigVersion.cmake DESTINATION ${LLD_INSTALL_PACKAGE_DIR} COMPONENT lld-cmake-exports) Index: flang/cmake/modules/CMakeLists.txt ==