Skip to content

Commit 4a85e5e

Browse files
Stinkfist0aothms
authored andcommitted
MSYS build scripts and instructions (IfcOpenShell#99) and warning fixes
* Preliminary MSYS2 + MinGW build scripts and instructions. * CMakeLists.txt: MinGW tweaks, enforce C++03, suppress warnings for now. * Fix some GCC warnings. * Fix unused parameter warnings coming from Ifc*.h. * Fix warning regarding unreachable code (++jt) on MSVC. * Add IfcParse_EXPORT for IfcInvalidTokenException * Fix potentially uninitialized pointer variables. * Note about OpenCASCADE cyclic dependencies fix. * GCC warning fix: don't generate 'current_enum' variable that is only set and not used for anything ever * Work around -Wmaybe-uninitialized warnings about boost::optional constructs. Also prevent passing of negative values for --bounds. * Remove unused variable. * CMakeLists.txt: ENABLE_BUILD_OPTIMIZATIONS for GCC (simply enforce -03)
1 parent 435eb7a commit 4a85e5e

26 files changed

+1125
-938
lines changed

README.md

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ Prerequisites
1111
-------------
1212
* Git
1313
* CMake (2.6 or newer)
14-
* Windows: Visual Studio 2008 or newer with C++ toolset, MinGW not supported currently
14+
* Windows: Visual Studio 2008 or newer with C++ toolset or [MSYS2] + MinGW
1515
* *nix: GCC 4.7 or newer, or Clang (any version)
1616

1717
Dependencies
@@ -34,10 +34,11 @@ Building IfcOpenShell
3434
---------------------
3535
### Compiling on Windows
3636
The preferred way to fetch and build this project's dependencies is to use the build scripts
37-
in win/ folder. **See [win/readme.md] for more information**. Instructions in a nutshell
38-
(**assuming Visual Studio 2015 x64 environment variables set**):
37+
in win/ folder. **See [win/readme.md] for more information**.
38+
39+
#### Compiling using Visual Studio
40+
Instructions in a nutshell (**assuming Visual Studio 2015 x64 environment variables set**):
3941

40-
> git clone https://github.com/IfcOpenShell/IfcOpenShell.git
4142
> cd IfcOpenShell\win
4243
> build-deps.cmd
4344
> run-cmake.bat
@@ -55,6 +56,16 @@ Alternatively, one can use the utility batch files to build and install the proj
5556
> build-ifcopenshell.bat
5657
> install-ifcopenshell.bat
5758

59+
#### Compiling using MSYS2 + MinGW
60+
61+
Start the MSYS2 Shell and then:
62+
63+
$ cd IfcOpenShell/win
64+
$ ./build-deps.sh
65+
$ ./run-cmake.sh
66+
$ ./build-ifcopenshell.sh
67+
$ ./install-ifcopenshell.sh
68+
5869
### Compiling on *nix
5970
There might be an Open CASCADE package in your operating system's software repository. If not, you will need to compile
6071
Open CASCADE yourself. See http://opencascade.org.
@@ -163,4 +174,5 @@ Usage examples
163174
[IFC]: http://www.buildingsmart-tech.org/specifications/ifc-overview "IFC"
164175
[IFC2x3 TC1]: http://www.buildingsmart-tech.org/specifications/ifc-releases/ifc2x3-tc1-release "IFC2x3 TC1"
165176
[IFC4 Add1]: http://www.buildingsmart-tech.org/specifications/ifc-releases/ifc4-add1-release "IFC4 Add1"
177+
[MSYS2]: https://msys2.github.io/ "MSYS2"
166178
[win/readme.md]: https://github.com/IfcOpenShell/IfcOpenShell/tree/master/win/readme.md "win/readme.md"

cmake/CMakeLists.txt

Lines changed: 26 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ MACRO(SET_INSTALL_RPATHS _target _paths)
9898
SET(${_target}_rpaths "")
9999
FOREACH(_path ${_paths})
100100
LIST(FIND CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES "${_path}" isSystemDir)
101-
IF("${isSystemDir}" STREQUAL "-1")
101+
IF("${isSystemDir}" STREQUAL "-1")
102102
LIST(APPEND ${_target}_rpaths ${_path})
103103
ENDIF()
104104
ENDFOREACH()
@@ -107,7 +107,7 @@ MACRO(SET_INSTALL_RPATHS _target _paths)
107107
ENDMACRO()
108108

109109
# Find Boost
110-
IF(MSVC)
110+
IF(WIN32)
111111
SET(Boost_USE_STATIC_LIBS ON)
112112
SET(Boost_USE_STATIC_RUNTIME ON)
113113
SET(Boost_USE_MULTITHREADED ON)
@@ -195,10 +195,11 @@ IF(UNICODE_SUPPORT)
195195
MESSAGE(STATUS "ICU libraries found")
196196
# NOTE icudata appears to be icudt on Windows/MSVC and icudata on others
197197
# dl is included to resolve dlopen and friends symbols
198-
IF(MSVC OR MINGW)
198+
IF(WIN32)
199199
SET(ICU_LIBRARIES icuuc icudt)
200200
ADD_DEBUG_VARIANTS(ICU_LIBRARIES "${ICU_LIBRARIES}" "d")
201-
ADD_DEFINITIONS(-DU_STATIC_IMPLEMENTATION) # required for static ICU
201+
# TODO MinGW build would appear to be using dynamic ICU regardless of this definition.
202+
ADD_DEFINITIONS(-DU_STATIC_IMPLEMENTATION) # required for static ICU
202203
ELSE()
203204
SET(ICU_LIBRARIES icuuc icudata dl)
204205
ENDIF()
@@ -273,12 +274,12 @@ IF(NOT CMAKE_BUILD_TYPE)
273274
SET(CMAKE_BUILD_TYPE "Release")
274275
ENDIF()
275276

276-
# NOTE: RelWithDebInfo and Release use O2 (= /Ox /Gl /Gy/ = Og /Oi /Ot /Oy /Ob2 /Gs /GF /Gy) by default,
277-
# with the exception with RelWithDebInfo has /Ob1 instead. /Ob2 has been observed to improve the performance
278-
# of IfcConvert significantly.
279-
# TODO Setting of /GL and /LTCG don't seem to apply for static libraries (IfcGeom, IfcParse)
280277
if(ENABLE_BUILD_OPTIMIZATIONS)
281278
if(MSVC)
279+
# NOTE: RelWithDebInfo and Release use O2 (= /Ox /Gl /Gy/ = Og /Oi /Ot /Oy /Ob2 /Gs /GF /Gy) by default,
280+
# with the exception with RelWithDebInfo has /Ob1 instead. /Ob2 has been observed to improve the performance
281+
# of IfcConvert significantly.
282+
# TODO Setting of /GL and /LTCG don't seem to apply for static libraries (IfcGeom, IfcParse)
282283
# C++
283284
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /Ob2 /GL")
284285
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELEASE} /Zi")
@@ -290,8 +291,9 @@ if(ENABLE_BUILD_OPTIMIZATIONS)
290291
set(CMAKE_EXE_LINKER_FLAGS_RELEASE "${CMAKE_EXE_LINKER_FLAGS_RELEASE} /LTCG /OPT:REF")
291292
set(CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO "${CMAKE_EXE_LINKER_FLAGS_RELEASE} /DEBUG /OPT:NOICF")
292293
else()
293-
#TODO GCC (& Clang?) optimizations
294-
message(STATUS "ENABLE_BUILD_OPTIMIZATIONS not implemented for GCC/non-MSVC compilers.)")
294+
# GCC-like: Release should use O3 but RelWithDebInfo 02 so enforce 03. Anything other useful that could be added here?
295+
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O3")
296+
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELEASE} -O3")
295297
endif()
296298
endif()
297299

@@ -328,12 +330,13 @@ IF(MSVC)
328330
ENDIF()
329331
ENDFOREACH()
330332
ElSE()
331-
IF(WIN32)
332-
# -fPIC is not relevant on Windows and create pointless warnings
333-
ADD_DEFINITIONS(-Wno-non-virtual-dtor -Wall -Wextra)
334-
ELSE()
335-
ADD_DEFINITIONS(-fPIC -Wno-non-virtual-dtor -Wall -Wextra)
336-
ENDIF()
333+
add_definitions(-Wno-non-virtual-dtor -Wall)
334+
# TODO Preferably use -Wextra too, but currently too much warning spam coming from the dependencies' headers.
335+
add_definitions(-std=c++03)
336+
# -fPIC is not relevant on Windows and creates pointless warnings
337+
if (UNIX)
338+
add_definitions(-fPIC)
339+
endif()
337340
ENDIF()
338341

339342
INCLUDE_DIRECTORIES(${INCLUDE_DIRECTORIES} ${OCC_INCLUDE_DIR} ${OPENCOLLADA_INCLUDE_DIRS}
@@ -490,10 +493,14 @@ endif()
490493
get_filename_component(libTKernelExt ${libTKernel} EXT)
491494
if("${libTKernelExt}" STREQUAL ".a")
492495
find_package(Threads)
493-
if (NOT APPLE)
494-
set(LIB_RT "rt")
496+
# OPENCASCADE_LIBRARIES repeated three times below in order to fix cyclic dependencies - use --start-group ... --end-group instead?
497+
set(OPENCASCADE_LIBRARIES ${OPENCASCADE_LIBRARIES} ${OPENCASCADE_LIBRARIES} ${OPENCASCADE_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT})
498+
if (NOT APPLE AND NOT WIN32)
499+
set(OPENCASCADE_LIBRARIES ${OPENCASCADE_LIBRARIES} "rt")
500+
endif()
501+
if (NOT WIN32)
502+
set(OPENCASCADE_LIBRARIES ${OPENCASCADE_LIBRARIES} "dl")
495503
endif()
496-
set(OPENCASCADE_LIBRARIES ${OPENCASCADE_LIBRARIES} ${OPENCASCADE_LIBRARIES} ${OPENCASCADE_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} ${LIB_RT} dl)
497504
endif()
498505

499506
TARGET_LINK_LIBRARIES(IfcConvert ${IFCOPENSHELL_LIBRARIES} ${OPENCASCADE_LIBRARIES} ${Boost_LIBRARIES} ${OPENCOLLADA_LIBRARIES} ${ICU_LIBRARIES})

src/ifcconvert/ColladaSerializer.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,8 +159,8 @@ class ColladaSerializer : public GeometrySerializer
159159
{
160160
}
161161
ColladaMaterials materials;
162-
ColladaSerializer *serializer;
163162
ColladaGeometries geometries;
163+
ColladaSerializer *serializer;
164164
std::vector<DeferredObject> deferreds;
165165
virtual ~ColladaExporter() {}
166166
void startDocument(const std::string& unit_name, float unit_magnitude);

src/ifcconvert/IfcConvert.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@
4040

4141
#include <boost/program_options.hpp>
4242
#include <boost/algorithm/string.hpp>
43-
#include <boost/optional/optional_io.hpp>
4443

4544
#include <fstream>
4645
#include <sstream>
@@ -279,10 +278,10 @@ int main(int argc, char** argv) {
279278
const bool generate_uvs = vmap.count("generate-uvs") != 0 ;
280279
const bool deflection_tolerance_specified = vmap.count("deflection-tolerance") != 0 ;
281280

282-
boost::optional<int> bounding_width, bounding_height;
281+
int bounding_width = -1, bounding_height = -1;
283282
if (vmap.count("bounds") == 1) {
284283
int w, h;
285-
if (sscanf(bounds.c_str(), "%ux%u", &w, &h) == 2) {
284+
if (sscanf(bounds.c_str(), "%ux%u", &w, &h) == 2 && w > 0 && h > 0) {
286285
bounding_width = w;
287286
bounding_height = h;
288287
} else {
@@ -404,7 +403,7 @@ int main(int argc, char** argv) {
404403
settings.set(IfcGeom::IteratorSettings::DISABLE_TRIANGULATION, true);
405404
serializer = new SvgSerializer(output_temp_filename, settings);
406405
if (bounding_width && bounding_height) {
407-
static_cast<SvgSerializer*>(serializer)->setBoundingRectangle(*bounding_width, *bounding_height);
406+
static_cast<SvgSerializer*>(serializer)->setBoundingRectangle(bounding_width, bounding_height);
408407
}
409408
} else {
410409
Logger::Message(Logger::LOG_ERROR, "Unknown output filename extension '" + output_extension + "'");

src/ifcconvert/XmlSerializer.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,8 @@ boost::optional<std::string> format_attribute(const Argument* argument, IfcUtil:
8383
value = unit_name;
8484
}
8585
break; }
86+
default:
87+
break;
8688
}
8789
return value;
8890
}

src/ifcexpressparser/header.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,17 +103,17 @@ def case_norm(n):
103103
argument_start = argument_count - len(type.attributes)
104104

105105
argument_name_function_body_switch_stmt = " switch (i) {%s}"%("".join(['case %d: return "%s"; '%(i+argument_start, attr.name) for i, attr in enumerate(type.attributes)])) if len(type.attributes) else ""
106-
argument_name_function_body_tail = (" return %s::getArgumentName(i); "%type.supertypes[0]) if len(type.supertypes) == 1 else ' throw IfcParse::IfcAttributeOutOfRangeException("Argument index out of range"); '
106+
argument_name_function_body_tail = (" return %s::getArgumentName(i); "%type.supertypes[0]) if len(type.supertypes) == 1 else ' (void)i; throw IfcParse::IfcAttributeOutOfRangeException("Argument index out of range"); '
107107

108108
argument_name_function_body = argument_name_function_body_switch_stmt + argument_name_function_body_tail
109109

110110
argument_type_function_body_switch_stmt = " switch (i) {%s}"%("".join(['case %d: return %s; '%(i+argument_start, mapping.make_argument_type(attr)) for i, attr in enumerate(type.attributes)])) if len(type.attributes) else ""
111-
argument_type_function_body_tail = (" return %s::getArgumentType(i); "%type.supertypes[0]) if len(type.supertypes) == 1 else ' throw IfcParse::IfcAttributeOutOfRangeException("Argument index out of range"); '
111+
argument_type_function_body_tail = (" return %s::getArgumentType(i); "%type.supertypes[0]) if len(type.supertypes) == 1 else ' (void)i; throw IfcParse::IfcAttributeOutOfRangeException("Argument index out of range"); '
112112

113113
argument_type_function_body = argument_type_function_body_switch_stmt + argument_type_function_body_tail
114114

115115
argument_entity_function_body_switch_stmt = " switch (i) {%s}"%("".join(['case %d: return %s; '%(i+argument_start, mapping.make_argument_entity(attr)) for i, attr in enumerate(type.attributes)])) if len(type.attributes) else ""
116-
argument_entity_function_body_tail = (" return %s::getArgumentEntity(i); "%type.supertypes[0]) if len(type.supertypes) == 1 else ' throw IfcParse::IfcAttributeOutOfRangeException("Argument index out of range"); '
116+
argument_entity_function_body_tail = (" return %s::getArgumentEntity(i); "%type.supertypes[0]) if len(type.supertypes) == 1 else ' (void)i; throw IfcParse::IfcAttributeOutOfRangeException("Argument index out of range"); '
117117

118118
argument_entity_function_body = argument_entity_function_body_switch_stmt + argument_entity_function_body_tail
119119

src/ifcexpressparser/templates.py

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,6 @@
3232
#include "../ifcparse/IfcException.h"
3333
#include "../ifcparse/%(schema_name)senum.h"
3434
35-
#ifdef _MSC_VER
36-
#pragma warning(push)
37-
#pragma warning(disable : 4100)
38-
#endif
39-
4035
#define IfcSchema %(schema_name)s
4136
4237
namespace %(schema_name)s {
@@ -53,10 +48,6 @@
5348
IfcUtil::IfcBaseClass* SchemaEntity(IfcAbstractEntity* e = 0);
5449
}
5550
56-
#ifdef _MSC_VER
57-
#pragma warning(pop)
58-
#endif
59-
6051
#endif
6152
"""
6253

@@ -209,7 +200,6 @@
209200
IfcEntityDescriptor* current;
210201
%(entity_descriptors)s
211202
// Enumerations
212-
IfcEnumerationDescriptor* current_enum;
213203
std::vector<std::string> values;
214204
%(enumeration_descriptors)s
215205
}
@@ -349,7 +339,7 @@
349339

350340
enumeration_descriptor = """ values.clear(); values.reserve(128);
351341
%(enumeration_descriptor_values)s
352-
current_enum = enumeration_descriptor_map[Type::%(type)s] = new IfcEnumerationDescriptor(Type::%(type)s, values);"""
342+
enumeration_descriptor_map[Type::%(type)s] = new IfcEnumerationDescriptor(Type::%(type)s, values);"""
353343

354344
enumeration_descriptor_value = ' values.push_back("%(name)s");'
355345

src/ifcgeom/IfcGeom.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -280,9 +280,9 @@ class Kernel {
280280
return _get_surface_style<T>(representation_item->as<IfcSchema::IfcStyledItem>());
281281
}
282282
IfcSchema::IfcStyledItem::list::ptr styled_items = representation_item->StyledByItem();
283-
for (IfcSchema::IfcStyledItem::list::it jt = styled_items->begin(); jt != styled_items->end(); ++jt) {
283+
if (styled_items->size()) {
284284
// StyledByItem is a SET [0:1] OF IfcStyledItem, so we return after the first IfcStyledItem:
285-
return _get_surface_style<T>(*jt);
285+
return _get_surface_style<T>(*styled_items->begin());
286286
}
287287
return std::make_pair<IfcSchema::IfcSurfaceStyle*, T*>(0,0);
288288
}

src/ifcgeom/IfcGeomFunctions.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1366,7 +1366,6 @@ bool IfcGeom::Kernel::convert_layerset(const IfcSchema::IfcProduct* product, std
13661366
const IfcSchema::IfcMaterialLayerSet* layerset = usage->ForLayerSet();
13671367
const bool positive = usage->DirectionSense() == IfcSchema::IfcDirectionSenseEnum::IfcDirectionSense_POSITIVE;
13681368
double offset = usage->OffsetFromReferenceLine() * getValue(GV_LENGTH_UNIT);
1369-
const int axis = usage->LayerSetDirection();
13701369

13711370
IfcSchema::IfcMaterialLayer::list::ptr material_layers = layerset->MaterialLayers();
13721371

@@ -1723,7 +1722,7 @@ bool IfcGeom::Kernel::fold_layers(const IfcSchema::IfcWall* wall, const IfcRepre
17231722

17241723
bool found_intersection = false;
17251724
boost::optional<gp_Pnt> point_outside_param_range;
1726-
double param;
1725+
//double param;
17271726

17281727
const Handle_Geom_Surface& surface = *jt;
17291728

@@ -1734,7 +1733,7 @@ bool IfcGeom::Kernel::fold_layers(const IfcSchema::IfcWall* wall, const IfcRepre
17341733
intersections.Parameters(1, u, v, w);
17351734
if (w < axis_u1 || w > axis_u2) {
17361735
point_outside_param_range = p;
1737-
param = w;
1736+
//param = w;
17381737
} else {
17391738
// Found an intersection. Layer end point is covered by connecting wall
17401739
found_intersection = true;

src/ifcgeom/IfcGeomIterator.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -393,8 +393,6 @@ namespace IfcGeom {
393393
}
394394
}
395395

396-
const int repid = representation->entity->id();
397-
398396
bool has_openings = false;
399397
bool has_layers = false;
400398

0 commit comments

Comments
 (0)