4
\$\begingroup\$

I am trying to write a premake4.lua file that builds and links to static libraries using premake.

  • library mbm was originally designed to be built using cmake. So to go around this issue I call ./configure then I build it using premake4 gmake.

  • library jansson was originally designed to be built using cmake. But calling ./configure was not enough to build it, since cmake was also generating jansson_config.h that is needed for the build. So I ended up calling premake with prebuildcommands to build jansson using cmake first.

I don't think the way I built jansson is nice at all. Any idea how I can make this better?

premake.lua:

local homepath = os.getenv("HOME")

newoption {
   trigger     = "create-static-libs",
   description = "Creates all the necessary dependencies to build the ProjectA"
}

solution "ProjectA"
  configurations { "Debug", "Release"}

  configuration { "Debug" }
    objdir "../build/debug"
    targetdir "../install/bin/debug"

  configuration { "Release" }
    objdir "../build/release"
    targetdir "../install/bin/release"


  if _ACTION == "clean" then
    os.rmdir("../install")
    os.rmdir("../build")
  end

  project "mbm"
    kind "StaticLib"
    language "C"
    includedirs { "mbm/" }
    files{ "mbm/src/**.h","mbm/src/**.c"}

    configuration { "create-static-libs" }
      prebuildcommands { "cd mbm; ./configure; cd -; rm -rf config.log" }


  project "ProjectA"
    kind "ConsoleApp"
    language "C++"
    links {"mbm", "jansson"}
    includedirs { "include/**", "mbm/**", "jansson-2.7/**" }
    files { "bin/**.h", "bin/**.cpp" }

    configuration { "Debug*" }
      libdirs { "../install/bin/debug/" }
      defines { "_DEBUG", "DEBUG" }
      flags   { "Symbols" }

      if _OPTIONS[ "create-static-libs" ] then
        prebuildcommands { "cd jansson-2.7;./configure --prefix=".. homepath .."/eclipse_workspace/ProjectA/build/jansson --disable-shared;make config=debug;make install;cd -" }
        prebuildcommands { "mkdir -p ../install/bin/debug; mv ../build/jansson/lib/libjansson.a ../install/bin/debug/" }
      end

    configuration { "Release*" }
      libdirs { "../install/bin/release/" }
      defines { "NDEBUG" }
      flags   { "Optimize" }

      if _OPTIONS[ "create-static-libs" ] then
        prebuildcommands { "cd jansson-2.7;./configure --prefix=".. homepath .."/eclipse_workspace/ProjectA/build/jansson --disable-shared;make config=release;make install;cd -" }
        prebuildcommands { "mkdir -p ../install/bin/release; mv ../build/jansson/lib/libjansson.a ../install/bin/release/" }
      end
\$\endgroup\$
  • \$\begingroup\$ Which tag(s) do you need? \$\endgroup\$ – Jamal Nov 14 '14 at 2:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.