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

.mod files not found during (cmake) compilation #85

Open
scarpma opened this issue Feb 6, 2023 · 4 comments
Open

.mod files not found during (cmake) compilation #85

scarpma opened this issue Feb 6, 2023 · 4 comments

Comments

@scarpma
Copy link

scarpma commented Feb 6, 2023

Hello, I have never used cmake, so I have (I think) a very dumb question.

I'm trying to compile with cmake, so I followed the readme and started the compilation with make. The problem is that after few instant the compilation stops with an error since it cannot find the .mod files (that are inside the lib directory).

Is there something that is not written in the readme that I should do ? It seems that the makefile doesn't know where to look for .mod files.

Thanks in advance !

@bilderbuchi
Copy link

It seems I'm having the same problem, I'm getting "Fatal Error: Cannot open module file 'bspline_module.mod' for reading at (1): No such file or directory" (at use bspline_module) when building the bspline_test module. (I'm trying to use bspline-fortran within another CMake-based Fortran project)

@bilderbuchi
Copy link

So, it seems that we need to make sure that, in addition to the library, we need to make sure that all targets find the module files in the (non-default) lib folder: https://stackoverflow.com/a/43918277/599884.

In my case, after

target_link_libraries(${prog_name} ${LIB_NAME}-static)
adding the line

    target_include_directories(${prog_name} PUBLIC $<TARGET_PROPERTY:${LIB_NAME}-static,Fortran_MODULE_DIRECTORY>)

fixes the problem at least for the test executables.
I'm not sure if that is not papering over a deeper issue, though. @jacobwilliams, @Gjacquenot, any idea ?

@jacobwilliams
Copy link
Owner

I'm not a CMake expert so I'm not sure what the proper solution is. If this works, I can merge it in.

See also: #31

@bilderbuchi
Copy link

bilderbuchi commented Jan 24, 2024

I think this is a better patch, inspired by CMake issues and jacobwilliams/json-fortran@d8dc940:

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 7754d07..20aba1c 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -73,6 +73,11 @@ endif()
 add_library( ${LIB_NAME}        SHARED ${SOURCES} )
 add_library( ${LIB_NAME}-static STATIC ${SOURCES} )
 
+# Make sure modules for the static library can be found by depending targets
+# put together from hints in https://gitlab.kitware.com/cmake/cmake/-/issues/24223
+# and https://gitlab.kitware.com/cmake/cmake/-/issues/25425
+target_include_directories(${LIB_NAME}-static PUBLIC $<BUILD_INTERFACE:${MODULE_DIR}>)
+
 set_target_properties(${LIB_NAME}-static
   PROPERTIES
   OUTPUT_NAME "${LIB_NAME}"

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

No branches or pull requests

3 participants