Reputation: 400
I am trying to set up CMAKE as a build system, so am quite new to it. Have done quite a bit of extensive research before posting this question but i couldn't find an answer. I have been looking for the past day and some of the links are here, and here, and in the official documentation but i do not understand what i am doing wrong.
Question: I am trying to build a dynamic library with cmake but the version is not being set.
This is my folder structure, generated with the "tree" command. (i have taken out stuff from the build directory so it is easily readable)
.
├── build
├── CMakeLists.txt
├── test_utility.cpp
└── test_utility.h
This is my CMakeLists.txt:
cmake_minimum_required(VERSION 3.13)
project(TestLib
VERSION 0.1
DESCRIPTION "Testing the library target utility in Cmake"
LANGUAGES CXX)
add_library (test_utility SHARED test_utility.cpp test_utility.h)
Then i go to the build directory and run cmake .. -G "Unix Makefiles" and cmake --build . . Everything finishes nicely except for one thing: The resultof this is libtest_utility.so whereas i would have wanted libtest_utility.so.0.1 and then i would do the symlink myself.
I know about the workarround solution from here that tells to use VERSION_MAJOR 0 and VERSION_MINOR 1 but i thought that the Version attribute in project should take care of it.
Question: Why isn'tt the version being set
Upvotes: 1
Views: 2868
Reputation: 2825
In case the version of the project is set, this value can be reused for the built targets. Just read the project version instead of value duplication
Set the version of the project:
project(TestLib
VERSION 0.1
DESCRIPTION "Testing the library target utility in Cmake"
LANGUAGES CXX
)
Use the value of PROJECT_VERSION
add_library (test_utility SHARED test_utility.cpp test_utility.h)
set_target_properties(test_utility PROPERTIES VERSION ${PROJECT_VERSION})
Upvotes: 0
Reputation: 65870
Project's version, which is set by the VERSION parameter of the project()
, denotes only version of the project, not the version of the libraries it produces.
For set version of the library, you need to set VERSION property of the library target:
set_target_properties(test_utility PROPERTIES VERSION "0.1")
Upvotes: 1