I'm maintaining two branches of two projects:
Projcect LeonLog:
master(version: 2.0.0)
producing(version: 1.0.0)
Projcect Octopus:
master(version: 6.0.0, depending on LeonLog:master)
producing(version:5.0.0, depending on LeonLog:producing)
The projcect LeonLog yields a static library libLeonLog.a into /usr/local/lib/, and when I building Octopus:master, the version 2.0.0 of libLeonLog.a should be linked against, and when Octopus:producing being built, the v1.0.0 of libLeonLog.a should be used.
So I want to save two versions of libLeonLog.a at same time, and add a symbolic link to current version, like what we do for shared libs(libLeonLog.so links to libLeonLog.so.1.0.0).
My questions:
Why is there not any symbolic linking convention for static-libs?
I think that the requirements like mine are very common, there must be a widely used solution.
How do you deal with problems like mine(to keep multiple versions of static-lib)?
How to gracefully add symbolic links for static-libs like what we have done for shared-libs with CMake?
I'm trying to do it by myself, like followings:
add_library( leonlog_static STATIC LogToFile.cpp )
set_target_properties( leonlog_static PROPERTIES
OUTPUT_NAME_RELEASE LeonLog
OUTPUT_NAME_DEBUG LeonLog
PUBLIC_HEADER LeonLog.hpp
VERSION ${PROJECT_VERSION}
SUFFIX ".a.${PROJECT_VERSION}"
)
install( TARGETS leonlog_static
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
)
And then, I’m trying to add a symbolic link by running a shell command when installing:
get_target_property( MY_NAME leonlog_static ARCHIVE_OUTPUT_NAME_RELEASE )
message( STATUS "MY_NAME:\"${MY_NAME}\"" )
install( CODE "execute_process(
COMMAND ln -fs ${MY_NAME}.${PROJECT_VERSION} ${MY_NAME}
WORKING_DIRECTORY ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR} )" )
But I can NOT get the value of PROPERTY ARCHIVE_OUTPUT_NAME_RELEASE, I got a empty string.
I have also tried many other properties, but all failed.
like this:
get_target_property( MY_NAME leonlog_static LIBRARY_OUTPUT_NAME_RELEASE )
message( STATUS "LIBRARY_OUTPUT_NAME_RELEASE:\"${MY_NAME}\"" )
get_property( MY_NAME TARGET leonlog_static PROPERTY OUTPUT_NAME )
message( STATUS "OUTPUT_NAME:\"${MY_NAME}\"" )
Finally, I have to compose it by myself, like this:
get_target_property( MY_NAME leonlog_static OUTPUT_NAME_RELEASE )
# compose it with adding a prefix, but it's hard coding!
set( MY_NAME "lib${MY_NAME}.a" )
message( STATUS "MY_NAME:\"${MY_NAME}\"" )
install( CODE "execute_process(
COMMAND ln -fs ${MY_NAME}.${PROJECT_VERSION} ${MY_NAME}
WORKING_DIRECTORY ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR} )" )
I think it is very ugly, and hard to be maintained.
Is there an “Official” way to do this? Sorry for my English!