-
Notifications
You must be signed in to change notification settings - Fork 496
[CMAKE] Set the project version through the cmake project macro #3605
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
base: main
Are you sure you want to change the base?
Conversation
…ndard config mode to find the project in the config.cmake file. Set cached variables for the version and abi number for in-tree builds with fetch content. Test the cached varaibles are set properly in ci
✅ Deploy Preview for opentelemetry-cpp-api-docs canceled.
|
@@ -487,13 +487,11 @@ function(otel_install_cmake_config) | |||
"${PROJECT_SOURCE_DIR}/cmake/templates/opentelemetry-cpp-config.cmake.in" | |||
"${CMAKE_CURRENT_BINARY_DIR}/cmake/${PROJECT_NAME}/${PROJECT_NAME}-config.cmake" | |||
INSTALL_DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}" | |||
PATH_VARS OPENTELEMETRY_ABI_VERSION_NO OPENTELEMETRY_VERSION PROJECT_NAME |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some of the variables set to PATH_VARS here are not paths (OPENTELEMETRY_ABI_VERSION_NO, OPENTELEMETRY_VERSION, PROJECT_NAME) and have been removed.
|
||
# Write version file for find_package(opentelemetry-cpp CONFIG) | ||
write_basic_package_version_file( | ||
"${CMAKE_CURRENT_BINARY_DIR}/cmake/${PROJECT_NAME}/${PROJECT_NAME}-config-version.cmake" | ||
VERSION ${OPENTELEMETRY_VERSION} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
By setting the VERSION arg in the project macro we don't need to explicitly set the version again here. CMake will use the internal variables (PROJECT_VERSION, CMAKE_PROJECT_VERSION).
FOUND_VAR ${CMAKE_FIND_PACKAGE_NAME}_FOUND | ||
REQUIRED_VARS OPENTELEMETRY_CPP_INCLUDE_DIRS OPENTELEMETRY_CPP_LIBRARIES) | ||
${CMAKE_FIND_PACKAGE_NAME} | ||
CONFIG_MODE |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Setting the CONFIG_MODE here is best and will provide a better message to the user that includes the project version found.
See https://cmake.org/cmake/help/latest/module/FindPackageHandleStandardArgs.html
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FOUND_VAR has been deprecated and removed in this PR
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #3605 +/- ##
=======================================
Coverage 90.03% 90.03%
=======================================
Files 220 220
Lines 7069 7069
=======================================
Hits 6364 6364
Misses 705 705 🚀 New features to boost your workflow:
|
The cmake
project
macro takesVERSION
andLANGUAGE
args which are not currently being set in otel-cppCMakeLists.txt
.CMake uses the
VERSION
arg to set internal variables (See https://cmake.org/cmake/help/v3.31/command/project.html#options) which are used by CMake. One example is for providing more info to the user when they callfind_package(opentelemetry-cpp CONFIG)
.Previous cmake message when calling
find_package(opentelemetry-cpp CONFIG)
New cmake message when calling
find_package(opentelemetry-cpp CONFIG)
Changes
OPENTELEMETRY_VERSION
andOPENTELEMETRY_ABI_VERSION_NO
variables tocmake/version.cmake
VERSION
andLANGUAGE
args inproject(opentelemetry-cpp ...)
OPENTELEMETRY_VERSION
andOPENTELEMETRY_ABI_VERSION_NO
as cached variables so users building otel-cpp in-tree with their project can know what version and abi number has been built.For significant contributions please make sure you have completed the following items:
CHANGELOG.md
updated for non-trivial changes