-
-
Notifications
You must be signed in to change notification settings - Fork 108
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
Make corrosion_install
install header files and export configurations
#544
Conversation
I'm extending this PR with functionality for The current implementation creates a file at There's still an awful lot of boilerplate, but almost all of it is just the "normal" amount of pointless CMake configuration. I'm creating the Sadly, because we need the base path of the install prefix in the I have tested this with both static and shared libraries using the https://github.com/gtker/corrosion_export/ repo. With this PR the planned functionality of |
corrosion_install
install header filescorrosion_install
install header files and export configurations
I completely forgot Windows IMPLIB support. If |
Haven't reviewed yet, but one short comment / question
I'm not sure I understood what you mean, but did you try specifying the target directory with a trailing slash?
Source: install(DIRECTORY) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I left some comments inline
This currently installs all PUBLIC/INTERFACE file sets for a target, should it do that, or only the HEADERS file set?
is there a need to install all file sets by default? I would start with HEADERS
only first, unless there is a reason to install more by default.
doc/src/quick_start.md
Outdated
corrosion_install(TARGETS rust-lib) | ||
# Add a manually written header file which will be exported | ||
# Requires CMake >=3.23 | ||
target_sources(rust-lib INTERFACE |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's add this example code as part of a test, and include it via the anchor
feature of the book.
I just added a first test project which installs a Rust executable to test/corrosion_install/install_rust_bin/rust_bin
Could you perhaps add a demo project which installs a shared library / headers? If can help with integrating it into the testing system.
I considered doing this like this, but we need to allow generator expressions, so it won't be a simple append-
I don't see it as completely necessary, but there had to be some default behavior so I just chose to install everything. I'll make it only install the I don't have a lot of time right now, but I'll reply to your other comments later and make the changes. I also tested it out on Windows, and I don't believe the IMPLIB is installed correctly with |
Still working on remaining change requests, just wanted to update. |
I fixed all issues, except creating a test. As far as I can see there's already a test for libraries in |
I probably don't have the time to review today, but perhaps you could edit the test, so that the shared library has an associated header that also needs to be installed. (
|
I added the header file, but I really can't penetrate the meta levels of CMake script that the tests are made of. It might have been easier with python scripts that just called the cmake executable. :) |
The test failures do not appear to be mine. :) |
Sorry for the delay, busy two weeks. I'll try to get to this MR over the weekend |
Supports directories added with `target_include_directories` like normal. There is a slight oddity. Because of how install(DIRECTORY) works, we can't put the include directory inside `${CMAKE_INSTALL_PREFIX}/include`, since that would create `${CMAKE_INSTALL_PREFIX}/include/<include dir name>`. Instead we copy directly to the CMAKE_INSTALL_PREFIX, and then use whatever name the include directory had (hopefully just `include`). This means that when installing the path to include files will be -- Installing: /tmp/install/./include -- Installing: /tmp/install/./include/is_odd -- Installing: /tmp/install/./include/is_odd/is_odd.h Instead of just -- Installing: /tmp/install/include -- Installing: /tmp/install/include/is_odd -- Installing: /tmp/install/include/is_odd/is_odd.h
This adds better `install` integration for targets with headers defined through target_sources. The PUBLIC_HEADER option can now be used to change the DIRECTORY.
This does an install(TARGETS EXPORT) and creates a file at ${CMAKE_BINARY_DIR}/corrosion/<export-name>TargetsCorrosion.cmake that contains the *-static and *-shared targets used by the main target. The examples use RustLib instead of ${PROJECT_NAME} for visual clarity.
Co-authored-by: Jonathan Schwender <[email protected]>
This is not actually part of the test.
c386cba
to
849474c
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can land this as is for now, and iterate over it in case any problems surface.
Thanks a lot for looking into this.
Cool. Let me know if any problems surface with |
This PR makes
corrosion_install
also install header files attached to the Rust target. It works both for files that are added throughtarget_include_directories
and throughtarget_sources
file sets for 3.23+.Progresses #415, #63, #64, and #117.
I believe that this will also solve #261 since the headers are added through
target_include_directories
andtarget_sources
for 3.23+, although I'm not sure how to setup cxxbridge so I can't test it.This also correctly installs headers added through
corrosion_experimental_cbindgen
, although I had errors relating tocbindgen
not running when testing it. If the files are generated in the correct location they will be installed.This uses commits from #543, but since it has been approved and is just waiting for a CI run before merging I assumed it was OK to put this up.
Adding header files the old way:
will lead to
while using file sets:
will lead to
The distinction between file sets and include directories is in preparation for
EXPORT
functionality.Caveat
For include directories added through
target_include_directories
thePUBLIC_HEADER DESTINATION
argument does not determine the install location, but the name of the include directory does.So for
target_include_directories(my-lib INTERFACE wacky-files)
andcorrosion_install(TARGETS my-lib PUBLIC_HEADER includerinos)
the file would go into./wacky-files
rather than./includerinos
.This is because CMake doesn't seem to offer any real way of installing entire directories without doubling nesting them, and we can't
file(GLOB)
through the directories to find files/directories since they can be generator expressions (and must be in order to be relocatable).From what I can tell just CMake doesn't have a good way of installing header files if you're not using 3.23+.
3.23+ file sets work completely fine.
Open questions
PUBLIC
/INTERFACE
file sets for a target, should it do that, or only theHEADERS
file set?PUBLIC_HEADER DESTINATION
not working fortarget_include_directories
too confusing for it to be included? Or should we find another way. I don't have a clue how that would be done, but I'm open to suggestions.