commit 7092917ce44b97379c64f1beba30ee267101b437
parent fac8495082d91c28e69bf68f2fcf365933cfe628
Author: vaplv <vaplv@free.fr>
Date: Sun, 2 Feb 2014 01:20:23 +0100
Make it [cross] compile on mingw
Diffstat:
3 files changed, 26 insertions(+), 12 deletions(-)
diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt
@@ -15,19 +15,20 @@ find_package(OpenMP)
################################################################################
# Setup compile flags/parameters
################################################################################
-if(CMAKE_SIZEOF_VOID_P EQUAL 8)
+if(NOT MINGW AND CMAKE_SIZEOF_VOID_P EQUAL 8)
set(BUILD_32-BIT OFF CACHE BOOL "Force code generation for 32-bit environment")
-endif(CMAKE_SIZEOF_VOID_P EQUAL 8)
+endif(NOT MINGW AND CMAKE_SIZEOF_VOID_P EQUAL 8)
set(C_FLAGS "-pedantic -std=c89 -fvisibility=hidden -fstrict-aliasing")
set(C_FLAGS_WARN "-Wall -Wextra -Wcast-align -Wmissing-declarations -Wmissing-prototypes -Wconversion")
set(C_FLAGS_LINK "-Wl,--no-undefined")
-if(CMAKE_HOST_UNIX)
+
+if(NOT MINGW)
set(C_FLAGS_UNIX "-fPIC")
-endif(CMAKE_HOST_UNIX)
-if(BUILD_32-BIT)
- set(C_FLAGS "${C_FLAGS} -m32")
-endif(BUILD_32-BIT)
+ if(BUILD_32-BIT)
+ set(C_FLAGS "${C_FLAGS} -m32")
+ endif(BUILD_32-BIT)
+endif(NOT MINGW)
set(CMAKE_C_FLAGS "${C_FLAGS} ${C_FLAGS_UNIX} ${C_FLAGS_WARN} ${C_FLAGS_LINK}")
set(CMAKE_C_FLAGS_DEBUG "-g -DDEBUG")
@@ -35,7 +36,7 @@ set(CMAKE_C_FLAGS_RELEASE "-O2 -DNDEBUG")
if(CMAKE_USE_PTHREADS_INIT)
add_definitions(-DRSYS_USE_PTHREADS)
-endif()
+endif(CMAKE_USE_PTHREADS_INIT)
################################################################################
# Helper macros
@@ -100,9 +101,9 @@ set_target_properties(rsys PROPERTIES
VERSION ${RSYS_VERSION}
SOVERSION ${VERSION_MAJOR})
-if(CMAKE_HOST_UNIX)
+if(NOT MINGW)
target_link_libraries(rsys dl)
-endif(CMAKE_HOST_UNIX)
+endif(NOT MINGW)
################################################################################
# Add tests
@@ -132,7 +133,7 @@ else(NOT OPENMP_FOUND)
new_test(test_mutex rsys)
set_target_properties(test_mutex test_condition PROPERTIES COMPILE_FLAGS ${OpenMP_C_FLAGS})
set_target_properties(test_mutex test_condition PROPERTIES LINK_FLAGS ${OpenMP_C_FLAGS})
-endif()
+endif(NOT OPENMP_FOUND)
################################################################################
# Define output & install directories
diff --git a/cmake/toolchain/x86_64-w64-mingw32-toolchain.cmake b/cmake/toolchain/x86_64-w64-mingw32-toolchain.cmake
@@ -0,0 +1,13 @@
+set(CMAKE_SYSTEM_NAME Windows)
+set(CMAKE_C_COMPILER x86_64-w64-mingw32-gcc)
+set(CMAKE_RC_COMPILER x86_64-w64-mingw32-windres)
+
+# here is the target environment located
+SET(CMAKE_FIND_ROOT_PATH /usr/x86_64-w64-mingw32/sys-root/mingw)
+
+# adjust the default behaviour of the FIND_XXX() commands:
+# search headers and libraries in the target environment, search
+# programs in the host environment
+set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
+set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
+set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
diff --git a/src/test_time.c b/src/test_time.c
@@ -16,7 +16,7 @@ main(int argc, char** argv)
time_sub(&res, &end, &start);
time = time_val(&res, TIME_NSEC);
- CHECK(time > 0, 1 );
+ CHECK(time >= 0, 1 );
CHECK(time_val(&res, TIME_USEC), time / 1000);
CHECK(time_val(&res, TIME_MSEC), time / 1000000);
CHECK(time_val(&res, TIME_SEC), time / 1000000000);