From 8306d2fc67b31aa36df2cb3e4fde3f9907330b9e Mon Sep 17 00:00:00 2001 From: "Sergey G. Brester" Date: Fri, 15 Oct 2021 14:49:24 +0200 Subject: [PATCH 1/2] cmake/boost.cmake: fixes search path for (linked) boost package if build in sub-directory (take a look into `include/boost` before `include`); otherwise `cd build/Release_x64; cmake -S ../.. -B .` may fail, because it cannot find linked boost folder. --- cmake/boost.cmake | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/cmake/boost.cmake b/cmake/boost.cmake index 44b4e8ba6..bb239a7fc 100644 --- a/cmake/boost.cmake +++ b/cmake/boost.cmake @@ -13,15 +13,19 @@ set(BOOST_NO_BOOST_CMAKE ON) unset(Boost_INCLUDE_DIR CACHE) # we might have boost in tree, so provide a hint and try again -set(BOOST_INCLUDEDIR "${PROJECT_SOURCE_DIR}/include") +set(BOOST_INCLUDEDIR "${PROJECT_SOURCE_DIR}/include/boost") find_package(Boost ${BOOST_MINVERSION} QUIET) if(NOT Boost_FOUND) + set(BOOST_INCLUDEDIR "${PROJECT_SOURCE_DIR}/include") + find_package(Boost ${BOOST_MINVERSION} QUIET) + if(NOT Boost_FOUND) # otherwise check for Boost installed on the system unset(BOOST_INCLUDEDIR) find_package(Boost ${BOOST_MINVERSION} QUIET) if(NOT Boost_FOUND) message(FATAL_ERROR "Boost ${BOOST_MINVERSION} or later not found. Either install system packages if available, extract Boost headers to ${CMAKE_SOURCE_DIR}/include, or set the CMake BOOST_ROOT variable.") endif() + endif() endif() message(STATUS "Boost version: ${Boost_MAJOR_VERSION}.${Boost_MINOR_VERSION}.${Boost_SUBMINOR_VERSION}") From f65a193e24c47900d3b446c3343a9268327321f0 Mon Sep 17 00:00:00 2001 From: "Sergey G. Brester" Date: Fri, 15 Oct 2021 18:41:40 +0200 Subject: [PATCH 2/2] support newest mingw toolchain (gcc 10/11), _WIN32 is not a sign of MSVC anymore (using _MSC_VER instead) --- src/ue2common.h | 16 ++++++++-------- src/util/bitutils.h | 12 ++++++------ src/util/cpuid_inline.h | 4 ++-- 3 files changed, 16 insertions(+), 16 deletions(-) diff --git a/src/ue2common.h b/src/ue2common.h index 5705af7be..ab09dfde8 100644 --- a/src/ue2common.h +++ b/src/ue2common.h @@ -46,7 +46,7 @@ #include /* ick */ -#if defined(_WIN32) +#if defined(_MSC_VER) #define ALIGN_ATTR(x) __declspec(align(x)) #else #define ALIGN_ATTR(x) __attribute__((aligned((x)))) @@ -66,7 +66,7 @@ typedef signed int s32; /* We append the 'a' for aligned, since these aren't common, garden variety * 64 bit values. The alignment is necessary for structs on some platforms, * so we don't end up performing accidental unaligned accesses. */ -#if defined(_WIN32) && ! defined(_WIN64) +#if defined(_MSC_VER) && ! defined(_WIN64) typedef unsigned long long ALIGN_ATTR(4) u64a; typedef signed long long ALIGN_ATTR(4) s64a; #else @@ -83,7 +83,7 @@ typedef u32 ReportID; /* Shorthand for attribute to mark a function as part of our public API. * Functions without this attribute will be hidden. */ -#if !defined(_WIN32) +#if !defined(_MSC_VER) #define HS_PUBLIC_API __attribute__((visibility("default"))) #else // TODO: dllexport defines for windows @@ -93,14 +93,14 @@ typedef u32 ReportID; #define ARRAY_LENGTH(a) (sizeof(a)/sizeof((a)[0])) /** \brief Shorthand for the attribute to shut gcc about unused parameters */ -#if !defined(_WIN32) +#if !defined(_MSC_VER) #define UNUSED __attribute__ ((unused)) #else #define UNUSED #endif /* really_inline forces inlining always */ -#if !defined(_WIN32) +#if !defined(_MSC_VER) #if defined(HS_OPTIMIZE) #define really_inline inline __attribute__ ((always_inline, unused)) #else @@ -130,7 +130,7 @@ typedef u32 ReportID; // We use C99-style "restrict". -#ifdef _WIN32 +#ifdef _MSC_VER #ifdef __cplusplus #define restrict #else @@ -186,7 +186,7 @@ typedef u32 ReportID; #define LIMIT_TO_AT_MOST(a, b) (*(a) = MIN(*(a),(b))) #define ENSURE_AT_LEAST(a, b) (*(a) = MAX(*(a),(b))) -#ifndef _WIN32 +#ifndef _MSC_VER #ifndef likely #define likely(x) __builtin_expect(!!(x), 1) #endif @@ -199,7 +199,7 @@ typedef u32 ReportID; #endif #if !defined(RELEASE_BUILD) || defined(DEBUG) -#ifdef _WIN32 +#ifdef _MSC_VER #define PATH_SEP '\\' #else #define PATH_SEP '/' diff --git a/src/util/bitutils.h b/src/util/bitutils.h index c545ee187..22ee33560 100644 --- a/src/util/bitutils.h +++ b/src/util/bitutils.h @@ -46,7 +46,7 @@ static really_inline u32 clz32(u32 x) { assert(x); // behaviour not defined for x == 0 -#if defined(_WIN32) +#if defined(_WIN32) && defined(_MSC_VER) unsigned long r; _BitScanReverse(&r, x); return 31 - r; @@ -58,11 +58,11 @@ u32 clz32(u32 x) { static really_inline u32 clz64(u64a x) { assert(x); // behaviour not defined for x == 0 -#if defined(_WIN64) +#if defined(_WIN64) && defined(_MSC_VER) unsigned long r; _BitScanReverse64(&r, x); return 63 - r; -#elif defined(_WIN32) +#elif defined(_WIN32) && defined(_MSC_VER) unsigned long x1 = (u32)x; unsigned long x2 = (u32)(x >> 32); unsigned long r; @@ -81,7 +81,7 @@ u32 clz64(u64a x) { static really_inline u32 ctz32(u32 x) { assert(x); // behaviour not defined for x == 0 -#if defined(_WIN32) +#if defined(_WIN32) && defined(_MSC_VER) unsigned long r; _BitScanForward(&r, x); return r; @@ -93,11 +93,11 @@ u32 ctz32(u32 x) { static really_inline u32 ctz64(u64a x) { assert(x); // behaviour not defined for x == 0 -#if defined(_WIN64) +#if defined(_WIN64) && defined(_MSC_VER) unsigned long r; _BitScanForward64(&r, x); return r; -#elif defined(_WIN32) +#elif defined(_WIN32) && defined(_MSC_VER) unsigned long r; if (_BitScanForward(&r, (u32)x)) { return (u32)r; diff --git a/src/util/cpuid_inline.h b/src/util/cpuid_inline.h index b7b424528..84e6a838f 100644 --- a/src/util/cpuid_inline.h +++ b/src/util/cpuid_inline.h @@ -32,7 +32,7 @@ #include "ue2common.h" #include "cpuid_flags.h" -#if !defined(_WIN32) && !defined(CPUID_H_) +#if !defined(_MSC_VER) && !defined(CPUID_H_) #include /* system header doesn't have a header guard */ #define CPUID_H_ @@ -46,7 +46,7 @@ extern "C" static inline void cpuid(unsigned int op, unsigned int leaf, unsigned int *eax, unsigned int *ebx, unsigned int *ecx, unsigned int *edx) { -#ifndef _WIN32 +#if !defined(_MSC_VER) __cpuid_count(op, leaf, *eax, *ebx, *ecx, *edx); #else int a[4];