内容纲要

premake5 生成的预编译头,声明的先后顺序有差别,且对单个文件不启用预编译头时未实现。把 premake5 从 github 上 clone 下来修改,重新编译。

git clone https://github.com/premake/premake-core.git
git submodule init
git submodule update

更新完后先用之前的 premake5.exe 生成工程

cd premake-core
premake5 vs2015

修改 premake-core\src\actions\vstudio\vs200x_vcproj.lua 的 function m.usePrecompiledHeader(cfg) 函数

    function m.usePrecompiledHeader(cfg)
        local prj, file = config.normalize(cfg)        
        if file then            
            if prj.pchsource == file.abspath and
               not prj.flags.NoPCH and
               prj.system == p.WINDOWS
            then
                p.w('UsePrecompiledHeader="1"')
            elseif file.flags.NoPCH then
                p.w('UsePrecompiledHeader="0"')
            end            
        else
            
            if not prj.flags.NoPCH and prj.pchheader then
                p.w('UsePrecompiledHeader="%s"', iif(_ACTION < "vs2005", 3, 2))
                p.x('PrecompiledHeaderThrough="%s"', prj.pchheader)
            else
                p.w('UsePrecompiledHeader="%s"', iif(_ACTION > "vs2003" or prj.flags.NoPCH, 0, 2))
            end
        end
    end

重新生成嵌入脚本

premake5 embed

打开 vs2015 重新编译 premake5.

使用例子

premake5.lua 工程模板,拿 duilib 做个例子

workspace "premake5-test"
    language "C++"
    location "build"
    targetdir "bin"

    configurations { "Debug", "Release" }
    platforms { "Win32", "Win64" }

    filter { "platforms:Win32" }
        system "Windows"
        architecture "x32"
    
    filter { "platforms:Win64" }
        system "Windows"
        architecture "x64"    

    filter "configurations:Debug"
        defines { "DEBUG" }
        flags { "Symbols" }

    filter "configurations:Release"
        defines { "NDEBUG" }
        flags { "Symbols" }
        optimize "On"    

    configuration "vs*"
        defines
        {
            "WIN32",
            -- "WIN32_LEAN_AND_MEAN",
            -- "_WIN32_WINNT=0x0600",
            "_CRT_SECURE_NO_WARNINGS",        
            "_CRT_SECURE_NO_DEPRECATE",
            "_SCL_SECURE_NO_WARNINGS",
            "STRSAFE_NO_DEPRECATE",
            "_CRT_NON_CONFORMING_SWPRINTFS"
        }
   
    group "3rdparty"

        project "duilib"
            location "build"
            kind "SharedLib"            
            defines { "_WINDOWS", "UILIB_EXPORTS" }               
            flags { "NoManifest" }
            targetdir "bin/lib"               
            files
            {
                "3rdparty/DuiLib/**.h",
                "3rdparty/DuiLib/**.cpp",  
                "3rdparty/DuiLib/**.c"
            }            
            removefiles
            {
                 
            }           
            includedirs
            {          
                "3rdparty/DuiLib",
                "3rdparty"    
            }            
            links
            {
                
            }
            libdirs
            {
                "bin/lib"                
            }
            pchsource "3rdparty/DuiLib/StdAfx.cpp"
            pchheader "StdAfx.h"
            filter "files:**.c"
                flags { "NoPCH" }
            filter "files:3rdparty/DuiLib/Utils/XUnzip.cpp"
                flags { "NoPCH" }

一定要将 filter 过滤器声明在工程最后,不然 include 和 lib 的引用目录会生成不了。

编译过的文件下载
http://pan.baidu.com/s/1nvbApFr

发表评论

电子邮件地址不会被公开。 必填项已用*标注