-
Notifications
You must be signed in to change notification settings - Fork 17
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: Partial fix for FetchContent #36
Conversation
Signed-off-by: Cristian Le <cristian.le@mpsd.mpg.de>
- Move `Fortran_MODULE_DIRECTORY` to global `CMAKE_Fortran_MODULE_DIRECTORY` option - Fix wrong usage of quotes in generator expression Signed-off-by: Cristian Le <cristian.le@mpsd.mpg.de>
# This is to avoid name-clashing (similar to how C projects structure their include) | ||
install(FILES | ||
${CMAKE_Fortran_MODULE_DIRECTORY}/dictionary.mod | ||
${CMAKE_Fortran_MODULE_DIRECTORY}/variable.mod |
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.
Add quotation for paths with spaces
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.
See earlier disccussion
) | ||
|
||
# Install all modules (omitting the directory) | ||
install(DIRECTORY "${LIB_MOD_DIR}/" DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}") | ||
# TODO: Move to single module interface and move the other modules to subfolder | ||
# This is to avoid name-clashing (similar to how C projects structure their include) |
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.
What do you meen here? Currently all modules from fdict is exposed?
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.
The convention in C/C++ projects is to install only 1 header file per project with a unique name. In cases where multiple header files are needed (header only libraries for example), than all the header files are in a subdirectory with the unique name of the project. Otherwise when you install another project that has similar header file names, they will overwrite each other and become unusable.
Same convention applies here. There is a potential of overlap with another project that uses variable.mod
for example. In this case, simply add both ${CMAKE_Fortran_MODULE_DIRECTORY}
and ${CMAKE_Fortran_MODULE_DIRECTORY}/fdict
to the target_include_directories()
, then depending on which target_link_libraries
, the appropriate modules are used.
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.
Ah, I see.
@@ -9,6 +9,10 @@ project(fdict | |||
DESCRIPTION "Fortran dictionary for arbitrary data-types" | |||
) | |||
|
|||
if (NOT DEFINED CMAKE_Fortran_MODULE_DIRECTORY) | |||
set(CMAKE_Fortran_MODULE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/fortran_modules) |
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.
add quotation, to ensure paths with spaces
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 have tested locally and the quotation does not appear to be necessary. In general I would avoid quotations where unnecessary (in this case the variable CMAKE_CURRENT_BINARY_DIR
is already sanitized to be a string) because sometimes the quotations are taken to be literal (as you've seen here in the generator expression). My rule of thumb is to sanitize everything at the set()
, option()
level rather than where the variables are used.
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 see, this is something where CMake is horrible, it is hard to know why some of the expansions works seamlessly, and others are problematic... Hence my guarding was just to put quotation everywhere.
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 fully agree. This is a relic of the original cmake design, and although there are rumors that the lead devs are working on a more robust, non text-based interface for camke 4, these are here to stay :(.
I was doing the same thing until I had various things break down because of the quotation. I realized though that most cmake commands are designed to work on variables (e.g. the if()
command), so I work on the assumption that most commands are designed and tested to work for unquoted formats, and just use the quotation when it is needed to enforce it.
Thanks for your PR! Some minor details |
Signed-off-by: Cristian Le <cristian.le@mpsd.mpg.de>
|
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'll fix the remaining issues.
Don't add the And why is the |
Hmm good point. But the version tells you about the release intent with e.g. major change telling you that api has breaking changes. Git hashes are only for development, but I can see why that can be useful. How about exporting that information manually. It is highly advised to use (Btw I have a cmake project to get and set the project version directly from git/git archive, compatible with python's setuptools_scm setup files)
That ony controls the cmake |
Partial fix for FetchContent issue regarding:
Issue is that generator expression should not have quotation marks there. A few other issues here are:
CMake_Fortran_MODULE_DIRECTORY
instead of setting the specific target property. This makes it consistent with downstream user's configurationtarget_include_directories
should bePUBLIC
, notINTERFACE
there. I.e. the library should be using it as well. This is a compiler dependent behaviour because some might be automatically be usingFortran_MODULE_DIRECTOR
or not, and this addresses the issue of the latterNote on the "partial" fix. This is because the install interface is not fixed yet according to #32