From 26c45372ca4aa6395c5798249587dad07ea81693 Mon Sep 17 00:00:00 2001 From: Jonathan GUILLOT Date: Tue, 27 Aug 2024 17:54:05 +0200 Subject: [PATCH] Globally set shared library versions from root CMakeLists.txt By the way, set SOVERSION to version major. It also fixes wiringPiDev shared library version not correctly set. --- CMakeLists.txt | 5 +++++ devLib/CMakeLists.txt | 2 +- wiringPi/CMakeLists.txt | 8 +------- 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 90b4d64..2d3f78e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,11 @@ cmake_minimum_required(VERSION 3.10) project(WiringPiLib) +# Read version from version.h +file(READ "${CMAKE_CURRENT_SOURCE_DIR}/version.h" WIRINGPI_VERSION) +string(REGEX REPLACE ".*VERSION \"([0-9]+.[0-9]+)\".*" "\\1" WIRINGPI_VERSION "${WIRINGPI_VERSION}") +string(REGEX REPLACE "([0-9]+)\..*" "\\1" WIRINGPI_SOVERSION "${WIRINGPI_VERSION}") + # Include subdirectories add_subdirectory(devLib) add_subdirectory(gpio) diff --git a/devLib/CMakeLists.txt b/devLib/CMakeLists.txt index beec8cb..272d369 100644 --- a/devLib/CMakeLists.txt +++ b/devLib/CMakeLists.txt @@ -28,7 +28,7 @@ set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wformat=2 -Winline -pipe") add_library(wiringPiDev SHARED ${SRC}) # Set the library version -set_target_properties(wiringPiDev PROPERTIES VERSION ${VERSION} SOVERSION ${WIRINGPI_SONAME_SUFFIX}) +set_target_properties(wiringPiDev PROPERTIES VERSION ${WIRINGPI_VERSION} SOVERSION ${WIRINGPI_SOVERSION}) # Install headers install(FILES ${HEADERS} DESTINATION include) diff --git a/wiringPi/CMakeLists.txt b/wiringPi/CMakeLists.txt index 1663374..2cde4c6 100644 --- a/wiringPi/CMakeLists.txt +++ b/wiringPi/CMakeLists.txt @@ -44,18 +44,12 @@ set(HEADERS ) # Compiler flags set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -Wformat=2 -Winline -pipe -Wformat-security") -set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,-soname,libwiringPi.so${WIRINGPI_SONAME_SUFFIX}") - -# Read version from version.h -file(READ "${CMAKE_CURRENT_SOURCE_DIR}/../version.h" VERSION) -string(REGEX REPLACE ".*VERSION \"([0-9]+.[0-9]+)\".*" "\\1" VERSION "${VERSION}") # Add the library target add_library(wiringPi SHARED ${SRC}) # Set the library version -set(WIRINGPI_SONAME_SUFFIX "1") -set_target_properties(wiringPi PROPERTIES VERSION ${VERSION} SOVERSION ${WIRINGPI_SONAME_SUFFIX}) +set_target_properties(wiringPi PROPERTIES VERSION ${WIRINGPI_VERSION} SOVERSION ${WIRINGPI_SOVERSION}) target_include_directories(wiringPi PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}) # Add -lm to link with the math library