Skip to content

Commit

Permalink
[cmake] fix issue #99 #100, check mingw on window
Browse files Browse the repository at this point in the history
  • Loading branch information
gozfree committed Jul 16, 2023
1 parent 5a97d29 commit 01ad990
Show file tree
Hide file tree
Showing 6 changed files with 79 additions and 13 deletions.
4 changes: 2 additions & 2 deletions build/cmake_env.inc
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ IF ("${CMAKE_SYSTEM_NAME}" MATCHES "Linux")
ELSEIF ("${CMAKE_SYSTEM_NAME}" MATCHES "Windows")
SET(OS_WINDOWS TRUE)
MESSAGE(STATUS " Target OS: WINDOWS")
ELSEIF (("${CMAKE_SYSTEM_NAME}" MATCHES "MSYS") OR ("${CMAKE_SYSTEM_NAME}" MATCHES "MINGW32"))
ELSEIF (("${CMAKE_SYSTEM_NAME}" MATCHES "MINGW32") OR ("${CMAKE_SYSTEM_NAME}" MATCHES "MINGW64"))
SET(OS_WINDOWS TRUE)
SET(ENV_MINGW TRUE)
MESSAGE(STATUS " Target OS: WINDOWS with MINGW")
MESSAGE(STATUS " Target OS: WINDOWS with MINGW32/64")
ELSE ()
MESSAGE(STATUS " Target OS: unknown ${CMAKE_SYSTEM_NAME}")
EXIT ()
Expand Down
53 changes: 53 additions & 0 deletions build/cmake_var.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@

MESSAGE(STATUS "ANDROID " ${CMAKE_LIBRARY_ARCHITECTURE_REGEX})
MESSAGE(STATUS "APPLE " ${ANDROID})
MESSAGE(STATUS "BORLAND " ${APPLE})
MESSAGE(STATUS "BSD " ${BORLAND})
MESSAGE(STATUS "CMAKE_ANDROID_NDK_VERSION " ${BSD})
MESSAGE(STATUS "CMAKE_CL_64 " ${CMAKE_ANDROID_NDK_VERSION})
MESSAGE(STATUS "CMAKE_COMPILER_2005 " ${CMAKE_CL_64})
MESSAGE(STATUS "CMAKE_HOST_APPLE " ${CMAKE_COMPILER_2005})
MESSAGE(STATUS "CMAKE_HOST_BSD " ${CMAKE_HOST_APPLE})
MESSAGE(STATUS "CMAKE_HOST_LINUX " ${CMAKE_HOST_BSD})
MESSAGE(STATUS "CMAKE_HOST_SOLARIS " ${CMAKE_HOST_LINUX})
MESSAGE(STATUS "CMAKE_HOST_SYSTEM " ${CMAKE_HOST_SOLARIS})
MESSAGE(STATUS "CMAKE_HOST_SYSTEM_NAME " ${CMAKE_HOST_SYSTEM})
MESSAGE(STATUS "CMAKE_HOST_SYSTEM_PROCESSOR " ${CMAKE_HOST_SYSTEM_NAME})
MESSAGE(STATUS "CMAKE_HOST_SYSTEM_VERSION " ${CMAKE_HOST_SYSTEM_PROCESSOR})
MESSAGE(STATUS "CMAKE_HOST_UNIX " ${CMAKE_HOST_SYSTEM_VERSION})
MESSAGE(STATUS "CMAKE_HOST_WIN32 " ${CMAKE_HOST_UNIX})
MESSAGE(STATUS "CMAKE_LIBRARY_ARCHITECTURE " ${CMAKE_HOST_WIN32})
MESSAGE(STATUS "CMAKE_LIBRARY_ARCHITECTURE_REGEX " ${CMAKE_LIBRARY_ARCHITECTURE})
MESSAGE(STATUS "CMAKE_OBJECT_PATH_MAX " ${CMAKE_OBJECT_PATH_MAX})
MESSAGE(STATUS "CMAKE_SYSTEM " ${CMAKE_SYSTEM})
MESSAGE(STATUS "CMAKE_SYSTEM_NAME " ${CMAKE_SYSTEM_NAME})
MESSAGE(STATUS "CMAKE_SYSTEM_PROCESSOR " ${CMAKE_SYSTEM_PROCESSOR})
MESSAGE(STATUS "CMAKE_SYSTEM_VERSION " ${CMAKE_SYSTEM_VERSION})
MESSAGE(STATUS "CYGWIN " ${CYGWIN})
MESSAGE(STATUS "GHSMULTI " ${GHSMULTI})
MESSAGE(STATUS "IOS " ${IOS})
MESSAGE(STATUS "LINUX " ${LINUX})
MESSAGE(STATUS "MINGW " ${MINGW})
MESSAGE(STATUS "MSVC " ${MSVC})
MESSAGE(STATUS "MSVC10 " ${MSVC10})
MESSAGE(STATUS "MSVC11 " ${MSVC11})
MESSAGE(STATUS "MSVC12 " ${MSVC12})
MESSAGE(STATUS "MSVC14 " ${MSVC14})
MESSAGE(STATUS "MSVC60 " ${MSVC60})
MESSAGE(STATUS "MSVC70 " ${MSVC70})
MESSAGE(STATUS "MSVC71 " ${MSVC71})
MESSAGE(STATUS "MSVC80 " ${MSVC80})
MESSAGE(STATUS "MSVC90 " ${MSVC90})
MESSAGE(STATUS "MSVC_IDE " ${MSVC_IDE})
MESSAGE(STATUS "MSVC_TOOLSET_VERSION " ${MSVC_TOOLSET_VERSION})
MESSAGE(STATUS "MSVC_VERSION " ${MSVC_VERSION})
MESSAGE(STATUS "MSYS " ${MSYS})
MESSAGE(STATUS "UNIX " ${UNIX})
MESSAGE(STATUS "WIN32 " ${WIN32})
MESSAGE(STATUS "WINCE " ${WINCE})
MESSAGE(STATUS "WINDOWS_PHONE " ${WINDOWS_PHONE})
MESSAGE(STATUS "WINDOWS_STORE " ${WINDOWS_STORE})
MESSAGE(STATUS "XCODE " ${XCODE})
MESSAGE(STATUS "XCODE_VERSION " ${XCODE_VERSION})


4 changes: 3 additions & 1 deletion gear-lib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ ENDIF ()

SET(POSIX_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/libposix/)
IF (DEFINED OS_WINDOWS)
IF (NOT DEFINED ENV_MINGW)
IF (DEFINED ENV_MINGW)
add_compile_definitions(ENV_MINGW=true)
ELSE ()
LIST(APPEND POSIX_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/libposix/pthreads4w/)
LIST(APPEND POSIX_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/libposix/MsvcLibX/include/)
ENDIF ()
Expand Down
4 changes: 3 additions & 1 deletion gear-lib/libposix/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ IF (DEFINED OS_LINUX)
LIST(APPEND SOURCE_FILES libposix4nix.c)
ELSEIF (DEFINED OS_WINDOWS)

IF (NOT DEFINED ENV_MINGW)
IF (DEFINED ENV_MINGW)
add_compile_definitions(ENV_MINGW=true)
ELSE ()
INCLUDE_DIRECTORIES(pthreads4w/ MsvcLibX/include)
AUX_SOURCE_DIRECTORY(MsvcLibX MSVCLIBX_SRC)
LIST(APPEND PTHREADS4W_SRC pthreads4w/pthread.c)
Expand Down
20 changes: 12 additions & 8 deletions gear-lib/libposix/libposix.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,21 +28,25 @@ extern "C" {

#define LIBPOSIX_VERSION "0.1.1"

/******************************************************************************
* OS_WINDOWS
* support MSVC, msys2, mingw32/64 on Windows
******************************************************************************/
#if defined (__WIN32__) || defined (WIN32) || defined (_MSC_VER) || defined (ENV_MINGW)
#define OS_WINDOWS
#define GEAR_API __declspec(dllexport)
#include "libposix4win.h"


/******************************************************************************
* OS_LINUX
* support UNIX on Linux
******************************************************************************/
#if defined (__linux__) || defined (__CYGWIN__)
#elif defined (__linux__) /* || defined (__CYGWIN__) */
#define OS_LINUX
#define GEAR_API __attribute__((visibility("default")))
#include "libposix4nix.h"

/******************************************************************************
* OS_WINDOWS
******************************************************************************/
#elif defined (__WIN32__) || defined (WIN32) || defined (_MSC_VER)
#define OS_WINDOWS
#define GEAR_API __declspec(dllexport)
#include "libposix4win.h"

/******************************************************************************
* OS_APPLE
Expand Down
7 changes: 6 additions & 1 deletion gear-lib/libposix/libposix4win.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,23 @@
#ifndef LIBPOSIX4WIN_H
#define LIBPOSIX4WIN_H

#ifndef ENV_MINGW
#include "msvclibx.h"
#endif

#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <string.h>
#include <stdbool.h>
#include <windows.h>
#include <winsock2.h>
#include <ws2tcpip.h>
#include <tlhelp32.h>
#include <windows.h>
#ifndef ENV_MINGW
#include "pthreads4w/pthread.h"
#include "pthreads4w/semaphore.h"
#endif
#include "kernel_list_win32.h"

#ifdef __cplusplus
Expand Down

0 comments on commit 01ad990

Please sign in to comment.