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

Compiling with different location of dependencies in the system (e.g. OSX) #7

Open
an0nym05 opened this issue Jul 24, 2024 · 2 comments

Comments

@an0nym05
Copy link

I've realized expected configuration doesn't work in some cases (e.g. on OSX with brew):

{port_env, [{"CFLAGS", "$CFLAGS -I/usr/local/include -I./include -g -Wall -Werror"},
            {"LDFLAGS", "$LDFLAGS -L/usr/local/lib -lzmq"}]}.

Do you think it would be more flexible to rely on the output of pkg-config for compiler/linker flags?
The current workaround for Elixir project I did as below (works in my library, and in an app that depends on my library that uses erlzmq):

  defp deps do
    [
      ...
      {:erlzmq,
       git: "https://github.com/lukaszsamson/erlzmq",
       tag: "v4.1.4",
       system_env: erlzmq_system_env()},
       ...
    ]
  end

  defp erlzmq_system_env() do
    {:ok, pid} = StringIO.open("")

    Mix.Shell.cmd("pkg-config --cflags libzmq", [], fn output ->
      IO.write(pid, String.replace(output, "\n", ""))
    end)

    cflags = StringIO.flush(pid)

    Mix.Shell.cmd("pkg-config --libs libzmq", [], fn output ->
      IO.write(pid, String.replace(output, "\n", ""))
    end)

    {:ok, {_, ldflags}} = StringIO.close(pid)

    [
      {"CFLAGS", cflags},
      {"LDFLAGS", ldflags}
    ]
  end
@lukaszsamson
Copy link
Owner

I'm sure there are better ways. The current state comes from the original project with minor changes for BSD compatibility (https://github.com/lukaszsamson/erlzmq/pull/5/files). Would you mind creating a PR?

@an0nym05
Copy link
Author

Sure, will prepare one today.

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

2 participants