[CMake] Determining a library name at configure time

Bill Newcomb bnewcomb at nvidia.com
Tue Sep 22 17:17:21 EDT 2015


Disclaimer:  The system I'm working on has its origins in pre cmake-2.6 
days, and we'd probably make a lot of different decisions if we started 
anew today.  We are using only the Unix Makefiles generator.

Our system comprises a number of components, each of which is its own 
cmake project, and builds libraries, executables, etc.  The configure 
(and make, later) operations on the components are driven by another 
invocation of cmake (i.e. the user points cmake at a top-level 
cmakelists, which then invokes cmake again for each component; then the 
user runs make, which results in 'make install' getting run in each 
component's configured subdir).

When cmake is run, the user may designate it either as global or 
local--local builds install component products to a local directory in 
the user's workspace, whereas global builds install to a central 
well-known location.  Periodic automated builds build all components and 
install globally, so that user builds need not build all components, but 
rather can use some components from the global area (with the obvious 
caveats about version incompatibilities).

I want a way to enable one component to use a static library from 
another component.  I tried using cmake's export/import functionality, 
but in that case the exported *.cmake file isn't written until install 
time, but the system must be able to configure all components before 
starting to make them.  So I was trying to figure out a way to create a 
skeletal version of the exported *.cmake file at configure time so that 
the dependent component could include an actual dependency on the static 
library to be provided by the other component.  Figuring out how to get 
the name of the library is my use case.

Please let me know if any of the above requires further description--I 
know it's a mess :-)

Thanks,
B.

On 09/22/2015 11:50 AM, Nils Gladitz wrote:
> On 09/18/2015 11:42 AM, Bill Newcomb wrote:
>>> Suppose I add a library in my project:
>>>
>>> add_library(foo STATIC foo.c bar.c)
>>>
>>> Is there a way I can get the name of the generated library file at 
>>> configure time?  LIBRARY_OUTPUT_NAME and OUTPUT_NAME for the target 
>>> do not seem to be set:
>
> Can you elaborate your use case?
>
> If your use case allows for it you could delegate getting the file 
> name to generation time (which is when the final file name is decided).
> e.g. $<TARGET_FILE_NAME:target> [1] would expand to the file name 
> (without path) of the given target  in the context of e.g. 
> add_custom_command() commands.
>
> Nils
>
> [1] 
> http://www.cmake.org/cmake/help/v3.3/manual/cmake-generator-expressions.7.html


-----------------------------------------------------------------------------------
This email message is for the sole use of the intended recipient(s) and may contain
confidential information.  Any unauthorized review, use, disclosure or distribution
is prohibited.  If you are not the intended recipient, please contact the sender by
reply email and destroy all copies of the original message.
-----------------------------------------------------------------------------------


More information about the CMake mailing list