Skip to content

Commit 8e998ec

Browse files
committed
MSYS2 Mingw64 compilation (IfcOpenShell#84)
2 parents 4afc568 + fc50e6a commit 8e998ec

3 files changed

Lines changed: 45 additions & 7 deletions

File tree

cmake/CMakeLists.txt

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ IF(UNICODE_SUPPORT)
184184
MESSAGE(STATUS "ICU libraries found")
185185
# NOTE icudata appears to be icudt on Windows/MSVC and icudata on others
186186
# dl is included to resolve dlopen and friends symbols
187-
IF(MSVC)
187+
IF(MSVC OR MINGW)
188188
SET(ICU_LIBRARIES icuuc icudt)
189189
ADD_DEBUG_VARIANTS(ICU_LIBRARIES "${ICU_LIBRARIES}" "d")
190190
ADD_DEFINITIONS(-DU_STATIC_IMPLEMENTATION) # required for static ICU
@@ -316,7 +316,12 @@ IF(MSVC)
316316
ENDIF()
317317
ENDFOREACH()
318318
ElSE()
319-
ADD_DEFINITIONS(-fPIC -Wno-non-virtual-dtor)
319+
IF(WIN32)
320+
# -fPIC is not relevant on Windows and create pointless warnings
321+
ADD_DEFINITIONS(-Wno-non-virtual-dtor)
322+
ELSE()
323+
ADD_DEFINITIONS(-fPIC -Wno-non-virtual-dtor)
324+
ENDIF()
320325
ENDIF()
321326

322327
INCLUDE_DIRECTORIES(${INCLUDE_DIRECTORIES} ${OCC_INCLUDE_DIR} ${OPENCOLLADA_INCLUDE_DIRS}

src/ifcgeomserver/IfcGeomServer.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,12 @@
2727
#include <iostream>
2828
#include <boost/cstdint.hpp>
2929

30-
#if defined(_WIN32) && !defined(__CYGWIN__)
30+
// NB: Streams are only re-opened as binary when compiled with MSVC currently.
31+
// It is unclear what the correct behaviour would be compiled with e.g MinGW
32+
#if defined(_MSC_VER)
3133
#define SET_BINARY_STREAMS
3234
#endif
35+
3336
#ifdef SET_BINARY_STREAMS
3437
#include <io.h>
3538
#include <fcntl.h>

src/ifcparse/IfcParse.cpp

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,23 +47,53 @@ using namespace IfcParse;
4747
// strtod_l() is used and a reference to the "C" locale is obtained here. The alternative is
4848
// to use std::istringstream::imbue(std::locale::classic()), but there are subtleties in
4949
// parsing in MSVC2010 and it appears to be much slower.
50-
#ifdef _MSC_VER
50+
#if defined(_MSC_VER)
51+
5152
static _locale_t locale = (_locale_t) 0;
5253
void init_locale() {
5354
if (locale == (_locale_t) 0) {
5455
locale = _create_locale(LC_NUMERIC, "C");
5556
}
5657
}
58+
5759
#else
60+
61+
#if defined(__MINGW64__) || defined(__MINGW32__)
62+
#include <locale>
63+
#include <sstream>
64+
65+
typedef void* locale_t;
66+
static locale_t locale = (locale_t)0;
67+
68+
void init_locale() {}
69+
70+
double strtod_l(const char* start, char** end, locale_t loc) {
71+
double d;
72+
std::stringstream ss;
73+
ss.imbue(std::locale::classic());
74+
ss << start;
75+
ss >> d;
76+
size_t nread = ss.tellg();
77+
*end = const_cast<char*>(start) + nread;
78+
return d;
79+
}
80+
81+
#else
82+
5883
#ifdef __APPLE__
5984
#include <xlocale.h>
6085
#endif
61-
static locale_t locale = (locale_t) 0;
86+
#include <locale.h>
87+
88+
static locale_t locale = (locale_t)0;
6289
void init_locale() {
63-
if (locale == (locale_t) 0) {
64-
locale = newlocale(LC_NUMERIC_MASK, "C", (locale_t) 0);
90+
if (locale == (locale_t)0) {
91+
locale = newlocale(LC_NUMERIC_MASK, "C", (locale_t)0);
6592
}
6693
}
94+
95+
#endif
96+
6797
#endif
6898

6999
//

0 commit comments

Comments
 (0)