Commit Graph

88 Commits

Author SHA1 Message Date
Brad King
f0e67da061 target_link_libraries: Fix out-of-dir linking of a list of targets
In a case like

    target_link_libraries(targetInOtherDir PUBLIC "$<1:a;b>")

then all entries in the list need to be looked up in the caller's
scope.  Previously our `::@(directory-id)` suffix would apply only
to the last entry.  Instead surround the entire entry by a pair
`::@(directory-id);...;::@` so that the `::@` syntax can encode
a directory lookup scope change evaluated as the list is processed.

Fixes: #20204
2020-01-16 13:24:27 -05:00
Brad King
09721ca078 target_link_libraries: Fix out-of-dir calls with debug/optimized keywords
In commit a1ad0a699b (target_link_libraries: Allow use with targets in
other directories, 2018-09-07, v3.13.0-rc1~94^2) we added use of `<...>`
to encode a directory id, but the closing `>` can incorrectly terminate
a surrounding generator expression early.  Encode the directory id using
`(...)` instead.

Fixes: #20202
2020-01-10 11:40:34 -05:00
Brad King
c40229968c target_link_libraries: Add FIXME comment for out-of-dir genex list
Issue: #20204
2020-01-10 11:40:18 -05:00
Kitware Robot
ed98209ddc Revise include order using clang-format-6.0
Run the `clang-format.bash` script to update our C and C++ code to a new
include order `.clang-format`.  Use `clang-format` version 6.0.
2019-10-01 12:26:36 -04:00
Robert Maynard
808b818063 Genex: CompileLang and CompileLangAndId now match against a list of ids
This allows for expressions such as:

 $<COMPILE_LANG_AND_ID, CXX, GNU, Clang>
2019-06-03 10:20:23 -04:00
Robert Maynard
ec66af2026 Genex: CompilerId now can match against a list of ids.
This allows for expressions like:
 $<$<CXX_COMPILER_ID:Clang,GNU>:-DMY_PRIVATE_DEFINE>
2019-06-03 10:20:23 -04:00
Robert Maynard
e214abdaab Genex: Add COMPILE_LANG_AND_ID generator expression 2019-05-14 14:54:15 -04:00
Brad King
3d3713121b target_link_libraries: Fix static library private deps in other dirs
In commit a1ad0a699b (target_link_libraries: Allow use with targets in
other directories, 2018-09-07, v3.13.0-rc1~94^2) we accidentally broke
the logic that adds `$<LINK_ONLY:...>` to private dependencies of static
libraries in their `INTERFACE_LINK_LIBRARIES` in the case that the
dependency is added from outside the directory creating the library.
The check for a valid target name should apply to the original name
specified by the caller and not the encoded cross-directory reference.

Fixes: #19197
2019-04-30 13:53:10 -04:00
Marc Chevrier
f9717725f9 link_directories(): enhance capabilities 2018-09-25 23:59:59 +10:00
Marc Chevrier
a71caab46b LINK_DIRECTORIES: Add new properties and commands
These new capabilities enable to manage link directories

Two new properties:
* target properties: LINK_DIRECTORIES and INTERFACE_LINK_DIRECTORIES

One new command
* target_link_directories(): to populate target properties

Fixes: #17215
2018-09-25 23:59:58 +10:00
Brad King
2af106a43a Merge topic 'link-options'
6da8b67c3f target_link_options: fix erroneous handling of BEFORE keyword.

Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !2384
2018-09-17 09:25:40 -04:00
Marc Chevrier
6da8b67c3f target_link_options: fix erroneous handling of BEFORE keyword. 2018-09-14 18:10:58 +02:00
Brad King
a1ad0a699b target_link_libraries: Allow use with targets in other directories
Previously the command did not allow naming targets on the LHS that
were not created in the calling directory.  Lift this restriction to
enable more flexible use by projects.

Targets named on the RHS will need to be looked up during generation in
the scope of the call site rather than the scope of the LHS target.
Introduce an internal syntax in `[INTERFACE_]LINK_LIBRARIES` properties
to specify target names that need to be looked up in a directory other
than that containing the target on which the property is set.  Add
minimal documentation of the syntax to help users that encounter it.

Unfortunately CMake previously did allow such calls in the case that
only `INTERFACE` libraries are specified, but those libraries would be
looked up in the target's directory rather than the caller's.  Add
policy `CMP0079` to enable the new behavior with new lookup scope in a
compatible way.

Fixes: #17943
2018-09-12 13:06:36 -04:00
Marc Chevrier
174721ecc0 LINK_OPTIONS property: add test for static library.
Check that property INTERFACE_LINK_OPTIONS is correctly propagated
from static libraries.

Issue: #18251
2018-08-15 14:40:36 +02:00
Craig Scott
6e7b424240 Merge topic 'subdir_target_sources'
316815e1f4 target_sources: Interpret relative paths as relative to the calling directory

Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !2128
2018-06-19 08:24:08 -04:00
Patrick Stotko
316815e1f4 target_sources: Interpret relative paths as relative to the calling directory
Previously the command considered non-absolute source file paths relative to
the associated target on the LHS. This causes problems in incremental builds
where files are added from subdirectories and forces users to workaround by
manually converting to absolute paths. Change this to enable more intuitive
usage by projects.

Fixes #17981
2018-06-18 21:01:57 +02:00
Marc Chevrier
c1f5a44b28 LINK_OPTIONS: Add new family of properties
This family enable to manage link flags

Three new properties:
* directory property: LINK_OPTIONS
* target properties: LINK_OPTIONS and INTERFACE_LINK_OPTIONS

Two new commands
* add_link_options(): to populate directory property
* target_link_options(): to populate target properties

Fixes: #16543
2018-06-06 17:22:39 +02:00
Kitware Robot
d7204e649e Revise C++ coding style using clang-format-6.0
Run the `clang-format.bash` script to update all our C and C++ code to a
new style defined by `.clang-format`.  Use `clang-format` version 6.0.

* If you reached this commit for a line in `git blame`, re-run the blame
  operation starting at the parent of this commit to see older history
  for the content.

* See the parent commit for instructions to rebase a change across this
  style transition commit.
2018-06-01 09:53:42 -04:00
Marc Chevrier
cb83314e65 add_compile_definitions: add new command
This command manages preprocessor definitions at directory level and
supports generator expressions.

Fixes: #15374
2018-04-20 09:28:13 -04:00
Brad King
a53cf69022 Features: Record C features for MSVC
The MSVC C compiler has no notion of C language standards or flags.
Tell CMake to assume that all language standards are available.
Record available C language features depending on the version of
the compiler.

Fixes: #17858
2018-03-29 10:40:13 -04:00
Brad King
506fda1cf0 Genex: Enable COMPILE_LANGUAGE for INCLUDE_DIRECTORIES with VS and Xcode
The set of compile flags used for a target's C and C++ sources is based
on the linker language.  By default this is always the C++ flags if any
C++ sources appear in the target, and otherwise the C flags.  Therefore
we can define the `COMPILE_LANGUAGE` generator expression in
`INCLUDE_DIRECTORIES` to match the selected language.

This is not exactly the same as for other generators, but is the best VS
and Xcode can do.  It is also sufficient for many use cases since the
set of include directories for C and C++ is frequently similar but may
be distinct from those for other languages like CUDA.

Fixes: #17435
2018-01-12 14:27:37 -05:00
Brad King
c2f79c9867 Genex: Enable COMPILE_LANGUAGE for COMPILE_DEFINITIONS with VS and Xcode
The set of compile flags used for a target's C and C++ sources is based
on the linker language.  By default this is always the C++ flags if any
C++ sources appear in the target, and otherwise the C flags.  Therefore
we can define the `COMPILE_LANGUAGE` generator expression in
`COMPILE_DEFINITIONS` to match the selected language.

This is not exactly the same as for other generators, but is the best VS
and Xcode can do.  It is also sufficient for many use cases since the
set of definitions for C and C++ is frequently similar but may be
distinct from those for other languages like CUDA.

Issue: #17435
2018-01-12 14:27:37 -05:00
Brad King
2ae880fa8f Genex: Enable COMPILE_LANGUAGE for COMPILE_OPTIONS with Visual Studio
Since commit v3.9.0-rc4~3^2~1 (VS: Fix target_compile_options for CUDA,
2017-06-21), the evaluation of `COMPILE_LANGUAGE` receives the proper
language.  The set of compile flags used for a target's C and C++
sources is based on the linker language.  By default this is always the
C++ flags if any C++ sources appear in the target, and otherwise the C
flags.  Therefore we can define the `COMPILE_LANGUAGE` generator
expression in `COMPILE_OPTIONS` to match the selected language.

This is not exactly the same as for other generators, but is the best VS
can do.  It is also sufficient for many use cases since the set of
allowed flags for C and C++ is almost the same in Visual Studio.
Furthermore, since the VS generator moves many of the flags to
declarative `.vcxproj` elements, it will automatically avoid passing
C++ flags for C sources.

Issue: #17435
2017-11-20 13:51:25 -05:00
Chuck Atkins
e556f1b909 CompileFeatures: Makes tests work with meta-feature only 2017-05-29 13:51:45 -04:00
Craig Scott
1bfe37201a Tests: Ensure Solaris linker never sees empty contents
Fixes the following tests on Solaris builds: wrapping, qtwrapping and
CMakeCommands.target_link_libraries
2017-05-18 10:32:03 +10:00
Rolf Eike Beer
ef47272b07 Tests: use cxx_auto_type only if actually available
The presence of CMAKE_CXX_COMPILE_FEATURES doesn't mean cxx_auto_type is always
available.
2017-01-25 21:00:30 +01:00
Kitware Robot
d9fd2f5402 Revise C++ coding style using clang-format
Run the `Utilities/Scripts/clang-format.bash` script to update
all our C++ code to a new style defined by `.clang-format`.
Use `clang-format` version 3.8.

* If you reached this commit for a line in `git blame`, re-run the blame
  operation starting at the parent of this commit to see older history
  for the content.

* See the parent commit for instructions to rebase a change across this
  style transition commit.
2016-05-16 16:05:19 -04:00
Brad King
e1c7747253 Format include directive blocks and ordering with clang-format
Sort include directives within each block (separated by a blank line) in
lexicographic order (except to prioritize `sys/types.h` first).  First
run `clang-format` with the config file:

    ---
    SortIncludes: false
    ...

Commit the result temporarily.  Then run `clang-format` again with:

    ---
    SortIncludes: true
    IncludeCategories:
      - Regex:    'sys/types.h'
        Priority: -1
    ...

Commit the result temporarily.  Start a new branch and cherry-pick the
second commit.  Manually resolve conflicts to preserve indentation of
re-ordered includes.  This cleans up the include ordering without
changing any other style.

Use the following command to run `clang-format`:

    $ git ls-files -z -- \
        '*.c' '*.cc' '*.cpp' '*.cxx' '*.h' '*.hh' '*.hpp' '*.hxx' |
      egrep -z -v '(Lexer|Parser|ParserHelper)\.' |
      egrep -z -v '^Source/cm_sha2' |
      egrep -z -v '^Source/(kwsys|CursesDialog/form)/' |
      egrep -z -v '^Utilities/(KW|cm).*/' |
      egrep -z -v '^Tests/Module/GenerateExportHeader' |
      egrep -z -v '^Tests/RunCMake/CommandLine/cmake_depends/test_UTF-16LE.h' |
      xargs -0 clang-format -i

This selects source files that do not come from a third-party.

Inspired-by: Daniel Pfeifer <daniel@pfeifer-mail.de>
2016-04-29 13:58:54 -04:00
Brad King
0778016a0b Tests: Do not try to use invalid "ld -v" flag on Solaris
Fix the CMakeCommands.target_link_libraries test to use "-V" instead of
"-v" on Solaris because the latter does not exist.
2015-03-31 11:21:36 -04:00
Stephen Kelly
b734fa4471 Genex: Allow COMPILE_LANGUAGE when processing include directories.
Issue an error if this is encountered by an IDE generator.
2015-03-09 20:49:17 +01:00
Stephen Kelly
0b945ea9a6 Genex: Allow COMPILE_LANGUAGE when processing compile definitions.
Issue an error if this is encountered by an IDE generator.
2015-03-09 20:49:16 +01:00
Stephen Kelly
5c559f1113 Genex: Enable use of COMPILE_LANGUAGE for compile options.
Follow-ups will allow the use of the generator expression
for compile definitions and include directories for non-IDE
generators.
2015-03-09 20:48:57 +01:00
Stephen Kelly
e0890d03a4 Features: Extend concept to C language.
Add properties and variables corresponding to CXX equivalents.

Add features for c_function_prototypes (C90), c_restrict (C99),
c_variadic_macros (C99) and c_static_assert (C11). This feature
set can be extended later.

Add a <PREFIX>_RESTRICT symbol define to WriteCompilerDetectionHeader
to conditionally represent the c_restrict feature.
2014-05-15 00:15:18 +02:00
Stephen Kelly
447fbb3fac Tests: Execute compile features tests unconditionally.
Conditionally create a dummy test if there are no known features.
2014-04-17 16:20:50 +02:00
Stephen Kelly
8ed59fc207 Add target_compile_features command.
This can be used to set the compiler features required by particular
targets. An error is issued at CMake time if the compiler does not
support the required feature. If a language dialect flag is required
by the features used, that will be added automatically.

Base the target_compile_features command on cmTargetPropCommandBase. This
gives us 'free' handling of IMPORTED, ALIAS, INTERFACE, non-compilable
and missing targets.
2014-04-07 18:11:18 +02:00
Stephen Kelly
272a20f8e5 cmTarget: Don't update IMPORTED target compilation properties
The include_directories() and add_compile_options() commands
should not append to the corresponding target property for IMPORTED
targets.  This is already the case for add_definitions().
2014-01-04 11:28:57 +01:00
Stephen Kelly
38afc82e76 target_include_directories: Allow relative path with genex
Treat paths which are relative and which contain a generator
expression which is not at the beginning as relative to the
source directory.

This matches the behavior of paths which are relative but contain
no generator expression at all.

Previously this would generate a relative path with the IMPORTED
target on export(), which would be a reported as a non-existent
path on import. If used directly in the buildsystem, it would be
reported as a relative path, which is also an error. There is no
need for a policy in this case.
2013-11-26 10:30:18 +01:00
Brad King
25b7f87eca Merge branch 'policy-CMP0022-fixes' into policy-CMP0022-fixes-for-master
Resolve conflict in Source/cmTarget.cxx by integrating the changes to
the internal copy constructor from both sides.  Also resolve a logical
conflict by dropping the special case for INTERFACE_LIBRARY targets.
Since cmTarget::SetMakefile already forces CMP0022 to NEW for such
targets we need no special handling.

Resolve conflict in Source/cmTargetLinkLibrariesCommand.h by dropping
the documentation change.  We will make the same change in the new
location of the same documentation in a separate commit.

Resolve conflicts in

 Tests/RunCMake/CMP0022/CMP0022-WARN-empty-old-stderr.txt
 Tests/RunCMake/CMP0022/RunCMakeTest.cmake

by taking the side from the 'policy-CMP0022-fixes' branch.
2013-11-03 09:20:47 -05:00
Stephen Kelly
0e06788c0a CMP0022: Add test for target_link_libraries plain signature 2013-11-02 12:48:48 -04:00
Brad King
1b21ac405f Merge topic 'fix-tll-static-private'
239b0c6 Don't add invalid content to static lib INTERFACE_LINK_LIBRARIES.
2013-10-26 10:28:02 -04:00
Stephen Kelly
239b0c6b0e Don't add invalid content to static lib INTERFACE_LINK_LIBRARIES.
Only valid target names or generator expressions may appear in
the target field of a LINK_ONLY expression.

Other content like link flags should still be added to that property
(wrapped in config-specific generator expressions), but not wrapped
in LINK_ONLY. Otherwise undue warnings would be issued for the
policy CMP0022.

The LINK_ONLY expression only has an effect for actual target
names anyway, so there is no logical deficit.
2013-10-26 10:10:20 -04:00
Stephen Kelly
dede273193 target_link_libraries: Allow repeated use of LINK_{PRIVATE,PUBLIC} keywords.
This has not been allowed since they were introduced in
commit 91438222 (target_link_libraries: Add LINK_(PUBLIC|PRIVATE)
options, 2011-10-07), but allowing this form makes it more compatible
with the newer PUBLIC and PRIVATE keywords.
2013-10-17 17:37:20 +02:00
Stephen Kelly
c0b8682200 Allow target commands to be invoked with no items (#14325).
Code such as

 target_include_directories(foo PRIVATE ${items})

should not work or break based on whether items is defined or not.
2013-07-31 16:06:34 +02:00
Stephen Kelly
c8a10ba9ad cmTarget: Fix iface libraries and languages for static libraries. 2013-07-26 15:15:42 +02:00
Stephen Kelly
b655865bbf target_link_libraries: Add PUBLIC/PRIVATE/INTERFACE keyword signature
Add a new signature to help populate INTERFACE_LINK_LIBRARIES and
LINK_LIBRARIES cleanly in a single call.  Add policy CMP0023 to control
whether the keyword signatures can be mixed with uses of the plain
signatures on the same target.
2013-07-24 11:52:44 -04:00
Stephen Kelly
3e30d9ed67 TLL: Don't populate old link interface if CMP0022 is NEW.
Always populate the INTERFACE_LINK_LIBRARIES for interface
entries. Don't populate the old interface properties
matching (IMPORTED_)?LINK_INTERFACE_LIBRARIES(_<CONFIG>)?
if CMP0022 is NEW.

Because the INTERFACE_LINK_LIBRARIES property is now populated by
the target_link_libraries when operating on a static library,
make an equivalent change which populates the property with
the same value when the old link_libraries() command is used. This
silences the policy warning in that case.
2013-07-08 22:39:58 +02:00
Stephen Kelly
a984f3257e Introduce add_compile_options command.
This command is similar to add_definitions, in that it affects
the compile options of all targets which follow it. The implementation
is similar to the implementation of the include_directories command,
in that it is based on populating a COMPILE_OPTIONS directory property
and using that to initialize the same property on targets.

Unlike the include_directories command however, the add_compile_options
command does not affect previously defined targets. That is, in
the following code, foo will not be compiled with -Wall, but bar
will be:

 add_library(foo ...)
 add_compile_options(-Wall)
 add_library(bar ...)
2013-06-04 11:36:55 +02:00
Stephen Kelly
24466f22c0 Add target_compile_options command.
This command populates the COMPILE_OPTIONS target property.
2013-06-02 11:56:37 +02:00
Stephen Kelly
88308bc2f2 Test that linking using the debug keyword to tll works. 2013-05-16 14:31:00 -04:00
Brad King
fc43477de0 Rename variable for including current directory in interfaces
Rename the variable added by commit 9ce1b9ef (Add
CMAKE_BUILD_INTERFACE_INCLUDES build-variable, 2012-11-25) to
CMAKE_INCLUDE_CURRENT_DIR_IN_INTERFACE to be more consistent with the
existing CMAKE_INCLUDE_CURRENT_DIR variable.

Suggested-by: Alex Neundorf <neundorf@kde.org>
2013-03-19 16:44:17 -04:00