Additional target parameters#47
Additional target parameters#47maikelvdh wants to merge 2 commits intotomtom-international:masterfrom
Conversation
| } else { | ||
| o << "\n"; | ||
| } | ||
| comp.additionalTargetParameters.insert("INTERFACE"); |
There was a problem hiding this comment.
This is definitely the wrong place to do this. This function really shouldn't change this argument.
There was a problem hiding this comment.
Totally agree, was the easiest way to achieve this ;). I will lift it to the input side to have there header only detection.
| } | ||
| comp.additionalTargetParameters.insert("INTERFACE"); | ||
| } | ||
| if (!comp.additionalTargetParameters.empty()) { |
| std::string type; | ||
| size_t index, lowlink; | ||
| std::string additionalTargetParameters; | ||
| std::set<std::string> additionalTargetParameters; |
There was a problem hiding this comment.
Specific order is not relevant? This will result in EXCLUDE_FROM_ALL SHARED if you entered SHARED EXCLUDE_FROM_ALL, which may change the meaning. I'd use a vector here for that reason.
There was a problem hiding this comment.
The order is not relevant here with regards of your example.
| Component &comp = AddComponentDefinition(components, path.parent_path()); | ||
| bool inTargetDefinition = false; | ||
| bool inAutoSection = false; | ||
| int parenLevel = 0; |
There was a problem hiding this comment.
This was paren, as in parentheses, not as in parent without a T. This new name is very wrong and confusing.
There was a problem hiding this comment.
To be honest the parenLevel as in terms of the abbreviation was rather confusing me. Agree that parentLevel is also not great, but I would rather see a different name. Maybe we can give it a better name instead which isn't confusing for neither of us.
There was a problem hiding this comment.
When checking again parenLevel is the best typed name will revert back to that.
| : line.length(); | ||
| if (endOfLine > 0) { | ||
| const std::string targetLine(line.substr(0, endOfLine)); | ||
| static const std::unordered_set<std::string> cmakeTargetParameters = { "ALIAS", "EXCLUDE_FROM_ALL", "GLOBAL", "IMPORTED", "INTERFACE", "MACOSX_BUNDLE", "MODULE", "OBJECT", "STATIC", "SHARED", "UNKNOWN", "WIN32" }; |
There was a problem hiding this comment.
Smells like it should be configurable, or at least something you can add on to. Also, some of these change the meaning of other arguments, for example you don't list files after ALIAS. Is this actually tested to work well?
There was a problem hiding this comment.
Not sure whether we want to have this set of options configurable it is highly depending on CMake itself. With regards of testing the inputs I don't think the cpp-dependencies should handle this at all, that is up to the CMake tool itself otherwise we will start to replicate all the logic here. If an user has already written an CMakeLists.txt we should expect that it is at least accepted by the CMake parser.
There was a problem hiding this comment.
Actually when checking again we should make set of options which are actually allowed in combination and we should restrict ourselves to specific CMake versions as some options are new for example. So we should put a bit more thinking in how far we want to go here.
For example even the test scenario of INTERFACE EXCLUDE_FROM_ALL is not a valid definition.
| const std::string expectedOutput( | ||
| "add_library(${PROJECT_NAME} INTERFACE\n" | ||
| " EXCLUDE_FROM_ALL\n" | ||
| "add_library(${PROJECT_NAME} EXCLUDE_FROM_ALL INTERFACE\n" |
There was a problem hiding this comment.
Yeah... this is wrong. I want INTERFACE to come first as the defining type of the library.
There was a problem hiding this comment.
As mentioned earlier there is no strict order necessary, so I could make it a vector instead, but then still it would be matching first EXCLUDE_FROM_ALL and later INTERFACE.
| for (auto& pair : components) { | ||
| const Component& comp = *pair.second; | ||
| ASSERT(comp.additionalTargetParameters.size() == 2); | ||
| ASSERT(*comp.additionalTargetParameters.begin() == "EXCLUDE_FROM_ALL"); |
There was a problem hiding this comment.
Why do you assert on the order?
There was a problem hiding this comment.
Will change this to evaluate that both arguments are in the set present.
This will allow users freedom to specify additional target parameters in
add_executable()andadd_library()in more relaxed way, e.g:Next it will no longer enforce the usage of
STATIClibraries by default after regeneration, but leave the possibility for the user to leave it blank and obtain then then the default setting of CMake which isSTATICanyway. That behaviour can in turn then easily be adjusted by using the CMake flagBUILD_SHARED_LIBS.