From af28e0a6ce229cc4873611721ed76469b79ac06b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?shuxin=20=E3=80=80=E3=80=80zheng?= Date: Thu, 4 Apr 2024 15:28:22 +0800 Subject: [PATCH] Optimize project's building. --- CMakeLists.txt | 13 +++++-------- build/.keepme | 1 - cmake-build.sh | 7 +++++++ build_by_cosmocc => cosmocc-build.sh | 0 lib_acl/CMakeLists.txt | 9 +++++++-- lib_acl/Makefile | 29 ++++++++++++++++------------ lib_acl/src/init/acl_init.c | 2 +- lib_acl_cpp/CMakeLists.txt | 8 +++++--- lib_acl_cpp/Makefile | 6 ++++-- lib_fiber/c/CMakeLists.txt | 7 ++++++- lib_fiber/c/Makefile | 18 ++++++++++------- lib_fiber/cpp/CMakeLists.txt | 8 +++++--- lib_fiber/cpp/Makefile | 20 ++++++++++--------- lib_protocol/CMakeLists.txt | 11 ++++++++--- lib_protocol/Makefile | 7 ++++--- 15 files changed, 91 insertions(+), 55 deletions(-) delete mode 100644 build/.keepme create mode 100755 cmake-build.sh rename build_by_cosmocc => cosmocc-build.sh (100%) diff --git a/CMakeLists.txt b/CMakeLists.txt index b01852c71..b647efd88 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -88,12 +88,9 @@ if (ACL_BUILD_SHARED MATCHES "YES") add_dependencies(acl_cpp_shared protocol_shared acl_shared) endif() -#if (CMAKE_SYSTEM_NAME MATCHES "Linux" OR CMAKE_SYSTEM_NAME MATCHES "Android") -#if (CMAKE_SYSTEM_NAME MATCHES "Linux" OR CMAKE_SYSTEM_NAME MATCHES "Darwin") - add_subdirectory(lib_fiber/c fiber) - add_subdirectory(lib_fiber/cpp fiber_cpp) +add_subdirectory(lib_fiber/c fiber) +add_subdirectory(lib_fiber/cpp fiber_cpp) - if (ACL_BUILD_SHARED MATCHES "YES") - add_dependencies(fiber_cpp_shared acl_cpp_shared protocol_shared acl_shared fiber_shared) - endif() -#endif() +if (ACL_BUILD_SHARED MATCHES "YES") + add_dependencies(fiber_cpp_shared acl_cpp_shared protocol_shared acl_shared fiber) +endif() diff --git a/build/.keepme b/build/.keepme deleted file mode 100644 index b0e2aa073..000000000 --- a/build/.keepme +++ /dev/null @@ -1 +0,0 @@ -keepme diff --git a/cmake-build.sh b/cmake-build.sh new file mode 100755 index 000000000..f940d9d84 --- /dev/null +++ b/cmake-build.sh @@ -0,0 +1,7 @@ +#!/bin/sh +mkdir -p build +cd build +#cmake -DCMAKE_INSTALL_PREFIX=/opt/soft/zsx -DACL_BUILD_SHARED=YES -DACL_BUILD_SHARED_ONE=YES .. +cmake -DCMAKE_INSTALL_PREFIX=/opt/soft/zsx -DACL_BUILD_SHARED=YES .. +make -j 4 +make install diff --git a/build_by_cosmocc b/cosmocc-build.sh similarity index 100% rename from build_by_cosmocc rename to cosmocc-build.sh diff --git a/lib_acl/CMakeLists.txt b/lib_acl/CMakeLists.txt index a24d07cd5..bbc14c359 100644 --- a/lib_acl/CMakeLists.txt +++ b/lib_acl/CMakeLists.txt @@ -8,7 +8,7 @@ project(acl) #message(project_dir=${PROJECT_SOURCE_DIR}) if (${CMAKE_BINARY_DIR} STREQUAL ${CMAKE_CURRENT_SOURCE_DIR}) - message(FATAL_ERROR "Please into another dir to build!") + message(FATAL_ERROR "Please into another dir to build! ${CMAKE_BINARY_DIR}, ${CMAKE_CURRENT_SOURCE_DIR}") endif() if (CMAKE_SYSTEM_NAME MATCHES "Android") @@ -206,7 +206,8 @@ install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/include/ DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/acl-lib/acl/" ) -if (NOT CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR AND ACL_BUILD_SHARED MATCHES "YES") +#if ((NOT CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR) AND ACL_BUILD_SHARED MATCHES "YES") +if (ACL_BUILD_SHARED MATCHES "YES") if (CMAKE_SYSTEM_NAME MATCHES "Android") if (ANDROID_STL MATCHES "gnustl_shared") set(sys_ldflags "-shared") @@ -220,6 +221,10 @@ if (NOT CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR AND ACL_BUILD_SHARED elseif (${UNIX_OS}) set(sys_ldflags "-shared -lpthread -ldl") target_compile_options(acl_static PRIVATE -fvisibility=hidden) + + if (CMAKE_SYSTEM_NAME MATCHES "Darwin") + set(CMAKE_MACOSX_RPATH 1) + endif() endif() set(CMAKE_SHARED_LINKER_FLAGS "${sys_ldflags}") diff --git a/lib_acl/Makefile b/lib_acl/Makefile index f4c46ff2a..9c77ba857 100644 --- a/lib_acl/Makefile +++ b/lib_acl/Makefile @@ -10,7 +10,12 @@ RANLIB = ${ENV_RANLIB} FLAGS = ${ENV_FLAGS} # default lib name -LIB_NAME = libacl.a +# LIB_NAME = libacl.a + +STATIC_OLD_LIBNAME = lib_acl.a +SHARED_OLD_LIBNAME = lib_acl.so +STATIC_LIBNAME = libacl.a +SHARED_LIBNAME = libacl.so #-fno-strict-aliasing \ #CFLAGS = -c -g -W -Wall -Wcast-qual -Wcast-align @@ -120,6 +125,8 @@ ifeq ($(findstring Darwin, $(UNIXNAME)), Darwin) -Os UNIXTYPE = MACOSX RPATH = macos + SHARED_LIBNAME = libacl.dylib + SHARED_OLD_LIBNAME = lib_acl.dylib endif # For Linux @@ -324,11 +331,6 @@ OBJS_DEF = $(INIT_DEF) $(PRIV_DEF) $(STDLIB_DEF) \ ########################################################### .PHONY = all static shared clean cl clean_lib rebuild rb -STATIC_OLD_LIBNAME = lib_acl.a -SHARED_OLD_LIBNAME = lib_acl.so -STATIC_LIBNAME = libacl.a -SHARED_LIBNAME = libacl.so - all: static shared $(shell mkdir -p $(DEF_PATH_DST)) @@ -359,31 +361,34 @@ static: $(OBJS_DST) ln -s $(STATIC_LIBNAME) $(STATIC_OLD_LIBNAME)) @echo 'build $(LIB_PATH_DST)/$(STATIC_LIBNAME) ok!' -#shared_ldflags = -lmysqlclient -lrt -lpthread -ldl -shared_ldflags = -lrt -lpthread -ldl #shared: depends $(OBJS_DST) + shared: $(OBJS_DST) @echo '' @echo 'creating $(SHARED_LIBNAME)' @if test -n "$(rpath)" && test "$(UNIXTYPE)" = "LINUX"; then \ echo "building for linux"; \ + shared_ldflags=-lrt -lpthread -ldl; \ $(CC) -shared -o $(rpath)/$(SHARED_LIBNAME) $(OBJS_DST) \ - -L$(rpath) $(shared_ldflags) -Wl,-rpath,$(rpath); \ + $(shared_ldflags) -Wl,-rpath,$(rpath); \ echo 'build $(rpath)/$(SHARED_LIBNAME) ok!'; \ elif test -n "$(rpath)" && test "$(UNIXTYPE)" = "SUNOS5"; then \ echo "building for sunos5"; \ + shared_ldflags=-lrt -lpthread -ldl; \ $(CC) -shared -o $(rpath)/$(SHARED_LIBNAME) $(OBJS_DST) \ - -L$(rpath) $(shared_ldflags); \ + $(shared_ldflags); \ echo 'build $(rpath)/$(SHARED_LIBNAME) ok!'; \ elif test -n "$(rpath)" && test "$(UNIXTYPE)" = "MACOSX"; then \ echo "building for Darwin"; \ + shared_ldflags=-lpthread; \ $(CC) -shared -o $(rpath)/$(SHARED_LIBNAME) $(OBJS_DST) \ - -L$(rpath) -lpthread; \ + $(shared_ldflags); \ echo 'build $(rpath)/$(SHARED_LIBNAME) ok!'; \ elif test -n "$(rpath)" && test "$(UNIXTYPE)" = "FREEBSD"; then \ echo "building for FreeBSD"; \ + shared_ldflags=-lrt -lpthread -ldl; \ $(CC) -shared -o $(rpath)/$(SHARED_LIBNAME) $(OBJS_DST) \ - -L$(rpath) -lpthread; \ + $(shared_ldflags); \ echo 'build $(rpath)/$(SHARED_LIBNAME) ok!'; \ else \ echo 'skip build $(SHARED_LIBNAME); usage: make shared rpath=xxx'; \ diff --git a/lib_acl/src/init/acl_init.c b/lib_acl/src/init/acl_init.c index 323bc5e3f..77c797488 100644 --- a/lib_acl/src/init/acl_init.c +++ b/lib_acl/src/init/acl_init.c @@ -25,7 +25,7 @@ #include "init.h" -static char *version = "3.6.1-6 20240226-16:00"; +static char *version = "3.6.1-6 20240404-14:00"; const char *acl_version(void) { diff --git a/lib_acl_cpp/CMakeLists.txt b/lib_acl_cpp/CMakeLists.txt index d9dfd9380..e73dded1a 100644 --- a/lib_acl_cpp/CMakeLists.txt +++ b/lib_acl_cpp/CMakeLists.txt @@ -268,7 +268,8 @@ install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/include/acl_cpp/ DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/acl-lib/acl_cpp/" ) -if (NOT CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR AND ACL_BUILD_SHARED MATCHES "YES") +#if (NOT CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR AND ACL_BUILD_SHARED MATCHES "YES") +if (ACL_BUILD_SHARED MATCHES "YES") if (CMAKE_SYSTEM_NAME MATCHES "Android") if (ANDROID_STL MATCHES "gnustl_shared") set(sys_ldflags "-shared -lz") @@ -285,6 +286,7 @@ if (NOT CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR AND ACL_BUILD_SHARED set(sys_ldflags "-shared -lz -liconv -lpthread -ldl") target_compile_options(acl_cpp_static PRIVATE -fvisibility=hidden -fvisibility-inlines-hidden) + set(CMAKE_MACOSX_RPATH 1) elseif (${UNIX_OS}) set(sys_ldflags "-shared -lz -lpthread -ldl") target_compile_options(acl_cpp_static PRIVATE @@ -296,10 +298,10 @@ if (NOT CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR AND ACL_BUILD_SHARED set(CMAKE_SHARED_LINKER_FLAGS "${lc_flags} ${sys_ldflags}") add_library(acl_cpp_shared SHARED ${lib_src}) else() - set(lc_flags "-Wl,-rpath,. -L${lib_output_path} -lprotocol -lacl") + set(lc_flags "-Wl,-rpath,${CMAKE_INSTALL_PREFIX}/lib -L${CMAKE_INSTALL_PREFIX}/lib -lprotocol -lacl") set(CMAKE_SHARED_LINKER_FLAGS "${lc_flags} ${sys_ldflags}") add_library(acl_cpp_shared SHARED ${lib_src}) - target_link_libraries(acl_cpp_shared protocol acl) +# target_link_libraries(acl_cpp_shared protocol acl) endif() SET_TARGET_PROPERTIES(acl_cpp_shared PROPERTIES OUTPUT_NAME "acl_cpp") diff --git a/lib_acl_cpp/Makefile b/lib_acl_cpp/Makefile index 35056cdf0..f0f85dda9 100644 --- a/lib_acl_cpp/Makefile +++ b/lib_acl_cpp/Makefile @@ -36,6 +36,9 @@ CFLAGS += -I/usr/local/include shared_ldflags = -lprotocol -lacl -lz -lpthread +STATIC_LIBNAME = libacl_cpp.a +SHARED_LIBNAME = libacl_cpp.so + ########################################################### #Check system: # Linux, SunOS, Solaris, BSD variants, AIX, HP-UX @@ -144,6 +147,7 @@ ifeq ($(findstring Darwin, $(UNIXNAME)), Darwin) endif shared_ldflags = -lprotocol -lacl -L/usr/lib -liconv -lz -lpthread + SHARED_LIBNAME = libacl_cpp.dylib endif # For Linux @@ -300,8 +304,6 @@ OBJS_DEF = $(patsubst %.cpp, $(DEF_PATH_DST)/%.inc, $(notdir $(wildcard src/*.cp VERSION = 1.1.1.2 DATE_NOW = 20`date +%y`.`date +%m`.`date +%d` -STATIC_LIBNAME = libacl_cpp.a -SHARED_LIBNAME = libacl_cpp.so PCH = src/acl_stdafx.hpp.gch lib: static diff --git a/lib_fiber/c/CMakeLists.txt b/lib_fiber/c/CMakeLists.txt index fafd5a43c..8d0ad41c0 100644 --- a/lib_fiber/c/CMakeLists.txt +++ b/lib_fiber/c/CMakeLists.txt @@ -168,7 +168,8 @@ install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/include/fiber/ DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/acl-lib/fiber" ) -if (NOT CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR AND ACL_BUILD_SHARED MATCHES "YES") +#if (NOT CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR AND ACL_BUILD_SHARED MATCHES "YES") +if (ACL_BUILD_SHARED MATCHES "YES") if (CMAKE_SYSTEM_NAME MATCHES "Android") if (ANDROID_STL MATCHES "gnustl_shared") set(sys_ldflags "-shared -O3") @@ -179,6 +180,10 @@ if (NOT CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR AND ACL_BUILD_SHARED elseif (${UNIX_OS}) set(sys_ldflags "-shared -O3") target_compile_options(fiber_static PRIVATE -fvisibility=hidden) + + if (CMAKE_SYSTEM_NAME MATCHES "Darwin") + set(CMAKE_MACOSX_RPATH 1) + endif() endif() set(CMAKE_SHARED_LINKER_FLAGS "${sys_ldflags}") diff --git a/lib_fiber/c/Makefile b/lib_fiber/c/Makefile index 8f4651e9a..30574a1e6 100644 --- a/lib_fiber/c/Makefile +++ b/lib_fiber/c/Makefile @@ -50,6 +50,13 @@ CHECKSYSRES = @echo "Unknow system type!";exit 1 UNIXNAME = $(shell uname -sm) UNIXTYPE = LINUX +########################################################### + +STATIC_LIBNAME = libfiber.a +SHARED_LIBNAME = libfiber.so +STATIC_OLD_LIBNAME = lib_fiber.a +SHARED_OLD_LIBNAME = lib_fiber.so + ifeq ($(CC),) CC = gcc endif @@ -117,10 +124,13 @@ endif # For Darwin ifeq ($(findstring Darwin, $(UNIXNAME)), Darwin) + UNIXTYPE = MACOSX # CC += -arch x86_64 -arch arm64 CFLAGS += -DMACOSX -Wno-invalid-source-encoding \ -Wno-invalid-offsetof \ -Wno-deprecated-declarations + SHARED_LIBNAME = libfiber.dylib + SHARED_OLD_LIBNAME = lib_fiber.dylib endif # For Linux @@ -236,13 +246,6 @@ OBJ = $(patsubst %.c, $(OBJ_PATH_DST)/%.o, $(notdir $(SRC))) $(ASM_OBJ) ########################################################### -STATIC_LIBNAME = libfiber.a -SHARED_LIBNAME = libfiber.so -STATIC_OLD_LIBNAME = lib_fiber.a -SHARED_OLD_LIBNAME = lib_fiber.so - -########################################################### - .PHONY = static shared clean COMPILE = $(CC) $(CFLAGS) -O3 COMPILE_FIBER = $(CC) $(CFLAGS) @@ -275,6 +278,7 @@ shared: $(OBJ) -R$(rpath) -L$(rpath) $(shared_ldflags); \ echo 'build $(rpath)/$(SHARED_LIBNAME) ok!'; \ elif test -n "$(rpath)" && test "$(UNIXTYPE)" = "MACOSX"; then \ + shared_ldflags = -lpthread; \ echo "building for Darwin"; \ $(CC) -shared -o $(rpath)/$(SHARED_LIBNAME) $(OBJ) \ -R$(rpath) -L$(rpath) -lpthread; \ diff --git a/lib_fiber/cpp/CMakeLists.txt b/lib_fiber/cpp/CMakeLists.txt index 4bf53079c..244c0812b 100644 --- a/lib_fiber/cpp/CMakeLists.txt +++ b/lib_fiber/cpp/CMakeLists.txt @@ -154,7 +154,8 @@ install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/include/fiber/ DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/acl-lib/fiber_cpp" ) -if (NOT CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR AND ACL_BUILD_SHARED MATCHES "YES") +#if (NOT CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR AND ACL_BUILD_SHARED MATCHES "YES") +if (ACL_BUILD_SHARED MATCHES "YES") if (CMAKE_SYSTEM_NAME MATCHES "Android") if (ANDROID_STL MATCHES "gnustl_shared") set(sys_ldflags "-shared -lz") @@ -167,6 +168,7 @@ if (NOT CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR AND ACL_BUILD_SHARED set(sys_ldflags "-shared -liconv -lz -lpthread -ldl") target_compile_options(fiber_cpp_static PRIVATE -fvisibility=hidden -fvisibility-inlines-hidden) + set(CMAKE_MACOSX_RPATH 1) elseif (${UNIX_OS}) set(sys_ldflags "-shared -lz -lpthread -ldl") target_compile_options(fiber_cpp_static PRIVATE @@ -178,10 +180,10 @@ if (NOT CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR AND ACL_BUILD_SHARED set(CMAKE_SHARED_LINKER_FLAGS "${lc_ldflags} ${sys_ldflags}") add_library(fiber_cpp_shared SHARED ${lib_src}) else() - set(lc_ldflags "-Wl,-rpath,. -L${lib_output_path} -lacl_cpp -lprotocol -lacl -lfiber") + set(lc_ldflags "-Wl,-rpath,${CMAKE_INSTALL_PREFIX}/lib -L${CMAKE_INSTALL_PREFIX}/lib -lacl_cpp -lprotocol -lacl -lfiber") set(CMAKE_SHARED_LINKER_FLAGS "${lc_ldflags} ${sys_ldflags}") add_library(fiber_cpp_shared SHARED ${lib_src}) - target_link_libraries(fiber_cpp_shared acl_cpp protocol acl fiber) +# target_link_libraries(fiber_cpp_shared acl_cpp protocol acl fiber) endif() SET_TARGET_PROPERTIES(fiber_cpp_shared PROPERTIES OUTPUT_NAME "fiber_cpp") diff --git a/lib_fiber/cpp/Makefile b/lib_fiber/cpp/Makefile index e7b86f7bf..4b9a1da65 100644 --- a/lib_fiber/cpp/Makefile +++ b/lib_fiber/cpp/Makefile @@ -29,7 +29,12 @@ CFLAGS = -c -g -W \ #just for freebsd's iconv.h CFLAGS += -I/usr/local/include -I../../lib_acl/src/master -shared_ldflags = -lacl_cpp -lprotocol -lacl -lz -lpthread +shared_ldflags = -lacl_cpp -lprotocol -lacl -lfiber -lz -lpthread + +STATIC_LIBNAME = libfiber_cpp.a +SHARED_LIBNAME = libfiber_cpp.so +STATIC_OLD_LIBNAME = lib_fiber_cpp.a +SHARED_OLD_LIBNAME = lib_fiber_cpp.so ########################################################### #Check system: @@ -71,7 +76,7 @@ endif # For FreeBSD ifeq ($(findstring FreeBSD, $(UNIXNAME)), FreeBSD) UNIXTYPE = FREEBSD - shared_ldflags = -lacl_cpp -lprotocol -lacl -L/usr/local/lib -liconv -lz -lpthread + shared_ldflags = -lacl_cpp -lprotocol -lacl -lfiber -L/usr/local/lib -liconv -lz -lpthread endif # For Darwin @@ -81,13 +86,15 @@ ifeq ($(findstring Darwin, $(UNIXNAME)), Darwin) -Wno-invalid-offsetof \ -Wno-unused-private-field UNIXTYPE = MACOSX - shared_ldflags = -lacl_cpp -lprotocol -lacl -L/usr/lib -liconv -lz -lpthread + shared_ldflags = -lacl_cpp -lprotocol -lacl -lfiber -L/usr/lib -liconv -lz -lpthread + SHARED_LIBNAME = libfiber_cpp.dylib + SHARED_OLD_LIBNAME = lib_fiber_cpp.dylib endif # For Linux ifeq ($(findstring Linux, $(UNIXNAME)), Linux) UNIXTYPE = LINUX - shared_ldflags = -lacl_cpp -lprotocol -lacl -lrt -lpthread -lz -ldl + shared_ldflags = -lacl_cpp -lprotocol -lacl -lfiber -lrt -lpthread -lz -ldl endif # For CYGWIN @@ -147,11 +154,6 @@ OBJ = $(patsubst %.cpp, $(OBJ_PATH_DST)/%.o, $(notdir $(SRC))) VERSION = 0.9 DATE_NOW = 20`date +%y`.`date +%m`.`date +%d` -STATIC_LIBNAME = libfiber_cpp.a -SHARED_LIBNAME = libfiber_cpp.so -STATIC_OLD_LIBNAME = lib_fiber_cpp.a -SHARED_OLD_LIBNAME = lib_fiber_cpp.so - lib: static all: static shared sample diff --git a/lib_protocol/CMakeLists.txt b/lib_protocol/CMakeLists.txt index 4fa469d39..16a2c02a9 100644 --- a/lib_protocol/CMakeLists.txt +++ b/lib_protocol/CMakeLists.txt @@ -154,7 +154,8 @@ install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/include/ DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/acl-lib/protocol/" ) -if (NOT CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR AND ACL_BUILD_SHARED MATCHES "YES") +#if (NOT CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR AND ACL_BUILD_SHARED MATCHES "YES") +if (ACL_BUILD_SHARED MATCHES "YES") if (CMAKE_SYSTEM_NAME MATCHES "Android") if (ANDROID_STL MATCHES "gnustl_shared") set(sys_ldflags "-shared -lz") @@ -168,6 +169,10 @@ if (NOT CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR AND ACL_BUILD_SHARED elseif (${UNIX_OS}) set(sys_ldflags "-shared -lz -lpthread -ldl") target_compile_options(protocol_static PRIVATE -fvisibility=hidden) + + if (CMAKE_SYSTEM_NAME MATCHES "Darwin") + set(CMAKE_MACOSX_RPATH 1) + endif() endif() if (ACL_BUILD_SHARED_ONE MATCHES "YES") @@ -175,10 +180,10 @@ if (NOT CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR AND ACL_BUILD_SHARED set(CMAKE_SHARED_LINKER_FLAGS "${lc_flags} ${sys_ldflags}") add_library(protocol_shared SHARED ${lib_src}) else() - set(lc_flags "-Wl,-rpath,. -L${lib_output_path} -lacl") + set(lc_flags "-Wl,-rpath,${CMAKE_INSTALL_PREFIX}/lib -L${CMAKE_INSTALL_PREFIX}/lib -lacl") set(CMAKE_SHARED_LINKER_FLAGS "${lc_flags} ${sys_ldflags}") add_library(protocol_shared SHARED ${lib_src}) - target_link_libraries(protocol_shared acl) +# target_link_libraries(protocol_shared acl) endif() SET_TARGET_PROPERTIES(protocol_shared PROPERTIES OUTPUT_NAME "protocol") diff --git a/lib_protocol/Makefile b/lib_protocol/Makefile index d586446e8..a2947a0f2 100644 --- a/lib_protocol/Makefile +++ b/lib_protocol/Makefile @@ -35,6 +35,9 @@ CHECKSYSRES = @echo "Unknow system type!";exit 1 UNIXNAME = $(shell uname -sm) UNIXTYPE = LINUX +STATIC_LIBNAME = libprotocol.a +SHARED_LIBNAME = libprotocol.so + ifeq ($(CC),) CC = gcc endif @@ -86,6 +89,7 @@ ifeq ($(findstring Darwin, $(UNIXNAME)), Darwin) -flto \ -Os UNIXTYPE = MACOSX + SHARED_LIBNAME = libprotocol.dylib endif # For Linux @@ -169,9 +173,6 @@ OBJS_DST = $(BASE_OBJ) $(HTTP_OBJ) $(ICMP_OBJ) $(SMTP_OBJ) LIB_ACL_PATH = ../lib_acl CFLAGS += -I $(LIB_ACL_PATH)/include -STATIC_LIBNAME = libprotocol.a -SHARED_LIBNAME = libprotocol.so - ########################################################### .PHONY = static shared clean