1

I'm using a global variable in cmake using CACHE STRING FORCE trick..

I want this simple test case to work messaging in the end only "dudee" and not "dudeedudee:

cmake_minimum_required(VERSION 2.8.10)
set(DUDEE "dudee")
set(LIB ${DUDEE} CACHE STRING "Description" FORCE)
set(LIB ${LIB} ${DUDEE} CACHE STRING "Description" FORCE)
message(${LIB})

Little explanation: Ok, I know that it is not nice to use global variable but cmake is kind of hell but I cannot track down the scope so PARENT can not work and I have a nice working example in which I set dependencies between different cmake modules and application that I wrote with global variable and it works.

But.. sometimes it happens that some modules call each other and each one is adding the dependencies.. a simple example:

application XXX uses the modules VideoReader, BlobDetector, VideoViewer, BlobTracker. All of those modules import the OpenCV libs dependecies in this way:

set(LIB ${LIB} ${OpenCV_LIBS} CACHE STRING "Description" FORCE)

and in the end I have the opencv libs a lot of time repeated in the ${LIB} variable

Community
  • 1
  • 1
nkint
  • 11,513
  • 31
  • 103
  • 174

1 Answers1

0

In the context of a list of libraries to be used in target_link_libraries, then duplicates shouldn't normally cause any real problems.

However, to remove the duplicates, you should be able to use list(REMOVE_DUPLICATES LIB).

Fraser
  • 74,704
  • 20
  • 238
  • 215