[CMake] conditional selection of either local "just built" or system versions of a library

Marco marco.corvo at pd.infn.it
Tue Jan 11 11:46:08 EST 2011


Dear CMake experts,

I'm facing the following problem. I have a project with many 
subdirectories, all at the same hierarchical level:

/my/project/path/CMakeLists.txt
/my/project/path/A - include
                  |- src
                  |- CMakeLists.txt

/my/project/path/B - include
                  |- src
                  |- CMakeLists.txt

Each subdir corresponds to a package that a user is allowed to modify 
and build against a given "general release" already installed centrally 
or against other locally built packages.

Some of the executables of package A must be linked against an object 
file generated by package B. The user could build package B, so that the 
object file needed by executables in package A is the "local" one, but 
could also decide to rely on the one that comes from the already 
installed release.

To give an example:

- package A has something like:
   add_executable(X src/X.cc)
   target_link_libraries(X ${RIGHTPATH}/ObjFile.o A B C)
   add_dependencies(X obj_file_target)

- package B has something like:
   add_custom_command(
OUTPUT ${LIBRARY_OUTPUT_PATH}/ObjFile.o
COMMAND ${CMAKE_CXX_COMPILER}  -Wall
-I${PROJECT_SOURCE_DIR}/include -c
${CMAKE_CURRENT_SOURCE_DIR}/src/ObjFile.cc -o 
${LIBRARY_OUTPUT_PATH}/ObjFile.o)

add_custom_target(obj_file_target DEPENDS ${LIBRARY_OUTPUT_PATH}/ObjFile.o)

In this way executable X triggers the compilation of ObjFile.o which is 
put into ${LIBRARY_OUTPUT_PATH}.

The point is that if the user wants to use the system ObjFile.o located 
in, say, /Soft/Releases/V1/lib/ObjFile.o I don't have a way to determine 
for package A the value of RIGHTPATH (either ${LIBRARY_OUTPUT_PATH} or 
/Soft/Releases/V1/lib/) as the path variable is set when I enter package 
A which can happen before I enter package B.

How could I solve this issue? Is there a way to conditionally select 
which library my exe will be linked against?

Thanks in advance for your help.

Marco


More information about the CMake mailing list