Commit Graph

116 Commits

Author SHA1 Message Date
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 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
Alex Neundorf 4b1919f73e ExportTargets: add one more comment to the generated file.
This patch adds a comment above the block which protects
the exported targets file against multiple inclusion, to make
the file easier to understand for readers.

Alex
2013-07-19 22:57:33 +02: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
Brad King 3caf565d07 Merge topic 'rpath-on-mac'
dc1d025 OS X: Add test for rpaths on Mac.
8576b3f OS X: Add support for @rpath in export files.
00d71bd Xcode: Add rpath support in Xcode generator.
94e7fef OS X: Add RPATH support for Mac.
2013-06-03 09:56:44 -04:00
Clinton Stimpson 8576b3f978 OS X: Add support for @rpath in export files.
Also expand the IMPORTED_SONAME property for targets
to match the install_name.
2013-06-03 09:42:05 -04: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 af81a3c31b install(EXPORT): Ensure clean INTERFACE_INCLUDE_DIRECTORIES
Check that source and binary directories are not part of the
INTERFACE_INCLUDE_DIRECTORIES for installed IMPORTED targets.

This is limited to directories which do not contain generator
expressions to evaluate. Such paths can only be checked at time
of use of the imported target, which will be done in a follow up
patch.
2013-03-26 10:45:07 -04:00
Brad King b887bca6ee Merge topic 'try_compile-targets'
236133e Handle targets in the LINK_LIBRARIES of try_compile.
1c0597c Add a new Export generator for IMPORTED targets.
f2ab17d Keep track of all targets seen while evaluating a genex.
2013-02-25 13:12:02 -05:00
Stephen Kelly 1c0597c25b Add a new Export generator for IMPORTED targets.
This is to be used during try_compile using LINK_LIBRARIES in the
srcfile signature and, in the future, TARGETS in the binary dir
signature.
2013-02-22 08:35:38 -05:00
Alex Neundorf 11d0c66206 export files: rewrite the code for checking required targets
Instead of generating a whole bunch of repeated if-statements
now a foreach()-loop is generated in the targets-file.
Also now a comment is inserted in the generated file if no
targets from other export sets are used, so if somebody looks
at the file he can see whether the information about missing
imported targets has been generated or not.

Alex
2013-02-20 20:09:45 +01:00
Stephen Kelly 79ae968a18 Revert "Add a way to exclude INTERFACE properties from exported targets."
This reverts commit 2c3654c3de.

The removal of some tests added in commit 77cecb77 (Add includes and compile
definitions with target_link_libraries., 2012-11-05) are also squashed
into this commit.
2013-02-13 15:12:31 +01:00
Stephen Kelly 3df36b5954 Revert "Add the $<LINKED:...> generator expression."
This reverts commit 0b92602b81.

Conflicts:
	Source/cmGeneratorExpressionEvaluator.cxx
	Tests/CMakeCommands/target_compile_definitions/CMakeLists.txt
	Tests/CMakeCommands/target_include_directories/CMakeLists.txt
2013-02-13 15:12:31 +01:00
Stephen Kelly 92e98dd909 Deduplicate the isGeneratorExpression method.
This API seems like the most appropriate.
2013-02-07 16:21:08 +01:00
Stephen Kelly 0b92602b81 Add the $<LINKED:...> generator expression.
This is both a short form of using a TARGET_DEFINED expression
together with a TARGET_PROPERTY definition, and a way to strip
non-target content from interface properties when exporting.
2013-01-31 17:34:20 +01:00
Stephen Kelly 2c3654c3de Add a way to exclude INTERFACE properties from exported targets.
Projects set interface requirements upstream, and existing
downstreams use of target_link_libraries will consume those interfaces.

This can create a backward compatibility concern as the result may
be changing the order of include directories of downstreams, or another
side-effect of using the INTERFACE properties.

Provide a way for them to emulate the behavior of a version-based
policy in the config file.
2013-01-31 17:29:04 +01:00
Stephen Kelly 7ceeba992b Advance more when preprocessing exported strings.
When evaluating TARGET_PROPERTY here, we can skip to the comma
location. We need to calculate it though as the string may have
just been changed.
2013-01-31 11:18:52 +01:00
Brad King 2eb7cee117 Merge topic 'fix-TARGET_PROPERTY-extraction'
5daaa5c Fix TARGET_PROPERTY target extractions.
2013-01-29 14:52:34 -05:00
Stephen Kelly 5daaa5c48d Fix TARGET_PROPERTY target extractions.
We need to make sure we can export targets which have content such
as $<0:$<TARGET_PROPERTY:not_a_target,INTERFACE_INCLUDE_DIRECTORIES>

That means making not finding a target non-fatal here.
2013-01-29 10:56:09 -05:00
Stephen Kelly 34d1ade048 Add the INSTALL_PREFIX genex. 2013-01-27 09:59:26 +01:00
Stephen Kelly 2fb2c32f9b Add the COMPATIBLE_INTERFACE_STRING property. 2013-01-24 20:36:04 +01:00
Brad King 33695c616a Merge topic 'export-new-style-files'
02d4e53 Generate new-style cmake code during export.
2013-01-23 15:11:32 -05:00
Stephen Kelly 830246e841 Export the COMPATIBLE_INTERFACE_BOOL content properties 2013-01-21 09:05:03 +01:00
Stephen Kelly 02d4e53f48 Generate new-style cmake code during export.
Use empty end*() commands and lowercase commands.
2013-01-20 18:05:23 +01:00
Stephen Kelly 522bdac149 Export the INTERFACE_PIC property. 2013-01-15 14:36:22 -05:00
Stephen Kelly cfd4f0a4f4 Move the exported check for dependencies of targets
Check only once, in the Config.cmake file, instead of once in each
Config-<cfg>.cmake file.
2013-01-15 14:36:21 -05:00
Stephen Kelly d8fe1fcd80 Only generate one check per missing target. 2013-01-15 14:36:21 -05:00
Stephen Kelly f623d37a95 Don't write a comment in the export file without the code. 2013-01-15 14:36:21 -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 94aeaf72c7 Split LINK_INTERFACE_LIBRARIES export handling into dedicated method. 2013-01-10 18:06:57 +01:00
Stephen Kelly a3aedb8152 Split the generator expression before extracting targets.
Now that we're processing a LINK_INTERFACE_LIBRARIES string, it
can contain targets. Make sure they are extracted for
namespacing purposes.

This needs to be restricted to strings which can actually have
targets named in them. For example, this is not done for
INTERFACE_COMPILE_DEFINITIONS, because even if there is a target
named 'foo', the string 'foo' in that property means that '-Dfoo'
will be set when compiling.
2013-01-10 18:06:57 +01:00
Stephen Kelly b6036d104a Extract the AddTargetNamespace method. 2013-01-10 18:06:03 +01:00
Stephen Kelly cb1afbf466 Don't pass a position when determining if a target name is a literal.
The lastPos refers to a position in a different string.
2013-01-10 18:06:03 +01:00
Stephen Kelly 40cf3fb95b Make linking APIs aware of 'head' target
The 'head' is the dependent target to be linked with the current target.
It will be used to evaluate generator expressions with proper handling
of mapped configurations and is used as the source target of properties.

This requires that memoization is done with a key of a pair of target
and config, instead of just config, because now the result also depends
on the target.  Removing the memoization entirely is not an option
because it slows cmake down considerably.
2013-01-08 08:53:25 -05:00
Stephen Kelly 0c657dc637 Add API to populate INTERFACE properties in exported targets.
The INTERFACE properties need to be preprocessed for context (build
location or install location) and to extract target names etc.
2013-01-05 01:18:36 +01:00
Stephen Kelly e04f737c7a Add API to extract target names from a genex string.
The TARGET_NAME expression, which requires a literal, provides
target names. $<TARGET_PROPERTY:tgt,prop> also provides target
names in the cases where tgt is a literal, so that TARGET_NAME is
not needed then in addition.
2013-01-05 01:18:36 +01:00
Stephen Kelly bf2ddceb4e Generate an early-return guard in target Export files.
Previously it was necessary for writers of Config files
which incude exported target files to write the guard themselves, but
this was not immediately obvious or documented. Options for them
would be to use a variable, or an INHERITED directory property in an
effort to avoid accidental name clashes in all contexts in
which find_package can be used.

Getting this right requires boiler plate code, so generate a simpler
check automatically instead.
2012-11-30 09:51:17 +01:00
Alex Neundorf 6f50a04cc1 exports: define a CMAKE_FIND_PACKAGE_NAME var set by find_package()
This way the name of the searched package can be accessed in find-modules,
config-files and more importantly in generated target export files.
This is now used when a target export file detects that a required
target does not exist.

Alex
2012-09-30 10:26:54 -04:00
Alex Neundorf 0cfd055acd exports: move the handling of missing targets into subclasses
Before, cmExportFileGenerator::ComplainAboutMissingTarget() was a virtual
function which had to be implemented in the subclasses. It is not
anymore. Instead, there is now a virtual function
HandleMissingTargets(), which is implemented in the two subclasses.
This makes e.g. dealing correctly with APPEND mode easier.

Alex
2012-09-30 10:26:10 -04:00
Alex Neundorf 190f2c8253 exports: fix build with MSVC6
it seems it doesn't like deleting const pointers

Alex
2012-09-28 17:00:52 -04:00
Alex Neundorf 8b5f448ba6 exports: first try at error handling if a target is missing
Now, if an imported target depends on a library which must come
from some other export set, cmake generates a check which errors
out if that target does not exist. I guess instead of completely
erroring out it would be better to only make the find_package() fail.

Alex
2012-09-28 09:21:42 -04:00
Alex Neundorf 87f4c01910 exports: accept a missing target if it is exported exactly once
If a target is exported, and a library it depends on is not part
of the same export set, before this patch cmake errored out.
With this patch, it now checks whether the missing target
is exported somewhere else exactly once, and accepts in this
case (because then it can determine the namespace for the
missing target and use this).

Alex
2012-09-28 09:21:42 -04:00
Modestas Vainius e1409ac59b Support building shared libraries or modules without soname (#13155)
Add a boolean target property NO_SONAME which may be used to disable
soname for the specified shared library or module even if the platform
supports it.  This property should be useful for private shared
libraries or various plugins which live in private directories and have
not been designed to be found or loaded globally.

Replace references to <CMAKE_SHARED_LIBRARY_SONAME_${LANG}_FLAG> and
hard-coded -install_name flags with a conditional <SONAME_FLAG> which is
expanded to the value of the CMAKE_SHARED_LIBRARY_SONAME_${LANG}_FLAG
definition as long as soname supports is enabled for the target in
question.  Keep expanding CMAKE_SHARED_LIBRARY_SONAME_${LANG}_FLAG in
rules in case third party projects still use it.  Such projects would
not yet use NO_SONAME so the adjacent <TARGET_SONAME> will always be
expanded.  Make <TARGET_INSTALLNAME_DIR> NO_SONAME aware as well.  Since
-install_name is soname on OS X, this should not be a problem if this
variable is expanded only if soname is enabled.

The Ninja generator performs rule variable substitution only once
globally per rule to put its own placeholders.  Final substitution is
performed by ninja at build time.  Therefore we cannot conditionally
replace the soname placeholders on a per-target basis.  Rather than
omitting $SONAME from rules.ninja, simply do not write its contents for
targets which have NO_SONAME.  Since 3 variables are affected by
NO_SONAME ($SONAME, $SONAME_FLAG, $INSTALLNAME_DIR), set them only if
soname is enabled.
2012-04-30 11:50:27 -04:00
Brad King 5c03438661 install(EXPORT): Improve target import failure message format 2011-11-22 15:55:04 -05:00
Alex Neundorf a2be068c75 install(EXPORT): Enforce existence of imported target files
Typical <package>Config.cmake files for find_package() rely only on the
files generated by install(EXPORT).  They might be wrong, for whatever
reasons, like people manually deleted files, projects were packaged
wrong by distributions, whatever.  To protect against this, add checks
that the file locations we are importing actually exist on disk.

Alex
2011-11-22 15:55:00 -05:00
Richard Bateman 5457b8254c Add support for CFBundle targets on the Mac (#11295)
This commit enables building, for example, plugin bundles
to be loaded by web browsers.
2011-01-11 12:54:44 -05:00
Brad King 96afb12087 Convert CMake to OSI-approved BSD License
This converts the CMake license to a pure 3-clause OSI-approved BSD
License.  We drop the previous license clause requiring modified
versions to be plainly marked.  We also update the CMake copyright to
cover the full development time range.
2009-09-28 11:43:28 -04:00
Brad King 69251f7549 Define 'multiplicity' for cyclic dependencies
We create target property "LINK_INTERFACE_MULTIPLICITY" and a per-config
version "LINK_INTERFACE_MULTIPLICITY_<CONFIG>".  It sets the number of
times a linker should scan through a mutually dependent group of static
libraries.  The largest value of this property on any target in the
group is used.  This will help projects link even for extreme cases of
cyclic inter-target dependencies.
2009-09-01 10:37:37 -04:00
Brad King f888a0efaf ENH: Export and import link interface languages
Now that languages are part of the link interface of a target we need to
export/import the information.  A new IMPORTED_LINK_INTERFACE_LANGUAGES
property and per-config IMPORTED_LINK_INTERFACE_LANGUAGES_<CONFIG>
property specify the information for imported targets.  The export() and
install(EXPORT) commands automatically set the properties.
2009-07-11 10:12:05 -04:00
Brad King 34f78ee552 ENH: Simplify cmTarget link interface storage
This makes the LinkInterface struct a member of cmTarget, pimplizes the
config-to-interface map, and stores interface instances by value.
2009-07-07 09:45:29 -04:00
Brad King 06b0a692f4 ENH: Centralize default link interface computation
When LINK_INTERFACE_LIBRARIES is not set we use the link implementation
to implicitly define the link interface.  These changes centralize the
decision so that all linkable targets internally have a link interface.
2009-07-06 16:25:20 -04:00
Brad King 3c5cf1bb8c ENH: Allow a custom list of debug configurations
Create a DEBUG_CONFIGURATIONS global property as a way for projects to
specify which configuration names are considered to be 'debug'
configurations.
2008-09-04 17:34:25 -04:00
Alexander Neundorf 68d6394cef ENH: protect the export files against inclusion with cmake 2.4
Alex
2008-04-27 07:30:46 -04:00
Brad King 6d064999f6 BUG: Generated target export files should set the policy version to 2.6 instead of the currently running version because they are 2.6 compatible. 2008-03-31 13:48:50 -04:00
Brad King a0ef989715 ENH: Add cmake_policy push/version/pop to import/export files. 2008-03-13 17:04:32 -04:00
Brad King dab5ea859a COMP: Fix Borland 5.5 build
- Its <iosfwd> header includes windows.h which
    defines GetCurrentDirectory
  - It defines 'interface' so we cannot use it as
    a variable name.
2008-02-24 14:05:11 -05:00
Brad King 82fcaebe28 ENH: Pass dependent library search path to linker on some platforms.
- Move runtime path ordering out of cmComputeLinkInformation
    into its own class cmOrderRuntimeDirectories.
  - Create an instance of cmOrderRuntimeDirectories for runtime
    path ordering and another instance for dependent library
    path ordering.
  - Replace CMAKE_DEPENDENT_SHARED_LIBRARY_MODE with explicit
    CMAKE_LINK_DEPENDENT_LIBRARY_FILES boolean.
  - Create CMAKE_LINK_DEPENDENT_LIBRARY_DIRS boolean.
  - Create variables to specify -rpath-link flags:
      CMAKE_SHARED_LIBRARY_RPATH_LINK_<LANG>_FLAG
      CMAKE_EXECUTABLE_RPATH_LINK_<LANG>_FLAG
  - Enable -rpath-link flag on Linux and QNX.
  - Documentation and error message updates
2008-02-01 08:56:00 -05:00
Brad King 2cff26fa52 ENH: Support linking to shared libs with dependent libs
- Split IMPORTED_LINK_LIBRARIES into two parts:
      IMPORTED_LINK_INTERFACE_LIBRARIES
      IMPORTED_LINK_DEPENDENT_LIBRARIES
  - Add CMAKE_DEPENDENT_SHARED_LIBRARY_MODE to select behavior
  - Set mode to LINK for Darwin (fixes universal binary problem)
  - Update ExportImport test to account for changes
2008-01-31 15:45:31 -05:00
Brad King 73a5f0846f COMP: Remove unused parameter. 2008-01-31 06:51:43 -05:00
Brad King 0ac845b7da BUG: Fixed previous commit in cmExportFileGenerator to separate libraries correctly in the import link list. 2008-01-30 17:57:54 -05:00
Brad King 7902bc06aa ENH: Implemented link-interface specification feature.
- Shared libs and executables with exports may now have
    explicit transitive link dependencies specified
  - Created LINK_INTERFACE_LIBRARIES and related properties
  - Exported targets get the interface libraries as their
    IMPORTED_LINK_LIBRARIES property.
  - The export() and install(EXPORT) commands now give
    an error when a linked target is not included since
    the user can change the interface libraries instead
    of adding the target.
2008-01-30 17:25:52 -05:00
Brad King e3b1bdb058 ENH: Support exporting/importing of AppBundle targets.
- Imported bundles have the MACOSX_BUNDLE property set
  - Added cmTarget::IsAppBundleOnApple method to simplify checks
  - Document BUNDLE keyword in INSTALL command
  - Updated IMPORTED_LOCATION property documentation for bundles
  - Updated ExportImport test to test bundles
2008-01-28 14:46:16 -05:00
Brad King 437043bb04 BUG: Fix export/import file generation to not store link dependencies of executables or modules. 2008-01-28 13:37:59 -05:00
Brad King 6388ebceb1 ENH: Restored APPEND option to EXPORT() command in new implementation. 2008-01-28 13:21:42 -05:00
Brad King 28ea034737 ENH: Support exporting/importing of Framework targets.
- Imported frameworks have the FRAMEWORK property set
  - Added cmTarget::IsFrameworkOnApple method to simplify checks
  - Also remove separate IMPORTED_ENABLE_EXPORTS property and just use ENABLE_EXPORTS since, like FRAMEWORK, it just represents the target type.
  - Document FRAMEWORK keyword in INSTALL command.
  - Updated IMPORTED_LOCATION property documentation for Frameworks
2008-01-28 13:05:58 -05:00
Brad King 5594ad4885 ENH: Updated exporting and importing of targets to support libraries and configurations.
- Created cmExportFileGenerator hierarchy to implement export file generation
  - Installed exports use per-config import files loaded by a central one.
  - Include soname of shared libraries in import information
  - Renamed PREFIX to NAMESPACE in INSTALL(EXPORT) and EXPORT() commands
  - Move addition of CMAKE_INSTALL_PREFIX to destinations to install generators
  - Import files compute the installation prefix relative to their location when loaded
  - Add mapping of importer configurations to importee configurations
  - Rename IMPORT targets to IMPORTED targets to distinguish from windows import libraries
  - Scope IMPORTED targets within directories to isolate them
  - Place all properties created by import files in the IMPORTED namespace
  - Document INSTALL(EXPORT) and EXPORT() commands.
  - Document IMPORTED signature of add_executable and add_library
  - Enable finding of imported targets in cmComputeLinkDepends
2008-01-28 08:38:36 -05:00