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

support C&Fortran packages on windows via utils.platform.gnu2mslib #1313

Closed
xq114 opened this issue Apr 2, 2021 · 2 comments
Closed

support C&Fortran packages on windows via utils.platform.gnu2mslib #1313

xq114 opened this issue Apr 2, 2021 · 2 comments

Comments

@xq114
Copy link
Contributor

xq114 commented Apr 2, 2021

你在什么场景下需要该功能?

一些数值计算库由于使用了fortran,无法仅用msvc编译,需要在mingw环境下编译成动态库然后转换成msvc格式

描述可能的解决方案

if is_plat("windows") then
	add_deps("mingw-w64")
end
on_install("mingw", ...)
on_install("windows", function (package)
	invoke_mingw_install_shared()
end)

作用是先用mingw安装,指定shared,然后自动把links对应的库文件.dll.a转成.lib

其他信息

也可用intel的ifort编译,不过ifort是intel的私有软件,需要用户自己安装,相对较难集成

@waruqi
Copy link
Member

waruqi commented Apr 2, 2021

目前还不支持 on_install 内部切换到其他工具链来编译,这块搞起来比较花时间,这个版本不一定有时间搞,先放着吧。。到时候看情况。

related issues: #1181

@waruqi waruqi modified the milestones: todo, v2.5.4 Apr 3, 2021
@waruqi
Copy link
Member

waruqi commented Apr 19, 2021

我改进了下,增加了对 add_requires("xxx", {private = true}) 设置为私有包,对于 add_deps/add_requires 仅提供安装,不导出links/envs 给 target

然后,可以在 xxx/windows 包中 通过 package:add("deps", "xxx", {plat = "mingw", private = true}) ,额外关联一个自身的 mingw 平台包依赖(只要平台不一样,就不会死递归),.仅用于提供 windows 平台进一步安装。

    on_load("windows", function (package)
        package:add("deps", "libogg", {plat = "mingw", private = true}) -- 注:目前不支持 add_deps/is_plat,因为 is_plat 取不到 package:plat信息,容易死递归。
    end)

    on_install("mingw", function (package)
        local configs = {"-DBUILD_TESTING=OFF"}
        table.insert(configs, "-DCMAKE_BUILD_TYPE=" .. (package:debug() and "Debug" or "Release"))
        table.insert(configs, "-DBUILD_SHARED_LIBS=" .. (package:config("shared") and "ON" or "OFF"))
        table.insert(configs, "-DCMAKE_POSITION_INDEPENDENT_CODE=ON")
        import("package.tools.cmake").install(package, configs)
    end)

    -- 这里只是 examples,随手写的,不一定直接 work,需要自己调整下,但大体逻辑可以参考下。。
    on_install("windows", function (package)
        local ogg_mingw = package:dep("libogg")
        local fetchinfo = ogg_mingw:fetch()
        if fetchinfo then
            import("utils.platform.gnu2mslib")
            for _, libfile in ipairs(fetchinfo.libfiles) do
                local mslib = path.join(package:installdir("lib"), path.basename(libfile) .. ".lib")
                gnu2mslib(mslib, libfile)
            end
            os.cp(ogg_mingw:installdir("include"), package:installdir())
        end
    end)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants