Skip to content
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

Fix output_directory support when not used as target property #268

Merged
merged 1 commit into from
Nov 25, 2022
Merged

Fix output_directory support when not used as target property #268

merged 1 commit into from
Nov 25, 2022

Conversation

tronical
Copy link
Contributor

In CMake, for example RUNTIME_OUTPUT_DIRECTORY is a target property. It is documented to be initialized from CMAKE_RUNTIME_OUTPUT_DIRECTORY, so it's not unusual for CMake projects to just set the latter variable in order to place all affected targets into the directory, instead of setting a per-target property on each manually.

Since Corrosion respects the target property, it makes sense to assume that just setting the CMAKE_ variable would also work. Oddly, the get_property returns -NOTFOUND when only the CMAKE_ variable is set and not the target property. To "work around" that, this patch implements the fallback manually.

@tronical
Copy link
Contributor Author

I need some advice on how to best add test coverage for this. test/output directory/output directory/CMakeLists.txt tests the target properties, but I'd rather not duplicate the whole test. Should I duplicate the series in test/output directory/CMakeLists.txt perhaps and add an option for test/output directory/output directory/CMakeLists.txt to select whether to set the target property or the global variable?

@jschwe
Copy link
Collaborator

jschwe commented Nov 23, 2022

it makes sense to assume that just setting the CMAKE_ variable would also work. Oddly, the get_property returns -NOTFOUND when only the CMAKE_ variable is set and not the target property.

I guess CMake doesn't set this property on IMPORTED or INTERFACE targets. I'm not sure why I didn't notice this earlier. Thanks for reporting this!

Instead of complicating the checking part like this PR proposes, I would prefer if Corrosion would initialize the properties as CMake would do.

Since respecting OUTPUT_DIRECTORY anyway requires CMake 3.19, I would suggest editing _generator_add_cargo_targets() in CorrosionGenerator.cmake and add a loop at the end of the function that iterates over created_targets and sets the 5 properties if the relevant CMAKE_ variable is defined. Should be very simple to do.

This approach has the advantage of working as expected if (for some reason) a user has two or more corrosion_import_crate calls in the same CMakeLists.txt file and changes the CMAKE_ values in between the calls.

Should I duplicate the series in test/output directory/CMakeLists.txt perhaps

Yes, please

and add an option for test/output directory/output directory/CMakeLists.txt to select whether to set the target property or the global variable?

Thats one option. We could also just duplicate the rust package (and have a CMake test project with 2 corrosion_import_crate calls). In my opinion, less logic in output directory/output directory is preferable.

@tronical
Copy link
Contributor Author

Thank you for the explanation. The observed behavior makes sense now and I agree about the way of fixing it. I'll look into that.

@tronical
Copy link
Contributor Author

I've implemented this now, and it seems to work to some extent. Local on macOS with ninja, I'm having the issue that mysteriously CMAKE_ARCHIVE_OUTPUT_DIRECTORY isn't respected for the static lib test.

@tronical
Copy link
Contributor Author

Lol, shortly after posting the comment I found the issue. So it's passing locally now.

@tronical
Copy link
Contributor Author

I guess the remaining failures are due to lack of support for CMAKE_CONFIGURATION_TYPES. I'll look into that tomorrow.

cmake/CorrosionGenerator.cmake Outdated Show resolved Hide resolved
test/output directory/output directory/CMakeLists.txt Outdated Show resolved Hide resolved
cmake/CorrosionGenerator.cmake Show resolved Hide resolved
@tronical
Copy link
Contributor Author

Ok, at least the CI is green now :-).

Copy link
Collaborator

@jschwe jschwe left a comment

Choose a reason for hiding this comment

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

Looks good now. Thanks for fixing this!
You mentioned you wanted to squash, so I'll wait for that before merging.

In CMake, for example RUNTIME_OUTPUT_DIRECTORY is a target property. It
is documented to be initialized from CMAKE_RUNTIME_OUTPUT_DIRECTORY, so
it's not unusual for CMake projects to just set the latter variable in
order to place all affected targets into the directory, instead of
setting a per-target property on each manually.

Since Corrosion respects the target property, it makes sense to assume
that just setting the CMAKE_ variable would also work.
@tronical
Copy link
Contributor Author

Done :)

@tronical
Copy link
Contributor Author

Hm, for some reason GitHub isn't show that force push.

@jschwe jschwe merged commit 7426f4a into corrosion-rs:master Nov 25, 2022
@tronical tronical deleted the simon/fix-output-directory-fallback branch November 25, 2022 15:46
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.

2 participants