Issue
I'm using CMake-3.13.4 and KDevelop-5.2.1.
I have a topmost CMakeLists.txt that defines the version numbers of my target. It looks like:
set( PROJECT_VERSION_MAJOR 1 )
set( PROJECT_VERSION_MINOR 4 )
set( PROJECT_VERSION_PATCH 7 )
...
add_executable( mytarget main.cpp XXX.cpp ... )
target_link_libraries( mytarget "stdc++fs" ${CMAKE_THREAD_LIBS_INIT} ... )
install( TARGETS mytarget RUNTIME DESTINATION . )
I want CMake automatically append the version string to the file name of the target. So I code as following:
install( TARGETS mytarget RUNTIME DESTINATION . RENAME "mytarget-${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH}" )
But it doesn't work.
Is there a way it can be done with CMake? The file name I finally want is "mytarget-1.4.7".
Solution
You are looking for the property OUTPUT_NAME
.
add_executable( mytarget main.cpp XXX.cpp ... )
target_link_libraries( mytarget "stdc++fs" ${CMAKE_THREAD_LIBS_INIT} ... )
set_target_properties( mytarget PROPERTIES OUTPUT_NAME "mytarget-${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH}" )
install( TARGETS mytarget RUNTIME DESTINATION . )
Answered By - serkan.tuerker Answer Checked By - Marilyn (WPSolving Volunteer)