urbanjost / M_CLI2

Fortran commandline-interface using a simple prototype command
The Unlicense
20 stars 4 forks source link

meson.build doesn't install m_cli2.mod file #17

Open band-a-prend opened 1 year ago

band-a-prend commented 1 year ago

The meson.build succsesfully build m_cli2 library and install it with appropriate symlinks but there is no rule to install m_cli2.mod file that is required as header to use the dynamic library.

zoziha commented 1 year ago

This does exist, and is an unfulfilled issue for meson, see https://github.com/mesonbuild/meson/issues/5374. The options are to follow this scheme suggested and this meson.build, or just move the *.mod files manually.

band-a-prend commented 1 year ago

I could try to implement rule using install_subdir function and then prepare pull request. I hope I will do it this weekend.

band-a-prend commented 1 year ago

Well, I prepared the patch but it seems it requires to be discussed:

diff --git a/meson.build b/meson.build
index f896dd7..a2be0c1 100644
--- a/meson.build
+++ b/meson.build
@@ -25,6 +25,11 @@ M_CLI2_dep = declare_dependency(
     include_directories : M_CLI2_inc,
 )

+install_subdir(meson.current_build_dir()/'lib'+meson.project_name()+'.so.'+meson.project_version()+'.p',
+    install_dir : 'include/m_cli2',
+    strip_directory : true,
+    exclude_files : ['M_CLI2-deps.json', 'M_CLI2.dat', 'depscan.dd', 'libM_CLI2.so.3.2.0.symbols', 'src_M_CLI2.F90.o'])
+
 test(
     'runTests',
     executable(
  1. I'm newbie with meson build system and didn't find more adequate way to set object build directory so currently it looks like that.
  2. Please notice that I have to use lowercase for module install path due to features of fpm: the M_CLI2 provides m_cli2.mod (actually gfortran generates module files always in lowecase, see https://gcc.gnu.org/bugzilla/show_bug.cgi?id=42607#c13) and if I package fpm for my system package manager then I need to use rule like
[build]
external-modules = ["tomlf", "m_cli2"]
link = ["toml-f","M_CLI2"]

to look for /usr/include/m_cli2/m_cli2.mod and libM_CLI2.so. If I will use external-modules = ["tomlf", "M_CLI2"] rule then fpm will try to find /usr/include/M_CLI2/M_CLI2.mod instead of /usr/include/M_CLI2/m_cli2.mod.

  1. I tested M_CLI2 build and instalation with commands:
    meson setup --prefix /usr builddir && cd builddir
    meson compile
    DESTDIR=../my_dir meson install

    The content of my_dir

before patch:

└── usr
    └── lib64
        ├── libM_CLI2.so -> libM_CLI2.so.3
        ├── libM_CLI2.so.3 -> libM_CLI2.so.3.2.0
        └── libM_CLI2.so.3.2.0

after:

└── usr
    ├── include
    │   └── m_cli2
    │       └── m_cli2.mod
    └── lib64
        ├── libM_CLI2.so -> libM_CLI2.so.3
        ├── libM_CLI2.so.3 -> libM_CLI2.so.3.2.0
        └── libM_CLI2.so.3.2.0
zoziha commented 1 year ago

For Windows compatibility and inspired by you, the following meson.build diff works in Windows-MSYS2, considering that the dynamic link library suffix is .dll under Windows. I will verify it later on a Linux machine (It works in both ifort and gfortran environments!).

diff --git a/meson.build b/meson.build
index f896dd7..260e1df 100644
--- a/meson.build
+++ b/meson.build
@@ -5,6 +5,8 @@ project(
     license : 'UNLICENSE',
     default_options : [
         'buildtype=debugoptimized',
+        'fortran_std=f2008',
+        'default_library=both',
     ]
 )

@@ -33,3 +35,39 @@ test(
         dependencies : M_CLI2_dep,
     ),
 )
+
+M_CLI2_lic = files(
+    'LICENSE',
+)
+install_data(
+    M_CLI2_lic,
+    install_dir : join_paths(get_option('prefix'), 'share', 'licenses', meson.project_name()),
+)
+
+if host_machine.system() == 'windows'
+    symbols_file = 'lib'+meson.project_name()+'-'+meson.project_version().split('.')[0]+'.dll.symbols'
+    obj_file = 'src_M_CLI2.F90.obj'
+else
+    symbols_file = 'lib'+meson.project_name()+'.so.'+meson.project_version()+'.symbols'
+    obj_file = 'src_M_CLI2.F90.o'
+endif
+install_subdir(M_CLI2_lib.path()+'.p',
+    install_dir: 'include'/meson.project_name(),
+    strip_directory: true,
+    exclude_files: [
+        'depscan.dd',
+        meson.project_name()+'-deps.json',
+        meson.project_name()+'.dat',
+        symbols_file,
+        obj_file,
+    ]
+)
+
+pkg = import('pkgconfig')
+pkg.generate(
+    name : meson.project_name(),
+    description : 'Fortran commandline-interface using a simple prototype command',
+    version : meson.project_version(),
+    libraries : M_CLI2_lib,
+    subdirs : meson.project_name(),
+)
> meson install --destdir tmp -C _build
ninja: Entering directory `C:\Users\zoziha\Code\opensource\M_CLI2\_build'
ninja: no work to do.
Installing subdir C:\Users\zoziha\Code\opensource\M_CLI2\_build\libM_CLI2-3.dll.p to C:\Users\zoziha\Code\opensource\M_CLI2\_build\tmp\include\M_CLI2
Installing C:\Users\zoziha\Code\opensource\M_CLI2\_build\libM_CLI2-3.dll.p\m_cli2.mod to C:\Users\zoziha\Code\opensource\M_CLI2\_build\tmp\include\M_CLI2
Installing libM_CLI2-3.dll to C:\Users\zoziha\Code\opensource\M_CLI2\_build\tmp\bin
Installing libM_CLI2.dll.a to C:\Users\zoziha\Code\opensource\M_CLI2\_build\tmp\lib
Installing libM_CLI2.a to C:\Users\zoziha\Code\opensource\M_CLI2\_build\tmp\lib
Installing C:\Users\zoziha\Code\opensource\M_CLI2\LICENSE to C:\Users\zoziha\Code\opensource\M_CLI2\_build\tmp\share\licenses\M_CLI2
Installing C:\Users\zoziha\Code\opensource\M_CLI2\_build\meson-private\M_CLI2.pc to C:\Users\zoziha\Code\opensource\M_CLI2\_build\tmp\lib\pkgconfig
band-a-prend commented 1 year ago

Great!

install_dir: 'include'/meson.project_name()

As I mentioned above I have problem with uppercase in path and lowercase for .mod file if build fpm with M_CLI2 as external library instead of builtin subproject. But I could handle this case localy and install .mod file into include/m_cli2 instead and also need to investigate this fpm problem in my system more detailed. It seems make include path lowercase.

So uppercased include subdirectory is expected if project name is uppercased.

zoziha commented 1 year ago

fpm is currently in alpha phase, and it is better to use fpm dependencies in fpm projects. If your project is small, you can use fpm(0.8.0) as a build tool at this stage. If your project becomes complex, has many local and remote dependencies, and has many source files, at this stage, meson(1.1.0) or cmake(3.25.2) is good enough. This is my advice from experience.

band-a-prend commented 1 year ago

It's my fault - I forget that fpm requires to pass include path as part of command line separately of fmp-toml options and didn't replace it with new path.