navderm
navderm

Reputation: 819

library versioning with cmake

I have a project with 4 different sub projects. To specify the versions, I use the

SET(parent_VERSION_MAJOR 1)
SET(parent_VERSION_MINOR 0)
set(parent_VERSION_PATCH 0)
set(parent_VERSION 1.0.0)

and then I can use this in the sub projects if the add_subdirectory is used.

Q1. I could not set parent_VERSION based on MAJOR, MINOR and PATCH. According to the documentation is should be set automatically but whenever I try printing it, it is empty without using the last line in the code.

Q2. In case I want to build from sub directory only, I get an error shouting :

CMake Error at CMakeLists.txt:28 (set_target_properties):
  set_target_properties called with incorrect number of arguments.

which is because I am using parent_VERSION there.

So I understand that it isn't able to get the parent_VERSION without running cmake from the top directory but how do I change the code such that it can build even without running from the top level. I read about SET with INHERITED but I don't think that is what I need.

Upvotes: 0

Views: 1654

Answers (1)

navderm
navderm

Reputation: 819

Here is how I solved it. If someone could tell me a better/more elegant way I'd be happy.

if(NOT parent_VERSION)
  SET(parent_VERSION_MAJOR 1)
  SET(parent_VERSION_MINOR 0)
  SET(parent_VERSION_PATCH 0)
  SET(parent_VERSION 1.0.0)
endif(NOT parent_VERSION)

Upvotes: 1

Related Questions