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.
Add quotation for paths with spaces
There was a problem hiding this comment.
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.
What do you meen here? Currently all modules from fdict is exposed?
There was a problem hiding this comment.
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.
| ) | ||
|
|
||
| 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.
add quotation, to ensure paths with spaces
There was a problem hiding this comment.
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.
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.
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>
|
zerothi
left a comment
There was a problem hiding this comment.
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_DIRECTORYinstead of setting the specific target property. This makes it consistent with downstream user's configurationtarget_include_directoriesshould bePUBLIC, notINTERFACEthere. I.e. the library should be using it as well. This is a compiler dependent behaviour because some might be automatically be usingFortran_MODULE_DIRECTORor 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