From d79720532d4a51688ea4ec0155815c44f88814fc Mon Sep 17 00:00:00 2001 From: dijunkun Date: Wed, 22 Nov 2023 17:00:52 +0800 Subject: [PATCH] Optimize build script --- src/interface/x.h | 24 +-- .../encode/ffmpeg/ffmpeg_video_encoder.cpp | 6 +- .../encode/openh264/openh264_encoder.cpp | 6 +- xmake.lua | 147 +++++++++--------- 4 files changed, 98 insertions(+), 85 deletions(-) diff --git a/src/interface/x.h b/src/interface/x.h index fedae42..66e4d4b 100644 --- a/src/interface/x.h +++ b/src/interface/x.h @@ -1,6 +1,12 @@ #ifndef _X_H_ #define _X_H_ +#ifdef DLL_EXPORTS +#define DLLAPI __declspec(dllexport) +#else +#define DLLAPI __declspec(dllimport) +#endif + #include #include @@ -34,20 +40,20 @@ typedef struct { NetStatusReport net_status_report; } Params; -PeerPtr* CreatePeer(const Params* params); +DLLAPI PeerPtr* CreatePeer(const Params* params); -int Init(PeerPtr* peer_ptr, const char* user_id); +DLLAPI int Init(PeerPtr* peer_ptr, const char* user_id); -int CreateConnection(PeerPtr* peer_ptr, const char* transmission_id, - const char* password); +DLLAPI int CreateConnection(PeerPtr* peer_ptr, const char* transmission_id, + const char* password); -int JoinConnection(PeerPtr* peer_ptr, const char* transmission_id, - const char* password); +DLLAPI int JoinConnection(PeerPtr* peer_ptr, const char* transmission_id, + const char* password); -int LeaveConnection(PeerPtr* peer_ptr); +DLLAPI int LeaveConnection(PeerPtr* peer_ptr); -int SendData(PeerPtr* peer_ptr, DATA_TYPE data_type, const char* data, - size_t size); +DLLAPI int SendData(PeerPtr* peer_ptr, DATA_TYPE data_type, const char* data, + size_t size); #ifdef __cplusplus } diff --git a/src/media/video/encode/ffmpeg/ffmpeg_video_encoder.cpp b/src/media/video/encode/ffmpeg/ffmpeg_video_encoder.cpp index 25249dd..37dada0 100644 --- a/src/media/video/encode/ffmpeg/ffmpeg_video_encoder.cpp +++ b/src/media/video/encode/ffmpeg/ffmpeg_video_encoder.cpp @@ -8,10 +8,10 @@ #define SAVE_H264_STREAM 0 #define YUV420P_BUFFER_SIZE 1280 * 720 * 3 / 2 -unsigned char yuv420p_buffer[YUV420P_BUFFER_SIZE]; +static unsigned char yuv420p_buffer[YUV420P_BUFFER_SIZE]; -int NV12ToYUV420PFFmpeg(unsigned char *src_buffer, int width, int height, - unsigned char *dst_buffer) { +static int NV12ToYUV420PFFmpeg(unsigned char *src_buffer, int width, int height, + unsigned char *dst_buffer) { AVFrame *Input_pFrame = av_frame_alloc(); AVFrame *Output_pFrame = av_frame_alloc(); struct SwsContext *img_convert_ctx = sws_getContext( diff --git a/src/media/video/encode/openh264/openh264_encoder.cpp b/src/media/video/encode/openh264/openh264_encoder.cpp index 92419fe..6c19ec0 100644 --- a/src/media/video/encode/openh264/openh264_encoder.cpp +++ b/src/media/video/encode/openh264/openh264_encoder.cpp @@ -23,10 +23,10 @@ extern "C" { #define SAVE_H264_STREAM 0 #define YUV420P_BUFFER_SIZE 1280 * 720 * 3 / 2 -unsigned char yuv420p_buffer[YUV420P_BUFFER_SIZE]; +static unsigned char yuv420p_buffer[YUV420P_BUFFER_SIZE]; -int NV12ToYUV420PFFmpeg(unsigned char *src_buffer, int width, int height, - unsigned char *dst_buffer) { +static int NV12ToYUV420PFFmpeg(unsigned char *src_buffer, int width, int height, + unsigned char *dst_buffer) { AVFrame *Input_pFrame = av_frame_alloc(); AVFrame *Output_pFrame = av_frame_alloc(); struct SwsContext *img_convert_ctx = sws_getContext( diff --git a/xmake.lua b/xmake.lua index 91f88bb..48ee512 100644 --- a/xmake.lua +++ b/xmake.lua @@ -15,126 +15,116 @@ add_defines("ASIO_STANDALONE", "ASIO_HAS_STD_TYPE_TRAITS", "ASIO_HAS_STD_SHARED_ "ASIO_HAS_STD_ADDRESSOF", "ASIO_HAS_STD_ATOMIC", "ASIO_HAS_STD_CHRONO", "ASIO_HAS_CSTDINT", "ASIO_HAS_STD_ARRAY", "ASIO_HAS_STD_SYSTEM_ERROR") -if is_os("windows") then - add_defines("_WEBSOCKETPP_CPP11_INTERNAL_") - add_links("ws2_32", "Bcrypt") - add_links("windowsapp", "User32", "Strmiids", "Mfuuid", "Secur32", "Bcrypt") - add_requires("cuda") -elseif is_os("linux") then - add_cxflags("-fPIC") - add_syslinks("pthread") -elseif is_os("macosx") then - add_ldflags("-ld_classic", {force = true}) -end - add_requires("asio 1.24.0", "nlohmann_json", "spdlog 1.11.0", "openfec", "libopus 1.4") -add_packages("spdlog", "openfec") +add_packages("asio", "nlohmann_json", "spdlog", "openfec", "opus") + includes("thirdparty") if is_os("windows") then add_requires("vcpkg::ffmpeg 5.1.2", {configs = {shared = false}}) add_requires("vcpkg::libnice 0.1.21") - add_packages("vcpkg::libnice") add_requires("openh264 2.1.1", {configs = {shared = false}}) + add_packages("vcpkg::ffmpeg", "vcpkg::libnice", "openh264", "cuda") + add_defines("_WEBSOCKETPP_CPP11_INTERNAL_") + add_requires("cuda") elseif is_os("linux") then add_requires("ffmpeg 5.1.2", {system = false}) add_requires("glib", {system = true}) add_requires("vcpkg::libnice 0.1.21") add_requires("openh264 2.1.1", {configs = {shared = false}}) - add_packages("glib", "vcpkg::libnice") + add_packages("ffmpeg", "glib", "vcpkg::libnice", "openh264", "cuda") + add_cxflags("-fPIC") + add_syslinks("pthread") elseif is_os("macosx") then add_requires("ffmpeg 5.1.2", {system = false}) add_requires("brew::libnice", "brew::glib") add_requires("brew::openh264", {configs = {shared = false}}) + add_packages("ffmpeg", "glib", "libnice") + add_ldflags("-ld_classic", {force = true}) end target("log") - set_kind("static") - add_packages("spdlog") + set_kind("object") add_files("src/log/log.cpp") add_includedirs("src/log", {public = true}) target("common") - set_kind("static") + set_kind("object") add_files("src/common/common.cpp") add_includedirs("src/common", {public = true}) target("inih") - set_kind("static") + set_kind("object") add_files("src/inih/ini.c", "src/inih/INIReader.cpp") add_includedirs("src/inih", {public = true}) target("ringbuffer") - set_kind("static") + set_kind("object") add_files("src/ringbuffer/ringbuffer.cpp") add_includedirs("src/ringbuffer", {public = true}) target("thread") - set_kind("static") + set_kind("object") add_deps("log") add_files("src/thread/*.cpp") add_includedirs("src/thread", {public = true}) target("frame") - set_kind("static") + set_kind("object") add_files("src/frame/*.cpp") add_includedirs("src/frame", {public = true}) target("fec") - set_kind("static") + set_kind("object") add_deps("log") add_files("src/fec/*.cpp") add_includedirs("src/fec", {public = true}) target("rtcp") - set_kind("static") + set_kind("object") add_deps("log") add_files("src/rtcp/*.cpp") add_includedirs("src/rtcp", {public = true}) target("rtp") - set_kind("static") + set_kind("object") add_deps("log", "frame", "ringbuffer", "thread", "rtcp", "fec") add_files("src/rtp/*.cpp") add_includedirs("src/rtp", {public = true}) target("ice") - set_kind("static") + set_kind("object") add_deps("log", "common", "ws") - add_packages("asio", "nlohmann_json") add_files("src/ice/*.cpp") add_includedirs("src/ws", "src/ice", {public = true}) if is_os("windows") then - add_includedirs(path.join(os.getenv("VCPKG_ROOT"), "installed/x64-windows-static/include/glib-2.0"), {public = true}) - add_includedirs(path.join(os.getenv("VCPKG_ROOT"), "installed/x64-windows-static/lib/glib-2.0/include"), {public = true}) - add_links("nice", "glib-2.0", "gio-2.0", "gmodule-2.0", "gobject-2.0", - "pcre2-8", "pcre2-16", "pcre2-32", "pcre2-posix", - "zlib", "ffi", "libcrypto", "libssl", "intl", "iconv", "charset", "bz2", - "Shell32", "Advapi32", "Dnsapi", "Shlwapi", "Iphlpapi") + add_includedirs(path.join(os.getenv("VCPKG_ROOT"), + "installed/x64-windows-static/include/glib-2.0"), {public = true}) + add_includedirs(path.join(os.getenv("VCPKG_ROOT"), + "installed/x64-windows-static/lib/glib-2.0/include"), {public = true}) elseif is_os("macosx") then - add_packages("glib", "libnice") - add_includedirs(path.join("$(shell brew --cellar)", "glib/2.78.0/include/glib-2.0"), {public = true}) - add_includedirs(path.join("$(shell brew --cellar)", "glib/2.78.0/lib/glib-2.0/include"), {public = true}) - add_includedirs(path.join("$(shell brew --cellar)", "glib/2.78.0/lib/glib-2.0/include"), {public = true}) - add_includedirs(path.join("$(shell brew --cellar)", "glib/2.78.0/include"), {public = true}) - add_includedirs(path.join("$(shell brew --cellar)", "libnice/0.1.21/include"), {public = true}) - add_linkdirs(path.join("$(shell brew --cellar)", "glib/2.78.0/lib")) - add_linkdirs(path.join("$(shell brew --cellar)", "libnice/0.1.21/lib")) - add_links("nice", "glib-2.0", "gio-2.0", "gobject-2.0") + add_includedirs(path.join("$(shell brew --cellar)", + "glib/2.78.0/include/glib-2.0"), {public = true}) + add_includedirs(path.join("$(shell brew --cellar)", + "glib/2.78.0/lib/glib-2.0/include"), {public = true}) + add_includedirs(path.join("$(shell brew --cellar)", + "glib/2.78.0/lib/glib-2.0/include"), {public = true}) + add_includedirs(path.join("$(shell brew --cellar)", + "glib/2.78.0/include"), {public = true}) + add_includedirs(path.join("$(shell brew --cellar)", + "libnice/0.1.21/include"), {public = true}) end target("ws") - set_kind("static") + set_kind("object") add_deps("log") add_files("src/ws/*.cpp") - add_packages("asio") add_includedirs("thirdparty/websocketpp/include", {public = true}) target("media") - set_kind("static") + set_kind("object") add_deps("log", "frame") if is_os("windows") then - add_packages("cuda", "vcpkg::ffmpeg", "openh264") add_files("src/media/video/encode/*.cpp", "src/media/video/decode/*.cpp", "src/media/video/encode/nvcodec/*.cpp", @@ -153,10 +143,7 @@ target("media") "src/media/video/decode/openh264", "thirdparty/nvcodec/Interface", "thirdparty/nvcodec/Samples", {public = true}) - add_linkdirs("thirdparty/nvcodec/Lib/x64") - add_links("cuda", "nvencodeapi", "nvcuvid") elseif is_os(("linux")) then - add_packages("cuda", "ffmpeg", "openh264") add_files("src/media/video/encode/*.cpp", "src/media/video/decode/*.cpp", "src/media/video/encode/nvcodec/*.cpp", @@ -175,10 +162,7 @@ target("media") "src/media/video/decode/openh264", "thirdparty/nvcodec/Interface", "thirdparty/nvcodec/Samples", {public = true}) - add_linkdirs("thirdparty/nvcodec/Lib/x64") - add_links("cuda", "nvidia-encode", "nvcuvid") elseif is_os("macosx") then - add_packages("ffmpeg") add_files("src/media/video/encode/*.cpp", "src/media/video/decode/*.cpp", "src/media/video/encode/ffmpeg/*.cpp", @@ -188,42 +172,65 @@ target("media") "src/media/video/encode/ffmpeg", "src/media/video/decode/ffmpeg", {public = true}) end - add_packages("opus") add_files("src/media/audio/encode/*.cpp", "src/media/audio/decode/*.cpp") add_includedirs("src/media/audio/encode", "src/media/audio/decode", {public = true}) target("qos") - set_kind("static") + set_kind("object") add_deps("log") add_files("src/qos/kcp/*.c") add_includedirs("src/qos/kcp", {public = true}) target("transmission") - set_kind("static") + set_kind("object") add_deps("log", "ws", "ice", "qos", "rtp", "rtcp") add_files("src/transmission/*.cpp") - add_packages("asio", "nlohmann_json") add_includedirs("src/ws", "src/ice", "src/qos", {public = true}) target("pc") - set_kind("static") + set_kind("object") add_deps("log") add_deps("ws", "ice", "transmission", "inih", "common", "media") add_files("src/pc/*.cpp") - add_packages("asio", "nlohmann_json", "cuda") add_includedirs("src/transmission", "src/interface", {public = true}) target("projectx") set_kind("shared") - add_deps("log") - add_deps("pc") - add_installfiles("src/interface/*.h", {prefixdir = "include"}) + add_deps("log", "pc") add_files("src/rtc/*.cpp") - add_packages("asio", "nlohmann_json", "cuda") add_includedirs("src/rtc", "src/pc", "src/interface") - add_rules("utils.symbols.export_all", {export_classes = true}) + + if is_os("windows") then + add_linkdirs("thirdparty/nvcodec/Lib/x64") + add_links("nice", "glib-2.0", "gio-2.0", "gmodule-2.0", "gobject-2.0", + "pcre2-8", "pcre2-16", "pcre2-32", "pcre2-posix", + "zlib", "ffi", "libcrypto", "libssl", "intl", "iconv", "charset", "bz2", + "Shell32", "Advapi32", "Dnsapi", "Shlwapi", "Iphlpapi", + "cuda", "nvencodeapi", "nvcuvid", + "ws2_32", "Bcrypt", "windowsapp", "User32", "Strmiids", "Mfuuid", + "Secur32", "Bcrypt") + elseif is_os(("linux")) then + add_linkdirs("thirdparty/nvcodec/Lib/x64") + add_links("cuda", "nvidia-encode", "nvcuvid") + elseif is_os("macosx") then + add_linkdirs(path.join("$(shell brew --cellar)", "glib/2.78.0/lib")) + add_linkdirs(path.join("$(shell brew --cellar)", "libnice/0.1.21/lib")) + add_links("nice", "glib-2.0", "gio-2.0", "gobject-2.0") + end + + add_installfiles("src/interface/*.h", {prefixdir = "include"}) + add_rules("utils.symbols.export_list", {symbols = { + "CreatePeer", + "Init", + "CreateConnection", + "JoinConnection", + "LeaveConnection", + "SendData"}}) + + + -- add_rules("utils.symbols.export_all", {export_classes = true}) -- after_install(function (target) -- os.rm("$(projectdir)/out/lib/*.a") -- os.rm("$(projectdir)/out/include/log.h") @@ -264,10 +271,10 @@ target("projectx") -- add_files("tests/fec/simple_server.cpp") -- add_includedirs("tests/fec") -target("opus_test") - set_kind("binary") - add_packages("libopus") - add_files("tests/opus/OpusEncoderImpl.cpp", - "tests/opus/OpusDecoderImpl.cpp", - "tests/opus/main.cpp") - add_includedirs("tests/opus") \ No newline at end of file +-- target("opus_test") +-- set_kind("binary") +-- add_packages("libopus") +-- add_files("tests/opus/OpusEncoderImpl.cpp", +-- "tests/opus/OpusDecoderImpl.cpp", +-- "tests/opus/main.cpp") +-- add_includedirs("tests/opus") \ No newline at end of file