diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..1b78cea --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,89 @@ +cmake_minimum_required(VERSION 3.15) +project(futils VERSION 1.0) + +set(DEFS "_FILE_OFFSET_BITS=64") + +list(APPEND LIB_SOURCES + src/hash.c + src/mbox.c + src/systimetools.c + src/timetools.c + src/random.c + src/varint.c +) + +list(APPEND LIB_DEPENDS + ulog +) + +if(UNIX) + list(APPEND LIB_SOURCES + src/inotify.c + ) + if(ANDROID) + list(APPEND LIB_SOURCES + src/string.c + ) + else() + list(APPEND LIB_SOURCES + src/dynmbox.c + ) + endif() + +else() + list(APPEND LIB_SOURCES + src/dynmbox.c + ) + +endif() + + + +if(NOT WIN32) + list(APPEND LIB_SOURCES + src/fdutils.c + src/fs.c + src/safew.c + src/synctools.c + ) + +else() + list(APPEND LIB_DEPENDS + ws2_32 + ) +endif() + +add_library(${PROJECT_NAME} SHARED ${LIB_SOURCES}) +target_compile_features(${PROJECT_NAME} INTERFACE cxx_std_11) + +# checks if set up rpath exists for install +if(COMMAND set_up_rpath) + set_up_rpath() +else() + message("Set up rpath not defined!") +endif() + +option(BUILD_SHARED_LIBS "Build using shared libraries" ON) +set_target_properties(${PROJECT_NAME} PROPERTIES + POSITION_INDEPENDENT_CODE ${BUILD_SHARED_LIBS} +) + +target_include_directories(${PROJECT_NAME} PUBLIC + $ + $ +) + +target_compile_definitions(${PROJECT_NAME} PRIVATE ${DEFS}) + +target_link_libraries(${PROJECT_NAME} + PRIVATE + ${LIB_DEPENDS} + ) + +install(TARGETS ${PROJECT_NAME} + EXPORT ${PROJECT_NAME}-targets + PUBLIC_HEADER DESTINATION include + ARCHIVE DESTINATION lib + LIBRARY DESTINATION lib + RUNTIME DESTINATION bin +) diff --git a/src/fdutils.c b/src/fdutils.c index 3ebea93..6b303f1 100644 --- a/src/fdutils.c +++ b/src/fdutils.c @@ -35,6 +35,14 @@ #include "futils/fdutils.h" +#ifdef _WIN32 +#define FD_CLOEXEC 1 +#define F_GETFD 1 /**< Get file descriptor flags */ +#define F_SETFD 2 /**< Set file descriptor flags */ +#define F_GETFL 3 /**< Get file status flags */ +#define F_SETFL 4 /**< Set file status flags */ +#endif + int fd_set_close_on_exec(int fd) { int old, ret; diff --git a/src/mbox.c b/src/mbox.c index 4f709cc..46c4c20 100644 --- a/src/mbox.c +++ b/src/mbox.c @@ -29,6 +29,7 @@ * ******************************************************************************/ +#include #include #include #include diff --git a/src/random.c b/src/random.c index 4ec48e6..7f56c0a 100644 --- a/src/random.c +++ b/src/random.c @@ -64,7 +64,7 @@ ULOG_DECLARE_TAG(futils_random); #elif defined(__GNUC__) && defined(__GLIBC__) # define thread_local __thread # define HAVE_THREAD_LOCAL 1 -#elif defined(_WIN32) +#elif defined(_WIN32) && (!defined(__GNUC__)) # define thread_local __declspec(thread) # define HAVE_THREAD_LOCAL 1 #else diff --git a/src/string.c b/src/string.c index 404a6d8..0033c8a 100644 --- a/src/string.c +++ b/src/string.c @@ -31,6 +31,7 @@ #include "futils/string.h" +#include #include #include #include diff --git a/src/systimetools.c b/src/systimetools.c index df0bd10..25150d0 100644 --- a/src/systimetools.c +++ b/src/systimetools.c @@ -36,6 +36,7 @@ #endif #include +#include #include #include #include "futils/systimetools.h"