Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add CMake compatibility for MinGW #1

Open
wants to merge 18 commits into
base: master
Choose a base branch
from
89 changes: 89 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>
)

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
)
8 changes: 8 additions & 0 deletions src/fdutils.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions src/mbox.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
*
******************************************************************************/

#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
Expand Down
2 changes: 1 addition & 1 deletion src/random.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/string.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@

#include "futils/string.h"

#include <string.h>
#include <errno.h>
#include <iconv.h>
#include <wchar.h>
Expand Down
1 change: 1 addition & 0 deletions src/systimetools.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
#endif

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include "futils/systimetools.h"
Expand Down