From faa7a69c489d724fc3d1e28bc7eb1d4dfc62da87 Mon Sep 17 00:00:00 2001 From: ambrop7 Date: Wed, 13 Mar 2013 15:06:47 +0000 Subject: [PATCH] compile PIC versions of internal libraries, to be used by NCD plugins --- CMakeLists.txt | 17 ++++++++++ base/CMakeLists.txt | 3 +- flow/CMakeLists.txt | 4 +-- ncd/CMakeLists.txt | 76 +++++++++++++------------------------------ system/CMakeLists.txt | 4 +-- tuntap/CMakeLists.txt | 4 +-- 6 files changed, 47 insertions(+), 61 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 0999c2fb3..1476a0eaf 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -255,6 +255,23 @@ set(BUILDING_UDEVMONITOR 0) set(BUILDING_THREADWORK 0) set(BUILDING_RANDOM 0) +function(badvpn_add_library LIB_NAME LINK_BADVPN_LIBS LINK_SYS_LIBS LIB_SOURCES) + set(BADVPN_LIBS_EXEC) + set(BADVPN_LIBS_PLUGIN) + foreach(LIB ${LINK_BADVPN_LIBS}) + list(APPEND BADVPN_LIBS_EXEC "${LIB}") + list(APPEND BADVPN_LIBS_PLUGIN "${LIB}-plugin") + endforeach() + + add_library("${LIB_NAME}" STATIC ${LIB_SOURCES}) + target_link_libraries("${LIB_NAME}" ${BADVPN_LIBS_EXEC} ${LINK_SYS_LIBS}) + + add_library("${LIB_NAME}-plugin" STATIC ${LIB_SOURCES}) + target_link_libraries("${LIB_NAME}-plugin" ${BADVPN_LIBS_PLUGIN} ${LINK_SYS_LIBS}) + set_target_properties("${LIB_NAME}-plugin" PROPERTIES POSITION_INDEPENDENT_CODE YES) + set_target_properties("${LIB_NAME}-plugin" PROPERTIES COMPILE_FLAGS "-fvisibility=hidden") +endfunction() + # internal libraries add_subdirectory(base) add_subdirectory(system) diff --git a/base/CMakeLists.txt b/base/CMakeLists.txt index bde66e2d6..cf1f0f0fc 100644 --- a/base/CMakeLists.txt +++ b/base/CMakeLists.txt @@ -4,9 +4,10 @@ if (HAVE_SYSLOG_H) list(APPEND BASE_ADDITIONAL_SOURCES BLog_syslog.c) endif () -add_library(base +set(BASE_SOURCES DebugObject.c BLog.c BPending.c ${BASE_ADDITIONAL_SOURCES} ) +badvpn_add_library(base "" "" "${BASE_SOURCES}") diff --git a/flow/CMakeLists.txt b/flow/CMakeLists.txt index 7c4390b64..6cd82f6c2 100644 --- a/flow/CMakeLists.txt +++ b/flow/CMakeLists.txt @@ -1,4 +1,4 @@ -add_library(flow +set(FLOW_SOURCES PacketPassFairQueue.c PacketPassPriorityQueue.c PacketPassConnector.c @@ -28,4 +28,4 @@ add_library(flow StreamPassConnector.c PacketPassFifoQueue.c ) -target_link_libraries(flow base) +badvpn_add_library(flow "base" "" "${FLOW_SOURCES}") diff --git a/ncd/CMakeLists.txt b/ncd/CMakeLists.txt index 66ced3da0..8c384aed4 100644 --- a/ncd/CMakeLists.txt +++ b/ncd/CMakeLists.txt @@ -23,16 +23,10 @@ if (NOT EMSCRIPTEN) ) endif () - add_library(ncdinterfacemonitor - extra/NCDInterfaceMonitor.c - ) - target_link_libraries(ncdinterfacemonitor base system) + badvpn_add_library(ncdinterfacemonitor "base;system" "" extra/NCDInterfaceMonitor.c) + + badvpn_add_library(ncdrequest "base;system;ncdvalgenerator;ncdvalparser" "" extra/NCDRequestClient.c) - add_library(ncdrequest - extra/NCDRequestClient.c - ) - target_link_libraries(ncdrequest base system ncdvalgenerator ncdvalparser) - list(APPEND NCD_ADDITIONAL_SOURCES extra/NCDIfConfig.c extra/build_cmdline.c @@ -73,59 +67,33 @@ if (NOT EMSCRIPTEN) ) endif () -add_library(ncdtokenizer - NCDConfigTokenizer.c -) -target_link_libraries(ncdtokenizer base) +badvpn_add_library(ncdtokenizer "base" "" NCDConfigTokenizer.c) -add_library(ncdstringindex - NCDStringIndex.c -) +badvpn_add_library(ncdstringindex "base" "" NCDStringIndex.c) -add_library(ncdval - NCDVal.c -) -target_link_libraries(ncdval base ncdstringindex) +badvpn_add_library(ncdval "base;ncdstringindex" "" NCDVal.c) -add_library(ncdvalgenerator - NCDValGenerator.c -) -target_link_libraries(ncdvalgenerator base ncdval) +badvpn_add_library(ncdvalgenerator "base;ncdval" "" NCDValGenerator.c) -add_library(ncdvalparser - NCDValParser.c -) -target_link_libraries(ncdvalparser base ncdval ncdtokenizer ncdvalcons) +badvpn_add_library(ncdvalparser "base;ncdval;ncdtokenizer;ncdvalcons" "" NCDValParser.c) -add_library(ncdast - NCDAst.c -) +badvpn_add_library(ncdast "" "" NCDAst.c) -add_library(ncdconfigparser - NCDConfigParser.c -) -target_link_libraries(ncdconfigparser base ncdtokenizer ncdast) +badvpn_add_library(ncdconfigparser "base;ncdtokenizer;ncdast" "" NCDConfigParser.c) -add_library(ncdsugar - NCDSugar.c -) -target_link_libraries(ncdsugar ncdast) +badvpn_add_library(ncdsugar "ncdast" "" NCDSugar.c) -add_library(ncdvalcons - NCDValCons.c -) -target_link_libraries(ncdvalcons ncdval) +badvpn_add_library(ncdvalcons "ncdval" "" NCDValCons.c) -add_library(ncdbuildprogram - NCDBuildProgram.c -) -target_link_libraries(ncdbuildprogram base ncdast ncdconfigparser) +badvpn_add_library(ncdbuildprogram "base;ncdast;ncdconfigparser" "" NCDBuildProgram.c) + +badvpn_add_library(ncdobject "" "" NCDObject.c) -add_library(ncdinterpreter +badvpn_add_library(ncdmodule "base;ncdobject;ncdstringindex;ncdval" "" NCDModule.c) + +set(NCDINTERPRETER_SOURCES NCDInterpreter.c - NCDModule.c NCDModuleIndex.c - NCDObject.c NCDInterpProcess.c NCDInterpProg.c NCDPlaceholderDb.c @@ -180,10 +148,10 @@ add_library(ncdinterpreter modules/getenv.c ${NCD_ADDITIONAL_SOURCES} ) -target_link_libraries(ncdinterpreter - system flow flowextra ncdval ncdstringindex ncdvalgenerator ncdvalparser - ncdconfigparser ncdsugar ${NCD_ADDITIONAL_LIBS} -) +set(NCDINTERPRETER_LIBS + base system flow flowextra ncdval ncdstringindex ncdvalgenerator ncdvalparser + ncdconfigparser ncdsugar ncdobject ncdmodule ${NCD_ADDITIONAL_LIBS}) +badvpn_add_library(ncdinterpreter "${NCDINTERPRETER_LIBS}" "" "${NCDINTERPRETER_SOURCES}") if (BADVPN_USE_LINUX_INPUT) string(REPLACE " " ";" FLAGS_LIST "${CMAKE_C_FLAGS}") diff --git a/system/CMakeLists.txt b/system/CMakeLists.txt index 5ea820ad1..99f7333a0 100644 --- a/system/CMakeLists.txt +++ b/system/CMakeLists.txt @@ -37,8 +37,8 @@ elseif (BREACTOR_BACKEND STREQUAL "emscripten") list(APPEND BSYSTEM_ADDITIONAL_SOURCES BReactor_emscripten.c) endif () -add_library(system +set(SYSTEM_SOURCES BTime.c ${BSYSTEM_ADDITIONAL_SOURCES} ) -target_link_libraries(system base flow ${BSYSTEM_ADDITIONAL_LIBS}) +badvpn_add_library(system "base;flow" "${BSYSTEM_ADDITIONAL_LIBS}" "${SYSTEM_SOURCES}") diff --git a/tuntap/CMakeLists.txt b/tuntap/CMakeLists.txt index 880c4504b..fd451c1a2 100644 --- a/tuntap/CMakeLists.txt +++ b/tuntap/CMakeLists.txt @@ -3,8 +3,8 @@ if (WIN32) list(APPEND TUNTAP_ADDITIONAL_SOURCES tapwin32-funcs.c) endif () -add_library(tuntap +set(TUNTAP_SOURCES BTap.c ${TUNTAP_ADDITIONAL_SOURCES} ) -target_link_libraries(tuntap system flow) +badvpn_add_library(tuntap "system;flow" "" "${TUNTAP_SOURCES}")