From 01ad9901e95bee77006e8d13293e9b95dae11b7f Mon Sep 17 00:00:00 2001 From: gozfree Date: Sun, 16 Jul 2023 21:43:29 +0800 Subject: [PATCH] [cmake] fix issue #99 #100, check mingw on window --- build/cmake_env.inc | 4 +-- build/cmake_var.inc | 53 ++++++++++++++++++++++++++++++++ gear-lib/CMakeLists.txt | 4 ++- gear-lib/libposix/CMakeLists.txt | 4 ++- gear-lib/libposix/libposix.h | 20 +++++++----- gear-lib/libposix/libposix4win.h | 7 ++++- 6 files changed, 79 insertions(+), 13 deletions(-) create mode 100644 build/cmake_var.inc diff --git a/build/cmake_env.inc b/build/cmake_env.inc index 897e344f..757a2ee8 100644 --- a/build/cmake_env.inc +++ b/build/cmake_env.inc @@ -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 () diff --git a/build/cmake_var.inc b/build/cmake_var.inc new file mode 100644 index 00000000..89468d9f --- /dev/null +++ b/build/cmake_var.inc @@ -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}) + + diff --git a/gear-lib/CMakeLists.txt b/gear-lib/CMakeLists.txt index 698f321d..34776fbd 100644 --- a/gear-lib/CMakeLists.txt +++ b/gear-lib/CMakeLists.txt @@ -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 () diff --git a/gear-lib/libposix/CMakeLists.txt b/gear-lib/libposix/CMakeLists.txt index 574c3cbf..001c649a 100644 --- a/gear-lib/libposix/CMakeLists.txt +++ b/gear-lib/libposix/CMakeLists.txt @@ -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) diff --git a/gear-lib/libposix/libposix.h b/gear-lib/libposix/libposix.h index aeee52c7..0967c083 100644 --- a/gear-lib/libposix/libposix.h +++ b/gear-lib/libposix/libposix.h @@ -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 diff --git a/gear-lib/libposix/libposix4win.h b/gear-lib/libposix/libposix4win.h index 5487691b..79df9956 100644 --- a/gear-lib/libposix/libposix4win.h +++ b/gear-lib/libposix/libposix4win.h @@ -22,18 +22,23 @@ #ifndef LIBPOSIX4WIN_H #define LIBPOSIX4WIN_H +#ifndef ENV_MINGW #include "msvclibx.h" +#endif #include #include +#include #include #include -#include #include #include #include +#include +#ifndef ENV_MINGW #include "pthreads4w/pthread.h" #include "pthreads4w/semaphore.h" +#endif #include "kernel_list_win32.h" #ifdef __cplusplus