allow static build, mainly for deb and rpm pack

This commit is contained in:
Fancy Zhang
2020-07-05 22:30:36 +08:00
parent 9d2c26e765
commit 85e7bb3317
2 changed files with 7 additions and 6 deletions

View File

@@ -12,8 +12,8 @@ endif()
if (build_execsnoop_dl)
add_library(execsnoop MODULE execsnoop_share.cpp)
install(TARGETS execsnoop DESTINATION ${CMAKE_INSTALL_LIBDIR}/cgproxy/)
target_link_libraries(execsnoop PRIVATE ${LIBBPF} -lelf -lz)
else()
add_library(execsnoop execsnoop_share.cpp)
add_library(execsnoop STATIC execsnoop_share.cpp)
target_link_libraries(execsnoop PRIVATE ${LIBBPF} -l:libelf.a -l:libz.a)
endif()
target_link_libraries(execsnoop PRIVATE ${LIBBPF} -lelf -lz)

View File

@@ -1,4 +1,3 @@
find_package(Threads REQUIRED)
find_package(nlohmann_json REQUIRED)
include_directories(${PROJECT_SOURCE_DIR})
include_directories(${PROJECT_SOURCE_DIR}/execsnoop-kernel/)
@@ -14,10 +13,12 @@ else()
endif()
add_executable(main main.cpp common.cpp config.cpp cgroup_attach.cpp socket_client.cpp socket_server.cpp)
target_link_libraries(main PRIVATE nlohmann_json::nlohmann_json Threads::Threads ${DL_LIB} ${EXECSNOOP_LIB})
target_link_libraries(main PRIVATE nlohmann_json::nlohmann_json ${DL_LIB} ${EXECSNOOP_LIB})
set_target_properties(main PROPERTIES OUTPUT_NAME cgproxy)
install(TARGETS main RUNTIME)
if (build_static)
target_link_libraries(main PRIVATE -static-libgcc -static-libstdc++)
target_link_libraries(main PRIVATE -static -Wl,--whole-archive -lpthread -Wl,--no-whole-archive)
else()
target_link_libraries(main PRIVATE -lpthread)
endif()