Repository: celix Updated Branches: refs/heads/develop 978d668e9 -> 147e8bfed
CELIX-385: Adds flags for etcdlib to make it possible to skip curl init. Removes celix prefix in header name/loc. Makes etcdlib CMakelists.txt a optional top level CMake file Project: http://git-wip-us.apache.org/repos/asf/celix/repo Commit: http://git-wip-us.apache.org/repos/asf/celix/commit/950788f1 Tree: http://git-wip-us.apache.org/repos/asf/celix/tree/950788f1 Diff: http://git-wip-us.apache.org/repos/asf/celix/diff/950788f1 Branch: refs/heads/develop Commit: 950788f1411522a57001e61d3cdbecf3b9d62793 Parents: 978d668 Author: Pepijn Noltes <[email protected]> Authored: Tue Dec 20 20:28:55 2016 +0100 Committer: Pepijn Noltes <[email protected]> Committed: Tue Dec 20 20:28:55 2016 +0100 ---------------------------------------------------------------------- etcdlib/CMakeLists.txt | 28 +++++++++++++++++++++++----- etcdlib/private/src/etcd.c | 10 ++++++++-- etcdlib/public/include/etcd.h | 17 +++++++++++++---- 3 files changed, 44 insertions(+), 11 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/celix/blob/950788f1/etcdlib/CMakeLists.txt ---------------------------------------------------------------------- diff --git a/etcdlib/CMakeLists.txt b/etcdlib/CMakeLists.txt index a9a0564..5c078f1 100644 --- a/etcdlib/CMakeLists.txt +++ b/etcdlib/CMakeLists.txt @@ -15,11 +15,29 @@ # specific language governing permissions and limitations # under the License. + +if (NOT PROJECT_SOURCE_DIR) + #If PROJECT_SOURCE_DIR is not defined, this CMakeLists will + #act as a top level project. Making the etcdlib useable + #stand-alone + + cmake_minimum_required (VERSION 3.2) + project(ETCDLIB + VERSION 1.0.0 + LANGUAGES C CXX + ) + + include(GNUInstallDirs) + set(ETCDLIB_CMP ${CMAKE_INSTALL_DEFAULT_COMPONENT_NAME}) +else() + set(ETCDLIB_CMP framework) +endif () + find_package(CURL REQUIRED) find_package(Jansson REQUIRED) include_directories( - ${CURL_INCLUDE_DIR} + ${CURL_INCLUDE_DIRS} ${JANSSON_INCLUDE_DIRS} private/include public/include @@ -30,9 +48,9 @@ add_library(etcdlib SHARED ) set_target_properties(etcdlib PROPERTIES "SOVERSION" 1) -target_link_libraries(etcdlib ${CURL_LIBRARIES} ${JANSSON_LIBRARY}) +target_link_libraries(etcdlib ${CURL_LIBRARIES} ${JANSSON_LIBRARIES}) -add_library(etcdlib_static STATIC +add_library(etcdlib_static STATIC private/src/etcd.c ) @@ -40,6 +58,6 @@ set_target_properties(etcdlib_static PROPERTIES "SOVERSION" 1) target_link_libraries(etcdlib_static ${CURL_LIBRARIES} ${JANSSON_LIBRARY}) -install(TARGETS etcdlib etcdlib_static DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT framework) +install(TARGETS etcdlib etcdlib_static DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT ${ETCDLIB_CMP}) FILE(GLOB files "public/include/*.h") -INSTALL(FILES ${files} DESTINATION include/celix/etcdlib COMPONENT framework) +INSTALL(FILES ${files} DESTINATION include/etcdlib COMPONENT framework) http://git-wip-us.apache.org/repos/asf/celix/blob/950788f1/etcdlib/private/src/etcd.c ---------------------------------------------------------------------- diff --git a/etcdlib/private/src/etcd.c b/etcdlib/private/src/etcd.c index 9a98010..e08db58 100644 --- a/etcdlib/private/src/etcd.c +++ b/etcdlib/private/src/etcd.c @@ -64,11 +64,17 @@ static size_t WriteMemoryCallback(void *contents, size_t size, size_t nmemb, voi /** * etcd_init */ -int etcd_init(const char* server, int port) { +int etcd_init(const char* server, int port, int flags) { + int status = 0; etcd_server = server; etcd_port = port; - return curl_global_init(CURL_GLOBAL_ALL) != 0; + if ((flags & ETCDLIB_NO_CURL_INITIALIZATION) == 0) { + //NO_CURL_INITIALIZATION flag not set + status = curl_global_init(CURL_GLOBAL_ALL); + } + + return status; } http://git-wip-us.apache.org/repos/asf/celix/blob/950788f1/etcdlib/public/include/etcd.h ---------------------------------------------------------------------- diff --git a/etcdlib/public/include/etcd.h b/etcdlib/public/include/etcd.h index ff0a214..ba05ff7 100644 --- a/etcdlib/public/include/etcd.h +++ b/etcdlib/public/include/etcd.h @@ -17,20 +17,29 @@ *under the License. */ -#ifndef CELIX_ETCDLIB_H_ -#define CELIX_ETCDLIB_H_ +#ifndef ETCDLIB_H_ +#define ETCDLIB_H_ #include <stdbool.h> +/* + * If set etcdlib will _not_ initialize curl + * using curl_global_init. Note that + * curl_global_init can be called mutiple + * times, but is _not_ thread-safe. + */ +#define ETCDLIB_NO_CURL_INITIALIZATION (1) + typedef void (*etcd_key_value_callback) (const char *key, const char *value, void* arg); /** * @desc Initialize the ETCD-LIB with the server/port where Etcd can be reached. * @param const char* server. String containing the IP-number of the server. * @param int port. Port number of the server. + * @param int flags. bitwise flags to control etcdlib initialization. * @return 0 on success, non zero otherwise. */ -int etcd_init(const char* server, int port); +int etcd_init(const char* server, int port, int flags); /** * @desc Retrieve a single value from Etcd. @@ -91,4 +100,4 @@ int etcd_del(const char* key); */ int etcd_watch(const char* key, long long index, char** action, char** prevValue, char** value, char** rkey, long long* modifiedIndex); -#endif /*CELIX_ETCDLIB_H_ */ +#endif /*ETCDLIB_H_ */
