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

Implement dynamic versioning #1

Open
wants to merge 2 commits into
base: FetchContent
Choose a base branch
from

Conversation

LecrisUT
Copy link

@LecrisUT LecrisUT commented Mar 9, 2023

I have left out setting the logic of how to configure CPM.cmake if it is release or not. You can do that from GIT_DESCRIBE (if it has a post-version or not)

@LecrisUT
Copy link
Author

LecrisUT commented Mar 9, 2023

Also please rebase this later after we've resolved the discussion in the PR

@flagarde
Copy link
Owner

@LecrisUT Nice work ! Thanks a lot. I didn't know it was possible to do that :) This will be very nice even for my personal projects.

So if I understand correctly the only thing I need to do now is to check is the version has a pos-version to trigger a warning on CPM to warn user ?

@LecrisUT
Copy link
Author

Yes, I've made a comment on the original PR about a regex you can use for that.

This will be very nice even for my personal projects.

Be careful that as I've written in my note, this does not work for build-able cmake projects. I am still working on an interface for that and if you're interested I'll ping you back when I have that.

@flagarde
Copy link
Owner

Yes, I've made a comment on the original PR about a regex you can use for that.

This will be very nice even for my personal projects.

Be careful that as I've written in my note, this does not work for build-able cmake projects. I am still working on an interface for that and if you're interested I'll ping you back when I have that.

You mean it is not econfiguring on version changes?

@LecrisUT
Copy link
Author

I.e.:

$ cmake -B ./build_dir -S ./
$ cmake --build ./build_dir
$ git tag v1.2.3
$ cmake --build ./build_dir

Last step will not be re-configured. There are ways around it by defining a custom_target, changing a file that is linked to CMAKE_CONFIGURE_DEPENDS and maybe delete some other linked configured files. That's what I am trying to finish implementing on that file.

@LecrisUT
Copy link
Author

@flagarde Heads up LecrisUT/CmakeExtraUtils if you want to try it out and give some feedback. In principle this one should re-build itself whenever a version is changed. I've added some convenience files to be able to link if you want a file to be re-built when a commit changed, version changed, etc. An example of how to use it:

cmake_minimum_required(VERSION 3.25)

find_package(CmakeExtraUtils REQUIRED)

include(DynamicVersion)
dynamic_version(PROJECT_PREFIX My_Project_)

project(My_Project
		VERSION ${PROJECT_VERSION})

configure_file(version.cpp.in version.cpp)
add_library(version_lib ${CMAKE_CURRENT_BINARY_DIR}/version.cpp)

# Make sure version is re-calculated even if you pass `cmake --build . --target version_lib`
# `My_Project_Version` is automatically generated target with the name from `PROJECT_PREFIX`
add_dependencies(version_lib My_Project_Version)

# Rebuild `version.cpp` whenever the version changes
# `.version` is automatically generated
set_property(SOURCE version.cpp.in APPEND PROPERTY
		OBJECT_DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/.version) 

Would appreciate any testing or feedback on this

@flagarde
Copy link
Owner

@flagarde Heads up LecrisUT/CmakeExtraUtils if you want to try it out and give some feedback. In principle this one should re-build itself whenever a version is changed. I've added some convenience files to be able to link if you want a file to be re-built when a commit changed, version changed, etc. An example of how to use it:

cmake_minimum_required(VERSION 3.25)

find_package(CmakeExtraUtils REQUIRED)

include(DynamicVersion)
dynamic_version(PROJECT_PREFIX My_Project_)

project(My_Project
		VERSION ${PROJECT_VERSION})

configure_file(version.cpp.in version.cpp)
add_library(version_lib ${CMAKE_CURRENT_BINARY_DIR}/version.cpp)

# Make sure version is re-calculated even if you pass `cmake --build . --target version_lib`
# `My_Project_Version` is automatically generated target with the name from `PROJECT_PREFIX`
add_dependencies(version_lib My_Project_Version)

# Rebuild `version.cpp` whenever the version changes
# `.version` is automatically generated
set_property(SOURCE version.cpp.in APPEND PROPERTY
		OBJECT_DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/.version) 

Would appreciate any testing or feedback on this

Looks very nice. I will try to dedicate so time on this. Thx for this nice work 😀

@LecrisUT
Copy link
Author

LecrisUT commented Mar 30, 2023

This is more relevant in the PR, but I don't want to pollute it, especially since the maintainers did not respond to us yet. The installation location does not work for using with LANGUAGES NONE projects. See this issue.

The idea is that /usr/local/lib64/cmake/<Project> is for architecture dependent projects. This however is not architecture dependent and should be allowed to be used by projects with LANGUAGES NONE which by design will not look into those files. One location that I found to work is <Prefix>/share/cmake/<Project> (<Prefix>/cmake/<Project> did not work apparently)

This seems to work:

install(FILES
	${CMAKE_CURRENT_BINARY_DIR}/<Project>ConfigVersion.cmake
	${CMAKE_CURRENT_BINARY_DIR}/<Project>Config.cmake
	DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/cmake/<Project>
	)

I yes you need to activate a language for cmake to find the right place. I enable C language when installing so it should be ok.

@flagarde
Copy link
Owner

@LecrisUT yes you need to activate a language for cmake to find the right place. I enable C language when installing so it should be ok?

@LecrisUT
Copy link
Author

You don't actually need to, it's just a developer warning. The only variable that will not be constructed is ${CMAKE_INSTALL_LIBDIR}. The sinppet above does work and I'm using it in CMakeExtraUtils

@flagarde
Copy link
Owner

flagarde commented Apr 3, 2023

Good to know that there is a place that we can use. I didn't know. As the cpm it is endianess independent we can use this path. I will supress then the enable_language

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