GithubHelp home page GithubHelp logo

Comments (4)

marvinfriede avatar marvinfriede commented on July 30, 2024

I agree that this should be removed. However, I could not figure out, where this is even coming from. Do you have any idea?

I built the package with Intel OneAPI 2021.2 and the following meson setup command:

meson setup $build_dir --libdir=lib --prefix=$install_dir --buildtype=release --default-library=static -Dfortran_link_args="-static" -Dfortran_args="-Ofast -axAVX2 -mtune=core-avx2 -fma"

I am not setting any flags with environment variables.

from dftd4.

marvinfriede avatar marvinfriede commented on July 30, 2024

For now, I just manually updated the file in the current release.

from dftd4.

awvwgk avatar awvwgk commented on July 30, 2024

This originates from meson combining the dependencies for the final library, in the dependency tree we have OpenMP four times:

- dftd4 -- multicharge -- mctc-lib -- OpenMP
        \- OpenMP      \- OpenMP
        \- LAPACK      \- LAPACK
        \- mctc-lib -- OpenMP

Every dependency library exports its link flags to parent projects, however they don't get pruned in the final pkgconfig file. I would not consider this harmful, it would be more fatal if the pruning of additional flags would actually mess up the linking.

Not sure whether there is a way to change this easily with how meson generates the pkgconfig file.

from dftd4.

hongyi-zhao avatar hongyi-zhao commented on July 30, 2024

@awvwgk

Not sure whether there is a way to change this easily with how meson generates the pkgconfig file.

Perhaps the following can be used as a starting point.

Implementation for Solution 1: Use Meson's post-install hook or other build scripts

For this solution, you will use Meson's ability to define a custom target that runs after the build process completes. You'll create a Python script that will clean up the .pc file, and then call this script from Meson's custom_target.

Step 1: Create the Python Cleanup Script

First, create a Python script called cleanup_pc.py that removes duplicate flags in a .pc file. This script takes the path to the .pc file as its argument.

# cleanup_pc.py
import sys
import re

def remove_duplicate_flags(pc_file_path):
    with open(pc_file_path, 'r') as file:
        contents = file.read()

    # This regular expression finds duplicate -qopenmp flags
    contents = re.sub(r'(-qopenmp\s+)+', '-qopenmp ', contents)

    with open(pc_file_path, 'w') as file:
        file.write(contents)

if __name__ == '__main__':
    if len(sys.argv) != 2:
        print("Usage: python cleanup_pc.py <path-to-pc-file>")
        sys.exit(1)
    remove_duplicate_flags(sys.argv[1])

Step 2: Integrate the Script into the Meson Build Process

In the meson.build file, add a custom target that will run this script after the build process. Use Meson's find_program to locate the script and custom_target to execute it.

# meson.build
project('your_project', 'c',
        version : '0.1',
        default_options : ['warning_level=3', 'optimization=3'])

# Assuming your .pc file and cleanup script are in the project root
cleanup_script = find_program('cleanup_pc.py', required : true)

# Define a custom target that cleans up the .pc file
custom_target('cleanup-pc-flags',
              output : 'dftd4.pc',
              command : [cleanup_script, join_paths(meson.current_build_dir(), 'dftd4.pc')],
              build_by_default : true)

This snippet defines a custom target named cleanup-pc-flags that runs the cleanup script on the dftd4.pc file located in the build directory. Ensure that the script is in the root of your project or adjust the path accordingly.

Implementation for Solution 2: Correcting Meson Project Dependency Declarations

In this solution, you carefully review your Meson project files to adjust how dependencies are declared. The objective is to minimize unnecessary duplication of flags by better controlling dependency resolution.

Example Meson Build Adjustments

Assuming we're dealing with an OpenMP dependency that's repeatedly included, you might refine your meson.build like this:

# meson.build
project('your_project', 'c',
        version : '0.1',
        default_options : ['warning_level=3', 'optimization=3'])

# Assuming OpenMP is a repeated dependency:
openmp_dep = dependency('openmp', required : false)
if not openmp_dep.found()
    # A fallback option: bundle the dependency or use a substitute
    openmp_dep = dependency('my_openmp_substitute', required : true, fallback : ['my_subproject', 'my_openmp_sub_dep'])
endif

executable('project_executable', 'main.c', dependencies : [openmp_dep])

This approach first attempts to find OpenMP using Meson's dependency() function. If the dependency is not found (perhaps it's optional or not available on all target environments), you can provide a fallback mechanism—either another subproject within your code base or a different but compatible library.

Using the fallback feature like this helps Meson make more intelligent decisions about when and how to include dependencies, potentially reducing the duplication of linker flags in generated .pc files.

from dftd4.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.