Commit 19eb1e4b by Patrick Steinhardt

cmake: specify project version

We currently do not set up a project version within CMake, meaning that
it can't be use by other projects including libgit2 as a sub-project and
also not by other tools like IDEs.

This commit changes this to always set up a project version, but instead
of extracting it from the "version.h" header we now set it up directly.
This is mostly to avoid mis-use of the previous `LIBGIT2_VERSION`
variables, as we should now always use the `libgit2_VERSION` ones that
are set up by CMake if one provides the "VERSION" keyword to the
`project()` call. While this is one more moving target we need to adjust
on releases, this commit also adjusts our release script to verify that
the project version was incremented as expected.
parent 325375e3
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
CMAKE_MINIMUM_REQUIRED(VERSION 3.5.1) CMAKE_MINIMUM_REQUIRED(VERSION 3.5.1)
project(libgit2 C) project(libgit2 VERSION "1.0.1" LANGUAGES C)
# Add find modules to the path # Add find modules to the path
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${libgit2_SOURCE_DIR}/cmake/") set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${libgit2_SOURCE_DIR}/cmake/")
...@@ -93,16 +93,6 @@ IF(MSVC) ...@@ -93,16 +93,6 @@ IF(MSVC)
OPTION(MSVC_CRTDBG "Enable CRTDBG memory leak reporting" OFF) OPTION(MSVC_CRTDBG "Enable CRTDBG memory leak reporting" OFF)
ENDIF() ENDIF()
FILE(STRINGS "${libgit2_SOURCE_DIR}/include/git2/version.h" GIT2_HEADER REGEX "^#define LIBGIT2_VERSION \"[^\"]*\"$")
STRING(REGEX REPLACE "^.*LIBGIT2_VERSION \"([0-9]+).*$" "\\1" LIBGIT2_VERSION_MAJOR "${GIT2_HEADER}")
STRING(REGEX REPLACE "^.*LIBGIT2_VERSION \"[0-9]+\\.([0-9]+).*$" "\\1" LIBGIT2_VERSION_MINOR "${GIT2_HEADER}")
STRING(REGEX REPLACE "^.*LIBGIT2_VERSION \"[0-9]+\\.[0-9]+\\.([0-9]+).*$" "\\1" LIBGIT2_VERSION_REV "${GIT2_HEADER}")
SET(LIBGIT2_VERSION_STRING "${LIBGIT2_VERSION_MAJOR}.${LIBGIT2_VERSION_MINOR}.${LIBGIT2_VERSION_REV}")
FILE(STRINGS "${libgit2_SOURCE_DIR}/include/git2/version.h" GIT2_HEADER_SOVERSION REGEX "^#define LIBGIT2_SOVERSION \"([0-9.]+)\"$")
STRING(REGEX REPLACE "^.*LIBGIT2_SOVERSION \"([0-9.]+)\"$" "\\1" LIBGIT2_SOVERSION "${GIT2_HEADER_SOVERSION}")
IF (DEPRECATE_HARD) IF (DEPRECATE_HARD)
ADD_DEFINITIONS(-DGIT_DEPRECATE_HARD) ADD_DEFINITIONS(-DGIT_DEPRECATE_HARD)
ENDIF() ENDIF()
...@@ -175,7 +165,7 @@ IF (MSVC) ...@@ -175,7 +165,7 @@ IF (MSVC)
# /NXCOMPAT - Data execution prevention (DEP) # /NXCOMPAT - Data execution prevention (DEP)
# /LARGEADDRESSAWARE - >2GB user address space on x86 # /LARGEADDRESSAWARE - >2GB user address space on x86
# /VERSION - Embed version information in PE header # /VERSION - Embed version information in PE header
SET(CMAKE_EXE_LINKER_FLAGS "/DYNAMICBASE /NXCOMPAT /LARGEADDRESSAWARE /VERSION:${LIBGIT2_VERSION_MAJOR}.${LIBGIT2_VERSION_MINOR}") SET(CMAKE_EXE_LINKER_FLAGS "/DYNAMICBASE /NXCOMPAT /LARGEADDRESSAWARE /VERSION:${libgit2_VERSION_MAJOR}.${libgit2_VERSION_MINOR}")
IF (NOT (MSVC_VERSION LESS 1900)) IF (NOT (MSVC_VERSION LESS 1900))
# /GUARD:CF - Enable Control Flow Guard # /GUARD:CF - Enable Control Flow Guard
......
...@@ -40,6 +40,15 @@ def verify_version(version): ...@@ -40,6 +40,15 @@ def verify_version(version):
'SOVERSION': [ '"{}.{}"'.format(version.major, version.minor), None ], 'SOVERSION': [ '"{}.{}"'.format(version.major, version.minor), None ],
} }
# Parse CMakeLists
with open('CMakeLists.txt') as f:
for line in f.readlines():
if line.startswith('project(libgit2 VERSION "{}"'.format(version)):
break
else:
raise Error("cmake: invalid project definition")
# Parse version.h
with open('include/git2/version.h') as f: with open('include/git2/version.h') as f:
lines = f.readlines() lines = f.readlines()
......
...@@ -364,19 +364,19 @@ ENDIF() ...@@ -364,19 +364,19 @@ ENDIF()
IDE_SPLIT_SOURCES(git2) IDE_SPLIT_SOURCES(git2)
IF (SONAME) if(SONAME)
SET_TARGET_PROPERTIES(git2 PROPERTIES VERSION ${LIBGIT2_VERSION_STRING}) set_target_properties(git2 PROPERTIES VERSION ${libgit2_VERSION})
SET_TARGET_PROPERTIES(git2 PROPERTIES SOVERSION ${LIBGIT2_SOVERSION}) set_target_properties(git2 PROPERTIES SOVERSION "${libgit2_VERSION_MAJOR}.${libgit2_VERSION_MINOR}")
IF (LIBGIT2_FILENAME) if(LIBGIT2_FILENAME)
ADD_DEFINITIONS(-DLIBGIT2_FILENAME=\"${LIBGIT2_FILENAME}\") add_definitions(-DLIBGIT2_FILENAME=\"${LIBGIT2_FILENAME}\")
SET_TARGET_PROPERTIES(git2 PROPERTIES OUTPUT_NAME ${LIBGIT2_FILENAME}) set_target_properties(git2 PROPERTIES OUTPUT_NAME ${LIBGIT2_FILENAME})
ELSEIF (DEFINED LIBGIT2_PREFIX) elseif(DEFINED LIBGIT2_PREFIX)
SET_TARGET_PROPERTIES(git2 PROPERTIES PREFIX "${LIBGIT2_PREFIX}") set_target_properties(git2 PROPERTIES PREFIX "${LIBGIT2_PREFIX}")
ENDIF() endif()
ENDIF() endif()
PKG_BUILD_CONFIG(NAME libgit2 PKG_BUILD_CONFIG(NAME libgit2
VERSION ${LIBGIT2_VERSION_STRING} VERSION ${libgit2_VERSION}
DESCRIPTION "The git library, take 2" DESCRIPTION "The git library, take 2"
LIBS_SELF git2 LIBS_SELF git2
PRIVATE_LIBS ${LIBGIT2_PC_LIBS} PRIVATE_LIBS ${LIBGIT2_PC_LIBS}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment