diff --git a/premake4.lua b/premake4.lua index 833a0ab26..843834d28 100644 --- a/premake4.lua +++ b/premake4.lua @@ -1,8 +1,26 @@ +newoption { trigger = "with-libsndfile", description = "Build with libsndfile support." } +newoption { trigger = "with-static-freetype", description = "Build freetype as a static library." } +newoption { trigger = "with-eepp-static", description = "Force to build the demos and tests with eepp compiled statically" } +newoption { trigger = "with-static-backend", description = "It will try to compile the library with a static backend (only for gcc and mingw).\n\t\t\t\tThe backend should be placed in libs/your_platform/libYourBackend.a" } +newoption { + trigger = "with-backend", + description = "Select the backend to use for window and input handling.\n\t\t\tIf no backend is selected or if the selected is not installed the script will search for a backend present in the system, and will use it.\n\t\t\tIt's possible to build with more than one backend support.\n\t\t\t\tUse comma to separate the backends to build ( you can't mix SDL and SDL2, you'll get random crashes ).\n\t\t\t\tExample: --with-backend=SDL2,SFML2", + allowed = { + { "SDL", "SDL 1.2" }, + { "SDL2", "SDL2 (default and recommended)" }, + { "allegro5", "Allegro 5" }, + { "SFML", "SFML2 ( SFML 1.6 not supported )" } + } +} + link_list = { } os_links = { } +backends = { } +static_backends = { } +backend_selected = false -function args_contains( element ) - for _, value in pairs(_ARGS) do +function table_contains( tb, element ) + for _, value in pairs( tb ) do if value == element then return true end @@ -10,6 +28,10 @@ function args_contains( element ) return false end +function args_contains( element ) + return table_contains( _ARGS, element ) +end + function print_table( table_ref ) for _, value in pairs( table_ref ) do print(value) @@ -38,7 +60,6 @@ function build_base_configuration( package_name ) targetname ( package_name ) end - function build_base_cpp_configuration( package_name ) configuration "debug" defines { "DEBUG" } @@ -53,18 +74,20 @@ function build_base_cpp_configuration( package_name ) targetname ( package_name ) end - function build_link_configuration( package_name ) links { link_list } if package_name ~= "eepp" and package_name ~= "eepp-static" then - links { "eepp-shared" } + if not _OPTIONS["with-eepp-static"] then + links { "eepp-shared" } + else + links { "eepp-static" } + add_static_links() + end if os.is("windows") then linkoptions { "-mwindows" } end - - --add_static_links() end configuration "debug" @@ -116,18 +139,22 @@ function parse_args() if args_contains( "GLES1" ) then defines { "EE_GLES1", "SOIL_GLES1" } end - - if not args_contains( "--with-static-freetype" ) and os.findlib("freetype") then - table.insert( link_list, "freetype" ) - end end function add_static_links() -- The linking order DOES matter + -- Expose the symbols that need one static library AFTER adding that static lib + + -- Add static backends + if next(static_backends) ~= nil then + for _, value in pairs( static_backends ) do + linkoptions { value } + end + end links { "haikuttf-static" } - if args_contains( "--with-static-freetype" ) or not os.findlib("freetype") then + if _OPTIONS["with-static-freetype"] or not os.findlib("freetype") then links { "freetype-static" } end @@ -141,47 +168,106 @@ function add_static_links() } end -function select_backend() - local selected = false +function can_add_static_backend( name ) + if _OPTIONS["with-static-backend"] then + local path = "libs/linux/lib" .. name .. ".a" + return os.isfile(path) + end +end + +function insert_static_backend( name ) + table.insert( static_backends, path.getrelative( "libs/" .. os.get(), "./" ) .. "/libs/linux/lib" .. name .. ".a" ) +end + +function add_sdl2() + files { "src/eepp/window/backend/SDL2/*.cpp" } + defines { "EE_BACKEND_SDL_ACTIVE", "EE_SDL_VERSION_2" } - if args_contains( "SDL2" ) then + if not can_add_static_backend("SDL2") then table.insert( link_list, "SDL2" ) - files { "src/eepp/window/backend/SDL2/*.cpp" } - defines { "EE_BACKEND_SDL_ACTIVE", "EE_SDL_VERSION_2" } - selected = true - elseif args_contains( "SDL" ) then - table.insert( link_list, "SDL" ) - files { "src/eepp/window/backend/SDL/*.cpp" } - defines { "EE_BACKEND_SDL_ACTIVE", "EE_SDL_VERSION_1_2" } - selected = true + else + insert_static_backend( "SDL2" ) end +end + +function add_sdl() + --- SDL is LGPL. It can't be build as static library + table.insert( link_list, "SDL" ) + files { "src/eepp/window/backend/SDL/*.cpp" } + defines { "EE_BACKEND_SDL_ACTIVE", "EE_SDL_VERSION_1_2" } +end + +function add_allegro5() + files { "src/eepp/window/backend/allegro5/*.cpp" } + defines { "EE_BACKEND_ALLEGRO_ACTIVE" } - if args_contains( "allegro5" ) then + if not can_add_static_backend("allegro5") then table.insert( link_list, "allegro5" ) - files { "src/eepp/window/backend/allegro5/*.cpp" } - defines { "EE_BACKEND_ALLEGRO_ACTIVE" } - selected = true + else + insert_static_backend( "allegro5" ) end +end + +function add_sfml() + files { "src/eepp/window/backend/SFML/*.cpp" } + defines { "EE_BACKEND_SFML_ACTIVE" } - if args_contains( "SFML" ) then + if not can_add_static_backend("SFML") then table.insert( link_list, "SFML" ) - files { "src/eepp/window/backend/SFML/*.cpp" } - defines { "EE_BACKEND_SFML_ACTIVE" } - selected = true + else + insert_static_backend( "SFML" ) + end +end + +function backend_is( name ) + if not _OPTIONS["with-backend"] then + _OPTIONS["with-backend"] = "SDL2" end - if not selected then - if os.findlib("SDL2") then - table.insert( link_list, "SDL2" ) - files { "src/eepp/window/backend/SDL2/*.cpp" } - defines { "EE_BACKEND_SDL_ACTIVE", "EE_SDL_VERSION_2" } - else - table.insert( link_list, "SDL" ) - files { "src/eepp/window/backend/SDL/*.cpp" } - defines { "EE_BACKEND_SDL_ACTIVE", "EE_SDL_VERSION_1_2" } + if next(backends) == nil then + backends = string.explode(_OPTIONS["with-backend"],",") + end + + local backend_sel = table_contains( backends, name ) + + local ret_val = os.findlib( name ) and backend_sel + + if ret_val then + backend_selected = true + end + + return ret_val +end + +function select_backend() + if backend_is( "SDL2" ) then + add_sdl2() + end + + if backend_is( "SDL" ) then + add_sdl() + end + + if backend_is( "allegro5" ) then + add_allegro5() + end + + if backend_is( "SFML" ) then + add_sfml() + end + + -- If the selected backend is not present, try to find one present + if not backend_selected then + if os.findlib("SDL") then + add_sdl() + elseif os.findlib("SDL2") then + add_sdl2() + elseif os.findlib("allegro5") then + add_allegro5() + elseif os.findlib("SFML") then + add_sfml() end end - end function build_eepp( build_name ) @@ -213,6 +299,20 @@ function build_eepp( build_name ) select_backend() + if not _OPTIONS["with-static-freetype"] and os.findlib("freetype") then + table.insert( link_list, "freetype" ) + end + + if _OPTIONS["with-libsndfile"] then + defines { "EE_LIBSNDFILE_ENABLED" } + + if os.is("windows") then + table.insert( link_list, "libsndfile-1" ) + else + table.insert( link_list, "sndfile" ) + end + end + multiple_insert( link_list, os_links ) links { link_list } @@ -222,7 +322,7 @@ function build_eepp( build_name ) linkoptions { "-mwindows" } if _ACTION == "gmake" then - linkoptions { "-static-libgcc" } --, "-static-libstdc++" + linkoptions { "-static-libgcc" } --, "-static-libstdc++" -- this should work, but it's not working with my mingw installation end configuration "linux" @@ -326,21 +426,21 @@ solution "eepp" build_eepp( "eepp" ) project "eepp-test" - kind "ConsoleApp" + kind "WindowedApp" language "C++" files { "src/test/*.cpp" } includedirs { "include", "src" } build_link_configuration( "eetest" ) project "eepp-es" - kind "ConsoleApp" + kind "WindowedApp" language "C++" files { "src/examples/external_shader/*.cpp" } includedirs { "include", "src" } build_link_configuration( "eees" ) project "eepp-ew" - kind "ConsoleApp" + kind "WindowedApp" language "C++" files { "src/examples/empty_window/*.cpp" } includedirs { "include", "src" } diff --git a/projects/ios/compile-release.sh b/projects/ios/compile-release.sh index e68f252fd..3ef9266e0 100644 --- a/projects/ios/compile-release.sh +++ b/projects/ios/compile-release.sh @@ -20,8 +20,8 @@ else BACKEND="GLES1=yes GLES2=yes" fi -make -j2 -e IOS=yes NO_SNDFILE=yes STATIC_FT2=yes SIMULATOR=yes DEBUGBUILD=no $BACKEND +make -j2 -e IOS=yes STATIC_FT2=yes SIMULATOR=yes DEBUGBUILD=no $BACKEND -make -j2 -e IOS=yes NO_SNDFILE=yes STATIC_FT2=yes SIMULATOR=no DEBUGBUILD=no $BACKEND +make -j2 -e IOS=yes STATIC_FT2=yes SIMULATOR=no DEBUGBUILD=no $BACKEND lipo -create -arch armv7 ./libs/ios/release/libeepp-armv7.a -arch i386 ./libs/ios/release/libeepp-i386.a -output ./libs/ios/release/libeepp.a \ No newline at end of file