As we know, only for Shared Libs, a symbolic link is created automatically, not for Static Libs.
For example:
If we have a target libLeonLog.so.1.2.3
, we will get a symbolic link libLeonlog.so
and libLeonLog.so.1
that is pointing to the real target libLeonLog.so.1.2.3
.
Now I want to do the same for my static lib.
At first, I defined my lib like this:
add_library( target_static STATIC LogToFile.cpp )
set_target_properties( target_static PROPERTIES
OUTPUT_NAME_RELEASE LeonLog
OUTPUT_NAME_DEBUG LeonLog
PUBLIC_HEADER LeonLog.hpp
VERSION ${PROJECT_VERSION}
SUFFIX ".a.${PROJECT_VERSION}"
#[[ Here I want keep the property "PREFIX" in default value('lib'), so I removed this line:
PREFIX "lib"
]]
)
install( TARGETS target_static
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
)
And then, I’m trying to add a symbolic link by means of running a shell command when installing.
Like this:
get_target_property( MY_NAME target_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 target_static LIBRARY_OUTPUT_NAME_RELEASE )
message( STATUS "LIBRARY_OUTPUT_NAME_RELEASE:\"${MY_NAME}\"" )
get_property( MY_NAME TARGET target_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 target_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} )" )
But I think it is ugly, and not the correct way.
Is there an “Official” way to do this?
Sorry for my English!