/src/CMake/Source/cmLinkDirectoriesCommand.cxx
Line | Count | Source |
1 | | /* Distributed under the OSI-approved BSD 3-Clause License. See accompanying |
2 | | file LICENSE.rst or https://cmake.org/licensing for details. */ |
3 | | #include "cmLinkDirectoriesCommand.h" |
4 | | |
5 | | #include "cmDiagnostics.h" |
6 | | #include "cmExecutionStatus.h" |
7 | | #include "cmGeneratorExpression.h" |
8 | | #include "cmList.h" |
9 | | #include "cmMakefile.h" |
10 | | #include "cmStringAlgorithms.h" |
11 | | #include "cmSystemTools.h" |
12 | | |
13 | | static void AddLinkDir(cmMakefile& mf, std::string const& dir, |
14 | | std::vector<std::string>& directories); |
15 | | |
16 | | bool cmLinkDirectoriesCommand(std::vector<std::string> const& args, |
17 | | cmExecutionStatus& status) |
18 | 0 | { |
19 | 0 | cmMakefile& mf = status.GetMakefile(); |
20 | |
|
21 | 0 | mf.IssueDiagnostic(cmDiagnostics::CMD_NON_TARGET_DIRECTIVE, |
22 | 0 | "Use of non-target directives is not recommended. " |
23 | 0 | "Consider target_link_directories instead."); |
24 | |
|
25 | 0 | if (args.empty()) { |
26 | 0 | return true; |
27 | 0 | } |
28 | | |
29 | 0 | bool before = mf.IsOn("CMAKE_LINK_DIRECTORIES_BEFORE"); |
30 | |
|
31 | 0 | auto i = args.cbegin(); |
32 | 0 | if ((*i) == "BEFORE") { |
33 | 0 | before = true; |
34 | 0 | ++i; |
35 | 0 | } else if ((*i) == "AFTER") { |
36 | 0 | before = false; |
37 | 0 | ++i; |
38 | 0 | } |
39 | |
|
40 | 0 | std::vector<std::string> directories; |
41 | 0 | for (; i != args.cend(); ++i) { |
42 | 0 | AddLinkDir(mf, *i, directories); |
43 | 0 | } |
44 | |
|
45 | 0 | mf.AddLinkDirectory(cmList::to_string(directories), before); |
46 | |
|
47 | 0 | return true; |
48 | 0 | } |
49 | | |
50 | | static void AddLinkDir(cmMakefile& mf, std::string const& dir, |
51 | | std::vector<std::string>& directories) |
52 | 0 | { |
53 | 0 | std::string unixPath = dir; |
54 | 0 | cmSystemTools::ConvertToUnixSlashes(unixPath); |
55 | 0 | if (!cmSystemTools::FileIsFullPath(unixPath) && |
56 | 0 | !cmGeneratorExpression::StartsWithGeneratorExpression(unixPath)) { |
57 | 0 | unixPath = cmStrCat(mf.GetCurrentSourceDirectory(), '/', unixPath); |
58 | 0 | } |
59 | 0 | directories.push_back(unixPath); |
60 | 0 | } |