[CMake] "Emulate" a package result (find_package)

felix schwitzer felix.schwitzer at gmx.at
Mon Mar 30 16:38:39 EDT 2015


 <r2d2leboss at ...> writes:

> Our idea was to use add_subdirectory but modules will try to search
LIBRARY and they will not find the
> library because it's not still compiled... So, how to "emulate" 
> find_package result for LIBRARY ? Bad idea (I think), is to set
LIBRARY-FOUND to true, manually include
> dirs (a pain because library is not installed) and it will not 
> prevent to library upgrade (maybe that tomorrow it will have a new
components, so a new include dir to add). 
> 
> Do you have any idea to build our top level PROJECT CMakeLists.txt ?
> 
Hm... do not understand where your problem is. We do your approach sketched
above all the time. The master CMakeLists.txt looks like
  add_subdirectory(LIBRARY)
  add_subdirectory(MODULE_1)
  ...
The important thing is, that the order of added subdirectories is right
(and your project dependency has such an ordering, no circular dependencies)

in MODULE_1/CMakeLists.txt you may have something like
   add_library(MODULE_1 ...)
   target_link_libraries(MODULE_1 LIBRARY)
This tells cmake that LIBRARY is a prerequisite for MODULE_1 and it will
build LIBRARY if MODULE_1 must be built; there is no need that LIBRARY
is compiled at configure time.

Or I misunderstood your problem totally.
 
Regards
Felix




More information about the CMake mailing list