From 17d71d9ef8adad095b8b06182bc1febca02899d0 Mon Sep 17 00:00:00 2001 From: Maximilien Siavelis <maximilien.siavelis@simulease.com> Date: 周五, 05 1月 2018 09:10:37 +0800 Subject: [PATCH] fix compilation with MINGW --- src/tools/bootstrap/CMakeLists.txt | 13 +++++++++++-- src/tools/base_lib/CMakeLists.txt | 6 +++--- src/library/os/win/os-win.c | 4 ++++ src/tools/base_lib/CryptoHelper.cpp | 4 ++-- CMakeLists.txt | 19 ++++++++++++------- src/library/base/StringUtils.cpp | 3 ++- src/library/pc-identifiers.c | 4 ++++ 7 files changed, 38 insertions(+), 15 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 74964b0..8c69513 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -29,7 +29,7 @@ set(RELEASE_BUILD 0) endif(CMAKE_BUILD_TYPE) -if(WIN32) +if(MSVC) SET(PLATFORM_LIBS "") include(target_arch) @@ -43,7 +43,7 @@ endif() SET(CMAKE_FIND_LIBRARY_SUFFIXES .lib ) #${CMAKE_FIND_LIBRARY_SUFFIXES} add_definitions("/D_CRT_SECURE_NO_WARNINGS") -else(WIN32) +else(MSVC) SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pipe -fmessage-length=0 -std=c++11 -Wuninitialized -fPIC") #-Wall SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -pipe -fmessage-length=0 -Wall -Wuninitialized -fPIC") #use static libraries in release to make it easier to distribute it @@ -59,7 +59,7 @@ IF(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT) SET(CMAKE_INSTALL_PREFIX "/usr/local" CACHE PATH "Install path prefix" FORCE) ENDIF(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT) -endif(WIN32) +endif(MSVC) set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS $<$<CONFIG:Debug>:_DEBUG>) @@ -75,12 +75,17 @@ add_definitions(-DBOOST_ALL_NO_LIB) #Disable Boost Microsoft magic, all dependencies are handled by cmake add_definitions(-DBOOST_LIB_DIAGNOSTIC) #Check it is really disabled -if(NOT WIN32) +if(NOT MSVC) #find a static version of openssl crypto library find_package(OpenSSL REQUIRED) include_directories(${OPENSSL_INCLUDE_DIR}) - list(APPEND EXTERNAL_LIBS ${OPENSSL_CRYPTO_LIBRARY}) - MESSAGE(STATUS "Found openssl version ${OPENSSL_VERSION}") + if(MINGW) + list(APPEND EXTERNAL_LIBS "-lcrypto -liphlpapi") + else(MINGW) + list(APPEND EXTERNAL_LIBS ${OPENSSL_CRYPTO_LIBRARY}) + endif(MINGW) + + MESSAGE(STATUS "Found openssl version ${OPENSSL_VERSION} ") #Zlib required when openssl version < 1.0.1f find_package(ZLIB REQUIRED) @@ -94,7 +99,7 @@ list(APPEND EXTERNAL_LIBS ${DBUS_LIBRARIES}) endif(USE_DBUS_IDENTIFIER) list(APPEND EXTERNAL_LIBS dl) -endif(NOT WIN32) +endif(NOT MSVC) FIND_PACKAGE(Doxygen) diff --git a/src/library/base/StringUtils.cpp b/src/library/base/StringUtils.cpp index 3d09b99..97675b7 100644 --- a/src/library/base/StringUtils.cpp +++ b/src/library/base/StringUtils.cpp @@ -11,8 +11,9 @@ #include <string> #include <cstring> #include <algorithm> +#include <stdexcept> -#ifdef WIN32 +#ifdef _WIN32 #include <time.h> //mktime under windows #endif diff --git a/src/library/os/win/os-win.c b/src/library/os/win/os-win.c index 2605df1..d3899e7 100644 --- a/src/library/os/win/os-win.c +++ b/src/library/os/win/os-win.c @@ -1,4 +1,8 @@ +#ifdef __MINGW32__ +#include <windows.h> +#else #include <Windows.h> +#endif #include <iphlpapi.h> //definition of size_t #include <stdlib.h> diff --git a/src/library/pc-identifiers.c b/src/library/pc-identifiers.c index e14c7a5..6b4144b 100644 --- a/src/library/pc-identifiers.c +++ b/src/library/pc-identifiers.c @@ -16,8 +16,12 @@ #include <stdbool.h> #include <valgrind/memcheck.h> #else +#ifdef __MINGW32__ +#include <windows.h> +#else #include <Windows.h> #endif +#endif static FUNCTION_RETURN generate_disk_pc_id(PcIdentifier * identifiers, unsigned int * num_identifiers, bool use_label); diff --git a/src/tools/base_lib/CMakeLists.txt b/src/tools/base_lib/CMakeLists.txt index 157964d..dd1df79 100644 --- a/src/tools/base_lib/CMakeLists.txt +++ b/src/tools/base_lib/CMakeLists.txt @@ -1,17 +1,17 @@ -if(WIN32) +if(MSVC) ADD_LIBRARY( tools_base STATIC CryptoHelper.cpp win/CryptoHelperWindows.cpp ) -else(WIN32) +else(MSVC) ADD_LIBRARY( tools_base STATIC CryptoHelper.cpp linux/CryptoHelperLinux.cpp ) -ENDIF(WIN32) +ENDIF(MSVC) target_link_libraries( tools_base diff --git a/src/tools/base_lib/CryptoHelper.cpp b/src/tools/base_lib/CryptoHelper.cpp index 07d0348..afa566d 100644 --- a/src/tools/base_lib/CryptoHelper.cpp +++ b/src/tools/base_lib/CryptoHelper.cpp @@ -1,6 +1,6 @@ #include <memory> #include "CryptoHelper.h" -#ifdef __unix__ +#ifndef _MSC_VER #include"linux/CryptoHelperLinux.h" #else #include"win/CryptoHelperWindows.h" @@ -10,7 +10,7 @@ namespace license { unique_ptr<CryptoHelper> CryptoHelper::getInstance() { -#ifdef __unix__ +#ifndef _MSC_VER unique_ptr<CryptoHelper> ptr((CryptoHelper*) new CryptoHelperLinux()); #else unique_ptr<CryptoHelper> ptr((CryptoHelper*) new CryptoHelperWindows()); diff --git a/src/tools/bootstrap/CMakeLists.txt b/src/tools/bootstrap/CMakeLists.txt index 1e55e6a..856fc5f 100644 --- a/src/tools/bootstrap/CMakeLists.txt +++ b/src/tools/bootstrap/CMakeLists.txt @@ -13,12 +13,21 @@ ) # add the command to generate the source code + +if(MINGW) +add_custom_command ( + OUTPUT "${CMAKE_BINARY_DIR}/private-key.h" "${CMAKE_BINARY_DIR}/public-key.h" + COMMAND ./bootstrap.exe "${CMAKE_BINARY_DIR}/private-key.h" "${CMAKE_BINARY_DIR}/public-key.h" + WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} + DEPENDS bootstrap) +else(MINGW) add_custom_command ( OUTPUT "${CMAKE_BINARY_DIR}/private-key.h" "${CMAKE_BINARY_DIR}/public-key.h" COMMAND bootstrap "${CMAKE_BINARY_DIR}/private-key.h" "${CMAKE_BINARY_DIR}/public-key.h" WORKING_DIRECTORY ${CMAKE_BINARY_DIR} - DEPENDS bootstrap -) + DEPENDS bootstrap) +endif(MINGW) + add_custom_target(private_key DEPENDS "${CMAKE_BINARY_DIR}/private-key.h") add_custom_target(public_key DEPENDS "${CMAKE_BINARY_DIR}/public-key.h") -- Gitblit v1.9.1