Skip to content

Additional target parameters #47

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

maikelvdh
Copy link
Member

@maikelvdh maikelvdh commented Oct 10, 2017

This will allow users freedom to specify additional target parameters in add_executable() and add_library() in more relaxed way, e.g:

add_library(MY_PROJECT_1 SHARED EXCLUDE_FROM_ALL my_source_1.cpp)
add_library(MY_PROJECT_2
  SHARED
  EXCLUDE_FROM_ALL
  my_source_2.cpp
)

Next it will no longer enforce the usage of STATIC libraries 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 is STATIC anyway. That behaviour can in turn then easily be adjusted by using the CMake flag BUILD_SHARED_LIBS.

} else {
o << "\n";
}
comp.additionalTargetParameters.insert("INTERFACE");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is definitely the wrong place to do this. This function really shouldn't change this argument.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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()) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This if does nothing.

@@ -87,7 +87,7 @@ struct Component {
bool hasAddonCmake;
std::string type;
size_t index, lowlink;
std::string additionalTargetParameters;
std::set<std::string> additionalTargetParameters;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The order is not relevant here with regards of your example.

@@ -250,58 +250,60 @@ static void ReadCmakelist(const Configuration& config, std::unordered_map<std::s
Component &comp = AddComponentDefinition(components, path.parent_path());
bool inTargetDefinition = false;
bool inAutoSection = false;
int parenLevel = 0;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was paren, as in parentheses, not as in parent without a T. This new name is very wrong and confusing.

Copy link
Member Author

@maikelvdh maikelvdh Oct 23, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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" };
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@@ -312,8 +312,7 @@ TEST(RegenerateCmakeAddTarget_Interface) {
};

const std::string expectedOutput(
"add_library(${PROJECT_NAME} INTERFACE\n"
" EXCLUDE_FROM_ALL\n"
"add_library(${PROJECT_NAME} EXCLUDE_FROM_ALL INTERFACE\n"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah... this is wrong. I want INTERFACE to come first as the defining type of the library.

Copy link
Member Author

@maikelvdh maikelvdh Oct 23, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you assert on the order?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will change this to evaluate that both arguments are in the set present.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants