Commit 8ad827c3 authored by Marcus Asteborg's avatar Marcus Asteborg Committed by Ralph Giles

cmake - fix bugs around consuming Opus as a submodule in cmake and package version parsing

parent 5edb5aac
cmake_minimum_required(VERSION 3.1)
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
include(OpusFunctions)
get_library_version(OPUS_LIBRARY_VERSION OPUS_LIBRARY_VERSION_MAJOR)
message(STATUS "Opus library version: ${OPUS_LIBRARY_VERSION}")
get_package_version(PACKAGE_VERSION)
message(STATUS "Opus package version: ${PACKAGE_VERSION}")
string(REGEX
REPLACE "^([0-9]+.[0-9]+\\.?([0-9]+)?).*"
"\\1"
PROJECT_VERSION
${PACKAGE_VERSION})
message(STATUS "Opus project version: ${PROJECT_VERSION}")
include(OpusPackageVersion)
get_package_version(PACKAGE_VERSION PROJECT_VERSION)
project(Opus LANGUAGES C VERSION ${PROJECT_VERSION})
include(OpusFunctions)
include(OpusBuildtype)
include(OpusConfig)
include(OpusSources)
......@@ -228,6 +217,9 @@ endif()
add_library(opus ${opus_headers} ${opus_sources} ${opus_sources_float} ${Opus_PUBLIC_HEADER})
add_library(Opus::opus ALIAS opus)
get_library_version(OPUS_LIBRARY_VERSION OPUS_LIBRARY_VERSION_MAJOR)
message(STATUS "Opus library version: ${OPUS_LIBRARY_VERSION}")
set_target_properties(opus
PROPERTIES SOVERSION
${OPUS_LIBRARY_VERSION_MAJOR}
......@@ -490,7 +482,7 @@ if(OPUS_INSTALL_CMAKE_CONFIG_MODULE)
include(CMakePackageConfigHelpers)
set(INCLUDE_INSTALL_DIR ${CMAKE_INSTALL_INCLUDEDIR})
configure_package_config_file(${CMAKE_SOURCE_DIR}/cmake/OpusConfig.cmake.in
configure_package_config_file(${PROJECT_SOURCE_DIR}/cmake/OpusConfig.cmake.in
OpusConfig.cmake
INSTALL_DESTINATION
${CMAKE_INSTALL_PACKAGEDIR}
......
......@@ -220,6 +220,7 @@ EXTRA_DIST = opus.pc.in \
cmake/OpusConfig.cmake \
cmake/OpusConfig.cmake.in \
cmake/OpusFunctions.cmake \
cmake/OpusPackageVersion.cmake \
cmake/OpusSources.cmake \
cmake/config.h.cmake.in \
cmake/vla.c \
......
......@@ -5,7 +5,7 @@ set(__opus_config INCLUDED)
include(OpusFunctions)
configure_file(${CMAKE_SOURCE_DIR}/cmake/config.h.cmake.in config.h @ONLY)
configure_file(cmake/config.h.cmake.in config.h @ONLY)
add_definitions(-DHAVE_CONFIG_H)
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
......@@ -89,4 +89,4 @@ if(NOT MSVC)
add_compile_options(${WARNING_FLAG})
endif()
endforeach()
endif()
\ No newline at end of file
endif()
......@@ -41,57 +41,6 @@ function(get_library_version OPUS_LIBRARY_VERSION OPUS_LIBRARY_VERSION_MAJOR)
set(OPUS_LIBRARY_VERSION_MAJOR ${OPUS_LIBRARY_VERSION_MAJOR} PARENT_SCOPE)
endfunction()
function(get_package_version PACKAGE_VERSION)
find_package(Git)
if(Git_FOUND AND EXISTS "${CMAKE_CURRENT_LIST_DIR}/.git")
execute_process(COMMAND ${GIT_EXECUTABLE} describe --tags --match "v*"
OUTPUT_VARIABLE OPUS_PACKAGE_VERSION)
if(OPUS_PACKAGE_VERSION)
string(STRIP ${OPUS_PACKAGE_VERSION}, OPUS_PACKAGE_VERSION)
string(REPLACE \n
""
OPUS_PACKAGE_VERSION
${OPUS_PACKAGE_VERSION})
string(REPLACE ,
""
OPUS_PACKAGE_VERSION
${OPUS_PACKAGE_VERSION})
string(SUBSTRING ${OPUS_PACKAGE_VERSION}
1
-1
OPUS_PACKAGE_VERSION)
set(PACKAGE_VERSION ${OPUS_PACKAGE_VERSION} PARENT_SCOPE)
return()
endif()
endif()
if(EXISTS "${CMAKE_SOURCE_DIR}/package_version")
# Not a git repo, lets' try to parse it from package_version file if exists
file(STRINGS package_version opus_package_version_string
LIMIT_COUNT 1
REGEX "PACKAGE_VERSION=")
string(REPLACE "PACKAGE_VERSION="
""
opus_package_version_string
${opus_package_version_string})
string(REPLACE "\""
""
opus_package_version_string
${opus_package_version_string})
# In case we have a unknown dist here we just replace it with 0
string(REPLACE "unknown"
"0"
opus_package_version_string
${opus_package_version_string})
set(PACKAGE_VERSION ${opus_package_version_string} PARENT_SCOPE)
return()
endif()
# if all else fails set to 0
set(PACKAGE_VERSION 0 PARENT_SCOPE)
endfunction()
function(check_flag NAME FLAG)
include(CheckCCompilerFlag)
check_c_compiler_flag(${FLAG} ${NAME}_SUPPORTED)
......
if(__opus_version)
return()
endif()
set(__opus_version INCLUDED)
function(get_package_version PACKAGE_VERSION PROJECT_VERSION)
find_package(Git)
if(GIT_FOUND AND EXISTS "${CMAKE_CURRENT_LIST_DIR}/.git")
execute_process(COMMAND ${GIT_EXECUTABLE}
--git-dir=${CMAKE_CURRENT_LIST_DIR}/.git describe
--tags --match "v*" OUTPUT_VARIABLE OPUS_PACKAGE_VERSION)
if(OPUS_PACKAGE_VERSION)
string(STRIP ${OPUS_PACKAGE_VERSION}, OPUS_PACKAGE_VERSION)
string(REPLACE \n
""
OPUS_PACKAGE_VERSION
${OPUS_PACKAGE_VERSION})
string(REPLACE ,
""
OPUS_PACKAGE_VERSION
${OPUS_PACKAGE_VERSION})
string(SUBSTRING ${OPUS_PACKAGE_VERSION}
1
-1
OPUS_PACKAGE_VERSION)
message(STATUS "Opus package version from git repo: ${OPUS_PACKAGE_VERSION}")
endif()
elseif(EXISTS "${CMAKE_CURRENT_LIST_DIR}/package_version"
AND NOT OPUS_PACKAGE_VERSION)
# Not a git repo, lets' try to parse it from package_version file if exists
file(STRINGS package_version OPUS_PACKAGE_VERSION
LIMIT_COUNT 1
REGEX "PACKAGE_VERSION=")
string(REPLACE "PACKAGE_VERSION="
""
OPUS_PACKAGE_VERSION
${OPUS_PACKAGE_VERSION})
string(REPLACE "\""
""
OPUS_PACKAGE_VERSION
${OPUS_PACKAGE_VERSION})
# In case we have a unknown dist here we just replace it with 0
string(REPLACE "unknown"
"0"
OPUS_PACKAGE_VERSION
${OPUS_PACKAGE_VERSION})
message(STATUS "Opus package version from package_version file: ${OPUS_PACKAGE_VERSION}")
endif()
if(OPUS_PACKAGE_VERSION)
string(REGEX
REPLACE "^([0-9]+.[0-9]+\\.?([0-9]+)?).*"
"\\1"
OPUS_PROJECT_VERSION
${OPUS_PACKAGE_VERSION})
else()
# fail to parse version from git and package version
message(WARNING "Could not get package version.")
set(OPUS_PACKAGE_VERSION 0)
set(OPUS_PROJECT_VERSION 0)
endif()
message(STATUS "Opus project version: ${OPUS_PROJECT_VERSION}")
set(PACKAGE_VERSION ${OPUS_PACKAGE_VERSION} PARENT_SCOPE)
set(PROJECT_VERSION ${OPUS_PROJECT_VERSION} PARENT_SCOPE)
endfunction()
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