Commit Graph

38 Commits

Author SHA1 Message Date
Brad King dd089e08b5 install: Allow absolute EXPORT destination with relative targets (#15258)
When install(EXPORT) is given an absolute destination we cannot compute
the install prefix relative to the installed export file location.
Previously we disallowed installation of targets in such exports with a
relative destination, but did not enforce this for target property
values besides the location of the main target file.  This could lead to
broken installations when the EXPORT is installed to an absolute path
but usage requirements are specified relative to the install prefix.

Since an EXPORT installed to an absolute destination cannot be relocated
we can just hard-code the value of CMAKE_INSTALL_PREFIX as the base for
relative paths.  This will allow absolute install(EXPORT) destinations
to work with relative destinations for targets and usage requirements.

Extend the ExportImport test with a case covering this behavior.
2014-12-15 11:45:49 -05:00
Brad King 6e89c8a5f1 install: Support generator expressions in FILES and PROGRAMS mode
Teach the install(FILES) and install(PROGRAMS) commands to evaluate
generator expressions in the list of files.

Extend the ExportImport test to cover installation cases involving
generator expressions.
2014-02-21 17:05:26 -05:00
Stephen Kelly 7a3e45b9d4 Export: Prefix relative items with genexes in INSTALL_INTERFACE.
Code such as

 target_include_directories(foo INTERFACE
   $<INSTALL_INTERFACE:include$<FOO>>
 )

should be treated as a relative directory, despite the genex, after
the INSTALL_INTERFACE is stripped away.

Previously, this would generate a relative directory on export, which
would be an error on import, so no policy is needed.
2013-11-26 13:01:53 +01:00
Stephen Kelly f088a32450 Export: Process INSTALL_INTERFACE in INCLUDES DESTINATION.
Code such as

 install(TARGETS ...
   INCLUDES DESTINATION $<INSTALL_INTERFACE:include>
 )

should behave as if the INSTALL_INTERFACE wrapper were not present.
2013-11-26 13:01:50 +01:00
Stephen Kelly 9eedc850eb Export: Process relative includes after genex evaluation.
In code such as

 install(TARGETS ...
   INCLUDES DESTINATION $<FOO>include
 )

the generator expressions are evaluated at generate-time. Delay
determining whether each entry is a relative path until after
the generator expressions are evaluated. Such relative paths
are based relative to the CMAKE_INSTALL_PREFIX.
2013-11-26 13:01:29 +01:00
Stephen Kelly a63fcbcb9f Always consider includes from IMPORTED targets to be SYSTEM.
Introduce a target property to control this behavior variable
to set the default value for the target property.

This does not affect try_compile runs.
2013-09-24 20:00:31 +02:00
Brad King dda6e93666 Merge topic 'install-interface-relative'
d777b8e Genex: Allow relative paths in INSTALL_INTERFACE.
2013-07-26 09:01:19 -04:00
Brad King c82b1cbe83 Merge topic 'install-interface-includes'
650e61f Add a convenient way to add the includes install dir to the INTERFACE.
2013-07-26 09:01:06 -04:00
Stephen Kelly d777b8e716 Genex: Allow relative paths in INSTALL_INTERFACE.
These paths can be prepended with the ${_IMPORT_PREFIX} generated
in the export file.

Such relative paths were previously an error.
2013-07-25 14:31:22 +02:00
Stephen Kelly f5ca872e8b Use linked frameworks as a source of include directories. 2013-07-24 11:49:06 -04:00
Stephen Kelly 650e61f833 Add a convenient way to add the includes install dir to the INTERFACE.
Export the INCLUDES DESTINATION without appending to the
INTERFACE_INCLUDE_DIRECTORIES of the target itself. That way, a target
can be exported multiple times with different INCLUDES DESTINATION
without unintended cross-pollution of export sets.
2013-07-24 17:32:58 +02:00
Brad King b6e0972262 Merge topic 'INTERFACE_LINK_LIBRARIES-prop'
3e30d9e TLL: Don't populate old link interface if CMP0022 is NEW.
574fec9 Export: Generate INTERFACE_LINK_LIBRARIES property on targets.
d0a76ea Introduce the INTERFACE_LINK_LIBRARIES property.
ddde61c Introduce the LINK_ONLY generator expression.
5aa9731 GenexEval: Add abstracted access to link interface for a target.
2013-07-15 09:33:42 -04:00
Brad King aa0b9fa311 Merge topic 'IMPORTED-build-dependencies'
4f7ceb5 Test non-IMPORTED libraries in the INTERFACE of IMPORTED libraries.
3405351 Add entire link interface transitive closure as target depends.
2013-07-15 09:30:34 -04:00
Stephen Kelly 574fec97fd Export: Generate INTERFACE_LINK_LIBRARIES property on targets.
This property is generated only for targets which have recorded
policy CMP0022 as NEW, and a compatibility mode is added to
additionally export the old interfaces in that case too.

If the old interfaces are not exported, the generated export files
require CMake 2.8.12. Because the unit tests use a version which
is not yet called 2.8.12, temporarily require a lower version.
2013-07-08 22:39:57 +02:00
Stephen Kelly 4f7ceb56d1 Test non-IMPORTED libraries in the INTERFACE of IMPORTED libraries.
If a non-IMPORTED library is added to the INTERFACE_LINK_LIBRARIES
of a IMPORTED target, the non-IMPORTED target needs to become a
target dependency and link dependency of the consuming target.

This is already the case since commit 30962029 (Make targets depend
on the link interface of their dependees, 2012-12-26), and fixed in
the parent commit, so test that it works.
2013-07-02 17:03:53 +02:00
Stephen Kelly 77ff352aa7 Generate INTERFACE_COMPILE_OPTIONS on export.
This was missing from commit 80ca9c4b (Add COMPILE_OPTIONS target
property., 2013-05-16).
2013-06-10 16:50:20 +02:00
Stephen Kelly b5d6f5dd5b Add EXPORT_NAME property.
This allows for example, the buildsystem to use names like 'boost_any'
instead of the overly generic 'any', and still be able to generate
IMPORTED targets called 'boost::any'.
2013-05-18 10:00:48 +02:00
Stephen Kelly 77cecb778f Add includes and compile definitions with target_link_libraries.
This establishes that linking is used to propagate usage-requirements
between targets in CMake code. The use of the target_link_libraries
command as the API for this is chosen because introducing a new command
would introduce confusion due to multiple commands which differ only in
a subtle way.
2013-01-31 17:34:20 +01:00
Stephen Kelly d4297d5697 Export targets to a targets file, not a Config file. 2013-01-31 17:27:06 +01:00
Stephen Kelly f6b16d4b06 Don't allow targets args in the new target commands. 2013-01-29 18:44:54 +01:00
Stephen Kelly 2fb2c32f9b Add the COMPATIBLE_INTERFACE_STRING property. 2013-01-24 20:36:04 +01:00
Stephen Kelly 830246e841 Export the COMPATIBLE_INTERFACE_BOOL content properties 2013-01-21 09:05:03 +01:00
Stephen Kelly e98799105b Make INTERFACE determined properties readable in generator expressions.
The properties are evaluated as link-dependent interface properties when
evaluating the generator expressions.
2013-01-20 17:06:47 +01:00
Stephen Kelly 522bdac149 Export the INTERFACE_PIC property. 2013-01-15 14:36:22 -05:00
Stephen Kelly 4ee872cb99 Make the BUILD_INTERFACE of export()ed targets work.
The existing BUILD_INTERFACE code is executed at generate time, which
is too late for export().
2013-01-15 14:36:22 -05:00
Stephen Kelly 1d47cd94f3 Add a test for the interfaces in targets exported from the build tree. 2013-01-15 14:36:22 -05:00
Stephen Kelly 77d2646784 Allow generator expressions in LINK_INTERFACE_LIBRARIES.
The Config and IMPORTED_ variants may also contain generator
expressions.

If 'the implementation is the interface', then the result of
evaluating the expressions at generate time is used to populate
the IMPORTED_LINK_INTERFACE_LIBRARIES property.

1) In the case of non-static libraries, this is fine because the
  user still has the option to populate the LINK_INTERFACE_LIBRARIES
  with generator expressions if that is what is wanted.

2) In the case of static libraries, this prevents a footgun,
  enforcing that the interface and the implementation are really
  the same.

  Otherwise, the LINK_LIBRARIES could contain a generator
  expression which is evaluated with a different context at build
  time, and when used as an imported target. That would mean that the
  result of evaluating the INTERFACE_LINK_LIBRARIES property for
  a static library would not necessarily be the 'link implementation'.

  For example:

    add_library(libone STATIC libone.cpp)
    add_library(libtwo STATIC libtwo.cpp)
    add_library(libthree STATIC libthree.cpp)

    target_link_libraries(libtwo
      $<$<STREQUAL:$<TARGET_PROPERTY:TYPE>,STATIC_LIBRARY>:libone>)
    target_link_libraries(libthree libtwo)

  If the LINK_LIBRARIES content was simply copied to the
  IMPORTED_LINK_INTERFACE_LIBRARIES, then libthree links to libone, but
  executables linking to libthree will not link to libone.

3) As the 'implementation is the interface' concept is to be
  deprecated in the future anyway, this should be fine.
2013-01-10 23:04:06 +01:00
Stephen Kelly 93034a8350 Fix linking to imported libraries test.
Make a C executable instead of attempting to make a C++ static
library (and not really succeeding). This was introduced in
commit 894f52f3 (Handle INTERFACE properties transitively for
includes and defines., 2012-09-23).
2013-01-10 17:13:19 +01:00
Stephen Kelly 894f52f32d Handle INTERFACE properties transitively for includes and defines.
Contextually, the behavior is as if the properties content from another
target is included in the string and then the result is evaluated.
2013-01-05 01:18:37 +01:00
Alex Neundorf 955b96629e exports: add a test for exporting dependent targets
The test exports two libraries into two separate exports,
and then include()s the generated export files. This must not fail.

Alex
2012-09-30 10:27:02 -04:00
Kitware Robot 9db3116226 Remove CMake-language block-end command arguments
Ancient versions of CMake required else(), endif(), and similar block
termination commands to have arguments matching the command starting the
block.  This is no longer the preferred style.

Run the following shell code:

for c in else endif endforeach endfunction endmacro endwhile; do
    echo 's/\b'"$c"'\(\s*\)(.\+)/'"$c"'\1()/'
done >convert.sed &&
git ls-files -z -- bootstrap '*.cmake' '*.cmake.in' '*CMakeLists.txt' |
egrep -z -v '^(Utilities/cm|Source/kwsys/)' |
egrep -z -v 'Tests/CMakeTests/While-Endwhile-' |
xargs -0 sed -i -f convert.sed &&
rm convert.sed
2012-08-13 14:19:16 -04:00
Alex Neundorf 35c48e1270 Check*.cmake: Expand imported targets in CMAKE_REQUIRED_LIBRARIES
Add the function cmake_expand_imported_targets() to expand imported
targets in a list of libraries into their on-disk file names for a
particular configuration.  Adapt the implementation from KDE's
HANDLE_IMPORTED_TARGETS_IN_CMAKE_REQUIRED_LIBRARIES which has been in
use for over 2 years.  Call the function from all the Check*.cmake
macros to handle imported targets named in CMAKE_REQUIRED_LIBRARIES.

Alex
2012-02-21 15:38:15 -05:00
Brad King a765c491ad Honor custom command dependencies on imported targets (#10395)
Imported targets do not themselves build, but we can follow dependencies
through them to find real targets.  This allows imported targets to
depend on custom targets that provide the underlying files at build
time.
2010-12-08 12:22:13 -05:00
Brad King e01cce2869 Allow add_dependencies() on imported targets (#10395)
Imported targets do not themselves build, but we can follow dependencies
through them to find real targets.  This allows imported targets to
depend on custom targets that provide the underlying files at build
time.
2010-11-19 17:19:21 -05:00
Brad King d259128894 Test link multiplicity export/import
We test that LINK_INTERFACE_MULTIPLICITY propagates through export() and
install(EXPORT) into dependent projects.  A simple cycle of two archives
that need to be scanned three times ensures that the importing project
uses the multiplicity correctly.
2009-09-01 10:38:36 -04:00
Brad King 3621e073a8 ENH: Test export/import of link interface languages
This extends the ExportImport test.  The Export project creates a C++
static library and exports it.  Then the Import project links the
library into a C executable.  On most platforms the executable will link
only if the C++ linker is chosen correctly.
2009-07-11 10:10:51 -04:00
Brad King d05e98f8d7 ENH: Allow IMPORTED_IMPLIB w/o IMPORTED_LOCATION
Linking to a Windows shared library (.dll) requires only its import
library (.lib).  This teaches CMake to recognize SHARED IMPORTED library
targets that set only IMPORTED_IMPLIB and not IMPORTED_LOCATION.
2009-04-08 16:29:04 -04:00
Brad King d6bdaf9f13 ENH: Test transitive link to subdir-imported lib
This tests linking to an imported target that is not visible but is a
transitive dependency of a target that is visible.  See issue #8843.
2009-04-06 11:11:33 -04:00