Skip to content

Commit 4218890

Browse files
jobermayraothms
authored andcommitted
Fixes to build on openSUSE/Packman. (#67)
- Support different BINDIR, INCLUDEDIR and LIBDIR on install - Take right python dir on x86_64 arch - Fix build against Boost >= 1.58 - Make it possible to build libIfcGeom shared to reduce size of dependent binaries - Fix INSTALL_RPATH - Fix some more compiler warnings
1 parent 414d7bb commit 4218890

File tree

13 files changed

+97
-38
lines changed

13 files changed

+97
-38
lines changed

cmake/CMakeLists.txt

Lines changed: 70 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,38 @@ OPTION(BUILD_IFCPYTHON "Build IfcPython." ON)
3030
OPTION(BUILD_EXAMPLES "Build example applications." ON)
3131
OPTION(USE_VLD "Use Visual Leak Detector for debugging memory leaks, MSVC-only." OFF)
3232
OPTION(BUILD_IFCMAX "Build IfcMax, a 3ds Max plug-in, Windows-only." OFF)
33+
OPTION(BUILD_SHARED_LIBS "Build ifcparse and ifcgeom libs shared." OFF)
3334
# TODO QtViewer is deprecated ATM as it uses the 0.4 API
3435
# OPTION(BUILD_QTVIEWER "Build IfcOpenShell Qt GUI Viewer (requires Qt 4 framework)." OFF)
3536

3637

38+
# Specify where to install files
39+
IF(NOT BINDIR)
40+
set(BINDIR bin)
41+
ENDIF()
42+
IF(NOT IS_ABSOLUTE ${BINDIR})
43+
set(BINDIR ${CMAKE_INSTALL_PREFIX}/${BINDIR})
44+
ENDIF()
45+
MESSAGE(STATUS "BINDIR: ${BINDIR}")
46+
47+
IF(NOT INCLUDEDIR)
48+
set(INCLUDEDIR include)
49+
ENDIF()
50+
IF(NOT IS_ABSOLUTE ${INCLUDEDIR})
51+
set(INCLUDEDIR ${CMAKE_INSTALL_PREFIX}/${INCLUDEDIR})
52+
ENDIF()
53+
MESSAGE(STATUS "INCLUDEDIR: ${INCLUDEDIR}")
54+
55+
IF(NOT LIBDIR)
56+
set(LIBDIR lib)
57+
ENDIF()
58+
IF(NOT IS_ABSOLUTE ${LIBDIR})
59+
set(LIBDIR ${CMAKE_INSTALL_PREFIX}/${LIBDIR})
60+
ENDIF()
61+
MESSAGE(STATUS "LIBDIR: ${LIBDIR}")
62+
63+
64+
3765
# Create cache entries if absent for environment variables
3866
MACRO(UNIFY_ENVVARS_AND_CACHE VAR)
3967
IF ((NOT DEFINED ${VAR}) AND (NOT "$ENV{${VAR}}" STREQUAL ""))
@@ -53,6 +81,20 @@ IF(WIN32)
5381
UNIFY_ENVVARS_AND_CACHE(THREEDS_MAX_SDK_HOME)
5482
ENDIF()
5583

84+
85+
# Set INSTALL_RPATH for target
86+
MACRO(SET_INSTALL_RPATHS _target _paths)
87+
SET(${_target}_rpaths "")
88+
FOREACH(_path ${_paths})
89+
LIST(FIND CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES "${_path}" isSystemDir)
90+
IF("${isSystemDir}" STREQUAL "-1")
91+
LIST(APPEND ${_target}_rpaths ${_path})
92+
ENDIF()
93+
ENDFOREACH()
94+
MESSAGE(STATUS "Set INSTALL_RPATH for ${_target}: ${${_target}_rpaths}")
95+
SET_TARGET_PROPERTIES(${_target} PROPERTIES INSTALL_RPATH "${${_target}_rpaths}")
96+
ENDMACRO()
97+
5698
# Find Boost
5799
IF(MSVC)
58100
SET(Boost_USE_STATIC_LIBS ON)
@@ -135,7 +177,7 @@ IF(UNICODE_SUPPORT)
135177
SET(ICU_LIBRARY_DIR "${ICU_LIBRARY_DIR}" CACHE FILEPATH "ICU library files")
136178
ENDIF()
137179

138-
FIND_LIBRARY(icu NAMES icuuc icuucd PATHS /usr/lib /usr/lib64 /usr/local/lib /usr/local/lib64 ${ICU_LIBRARY_DIR})
180+
FIND_LIBRARY(icu NAMES icuuc icuucd PATHS /usr/lib64 /usr/lib /usr/local/lib64 /usr/local/lib ${ICU_LIBRARY_DIR})
139181

140182
IF(icu)
141183
ADD_DEFINITIONS(-DHAVE_ICU)
@@ -165,10 +207,10 @@ IF(COLLADA_SUPPORT)
165207

166208
IF("${OPENCOLLADA_LIBRARY_DIR}" STREQUAL "")
167209
MESSAGE(STATUS "No OpenCOLLADA library directory specified")
168-
SET(OPENCOLLADA_LIBRARY_DIR "/usr/lib/opencollada" CACHE FILEPATH "OpenCOLLADA library files")
169-
ElSE()
170-
SET(OPENCOLLADA_LIBRARY_DIR "${OPENCOLLADA_LIBRARY_DIR}" CACHE FILEPATH "OpenCOLLADA library files")
210+
FIND_LIBRARY(OPENCOLLADA_FRAMEWORK_LIB NAMES OpenCOLLADAFramework PATHS /usr/lib64/opencollada /usr/lib/opencollada /usr/lib64 /usr/lib /usr/local/lib64 /usr/local/lib)
211+
GET_FILENAME_COMPONENT(OPENCOLLADA_LIBRARY_DIR ${OPENCOLLADA_FRAMEWORK_LIB} PATH)
171212
ENDIF()
213+
SET(OPENCOLLADA_LIBRARY_DIR "${OPENCOLLADA_LIBRARY_DIR}" CACHE FILEPATH "OpenCOLLADA library files")
172214

173215
SET(OPENCOLLADA_INCLUDE_DIRS "${OPENCOLLADA_INCLUDE_DIR}/COLLADABaseUtils" "${OPENCOLLADA_INCLUDE_DIR}/COLLADAStreamWriter")
174216

@@ -361,6 +403,11 @@ else()
361403
endif()
362404
endif()
363405

406+
# Boost >= 1.58 requires BOOST_OPTIONAL_USE_OLD_DEFINITION_OF_NONE to build
407+
if(NOT Boost_VERSION LESS 105800)
408+
add_definitions(-DBOOST_OPTIONAL_USE_OLD_DEFINITION_OF_NONE)
409+
endif()
410+
364411
# IfcParse
365412
file(GLOB IFCPARSE_H_FILES ../src/ifcparse/*.h)
366413
file(GLOB IFCPARSE_CPP_FILES ../src/ifcparse/*.cpp)
@@ -386,7 +433,15 @@ file(GLOB IFCGEOM_H_FILES ../src/ifcgeom/*.h)
386433
file(GLOB IFCGEOM_CPP_FILES ../src/ifcgeom/*.cpp)
387434

388435
set(IFCGEOM_FILES ${IFCGEOM_CPP_FILES} ${IFCGEOM_H_FILES})
389-
ADD_LIBRARY(IfcGeom STATIC ${IFCGEOM_FILES})
436+
IF(BUILD_SHARED_LIBS)
437+
ADD_LIBRARY(IfcGeom SHARED ${IFCGEOM_FILES})
438+
SET(IFCLIBS "IfcGeom")
439+
SET(IFCDIRS "${LIBDIR}")
440+
ELSE()
441+
ADD_LIBRARY(IfcGeom STATIC ${IFCGEOM_FILES})
442+
SET(IFCLIBS "IfcParse;IfcGeom")
443+
SET(IFCDIRS "")
444+
ENDIF()
390445

391446
TARGET_LINK_LIBRARIES(IfcGeom IfcParse)
392447

@@ -414,18 +469,21 @@ if("${libTKernelExt}" STREQUAL ".a")
414469
if (NOT APPLE)
415470
set(LIB_RT "rt")
416471
endif()
417-
set(OPENCASCADE_LIBRARIES ${OPENCASCADE_LIBRARIES} ${OPENCASCADE_LIBRARIES} ${OPENCASCADE_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} ${LIB_RT} dl)
472+
set(OPENCASCADE_LIBRARIES ${OPENCASCADE_LIBRARIES} ${OPENCASCADE_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} ${LIB_RT} dl)
418473
endif()
419474

420-
TARGET_LINK_LIBRARIES(IfcConvert IfcParse IfcGeom ${OPENCASCADE_LIBRARIES} ${Boost_LIBRARIES} ${OPENCOLLADA_LIBRARIES} ${ICU_LIBRARIES})
475+
TARGET_LINK_LIBRARIES(IfcConvert ${IFCLIBS} ${OPENCASCADE_LIBRARIES} ${Boost_LIBRARIES} ${OPENCOLLADA_LIBRARIES} ${ICU_LIBRARIES})
476+
SET_INSTALL_RPATHS(IfcConvert "${IFCDIRS};${OCC_LIBRARY_DIR};${Boost_LIBRARY_DIRS};${OPENCOLLADA_LIBRARY_DIR};${ICU_LIBRARY_DIR}")
477+
421478

422479
# IfcGeomServer
423480
file(GLOB CPP_FILES ../src/ifcgeomserver/*.cpp)
424481
file(GLOB H_FILES ../src/ifcgeomserver/*.h)
425482
set(SOURCE_FILES ${CPP_FILES} ${H_FILES})
426483
ADD_EXECUTABLE(IfcGeomServer ${SOURCE_FILES})
427484

428-
TARGET_LINK_LIBRARIES(IfcGeomServer IfcParse IfcGeom ${OPENCASCADE_LIBRARIES} ${Boost_LIBRARIES} ${ICU_LIBRARIES})
485+
TARGET_LINK_LIBRARIES(IfcGeomServer ${IFCLIBS} ${OPENCASCADE_LIBRARIES} ${Boost_LIBRARIES} ${ICU_LIBRARIES})
486+
SET_INSTALL_RPATHS(IfcGeomServer "${IFCDIRS};${OCC_LIBRARY_DIR};${Boost_LIBRARY_DIRS};${ICU_LIBRARY_DIR}")
429487

430488
IF(BUILD_IFCPYTHON)
431489
ADD_SUBDIRECTORY(../src/ifcwrap ifcwrap)
@@ -440,7 +498,7 @@ IF(BUILD_IFCMAX)
440498
ENDIF()
441499

442500
# CMake installation targets
443-
INSTALL(FILES ${IFCPARSE_H_FILES} DESTINATION include/ifcparse)
444-
INSTALL(FILES ${IFCGEOM_H_FILES} DESTINATION include/ifcgeom)
445-
INSTALL(TARGETS IfcConvert IfcGeomServer DESTINATION bin)
446-
INSTALL(TARGETS IfcParse IfcGeom DESTINATION lib)
501+
INSTALL(FILES ${IFCPARSE_H_FILES} DESTINATION ${INCLUDEDIR}/ifcparse)
502+
INSTALL(FILES ${IFCGEOM_H_FILES} DESTINATION ${INCLUDEDIR}/ifcgeom)
503+
INSTALL(TARGETS IfcConvert IfcGeomServer DESTINATION ${BINDIR})
504+
INSTALL(TARGETS ${IFCLIBS} DESTINATION ${LIBDIR})

src/examples/CMakeLists.txt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,13 @@
1818
################################################################################
1919

2020
ADD_EXECUTABLE(IfcParseExamples IfcParseExamples.cpp)
21-
TARGET_LINK_LIBRARIES(IfcParseExamples IfcParse)
21+
IF(BUILD_SHARED_LIBS)
22+
TARGET_LINK_LIBRARIES(IfcParseExamples ${IFCLIBS})
23+
ELSE()
24+
TARGET_LINK_LIBRARIES(IfcParseExamples IfcParse)
25+
ENDIF()
2226
set_target_properties(IfcParseExamples PROPERTIES FOLDER Examples)
2327

2428
ADD_EXECUTABLE(IfcOpenHouse IfcOpenHouse.cpp)
25-
TARGET_LINK_LIBRARIES(IfcOpenHouse IfcParse IfcGeom ${OPENCASCADE_LIBRARIES})
29+
TARGET_LINK_LIBRARIES(IfcOpenHouse ${IFCLIBS} ${OPENCASCADE_LIBRARIES})
2630
set_target_properties(IfcOpenHouse PROPERTIES FOLDER Examples)

src/ifcconvert/ColladaSerializer.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,8 @@ class ColladaSerializer : public GeometrySerializer
106106
public:
107107
explicit ColladaMaterials(COLLADASW::StreamWriter& stream, ColladaSerializer *_serializer)
108108
: COLLADASW::LibraryMaterials(&stream)
109-
, effects(stream)
110-
, serializer(_serializer)
109+
, serializer(_serializer)
110+
, effects(stream)
111111
{}
112112
void add(const IfcGeom::Material& material);
113113
bool contains(const IfcGeom::Material& material);
@@ -152,10 +152,10 @@ class ColladaSerializer : public GeometrySerializer
152152
ColladaExporter(const std::string& scene_name, const std::string& fn, ColladaSerializer *_serializer)
153153
: filename(fn)
154154
, stream(filename, sizeof(real_t) == sizeof(double)) // utilise Collada stream's double precision feature
155-
, geometries(stream, _serializer)
156155
, scene(scene_name, stream, _serializer)
157156
, materials(stream, _serializer)
158-
, serializer(_serializer)
157+
, geometries(stream, _serializer)
158+
, serializer(_serializer)
159159
{
160160
}
161161
ColladaMaterials materials;

src/ifcconvert/SvgSerializer.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ class SvgSerializer : public GeometrySerializer {
4747
: GeometrySerializer(settings)
4848
, svg_file(out_filename.c_str())
4949
, xmin(+std::numeric_limits<double>::infinity())
50-
, xmax(-std::numeric_limits<double>::infinity())
5150
, ymin(+std::numeric_limits<double>::infinity())
51+
, xmax(-std::numeric_limits<double>::infinity())
5252
, ymax(-std::numeric_limits<double>::infinity())
5353
, rescale(false)
5454
, file(0)

src/ifcconvert/WavefrontObjSerializer.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ class WaveFrontOBJSerializer : public GeometrySerializer {
3737
public:
3838
WaveFrontOBJSerializer(const std::string& obj_filename, const std::string& mtl_filename, const IfcGeom::IteratorSettings &settings)
3939
: GeometrySerializer(settings)
40-
, obj_stream(obj_filename.c_str())
4140
, mtl_filename(mtl_filename)
41+
, obj_stream(obj_filename.c_str())
4242
, mtl_stream(mtl_filename.c_str())
4343
, vcount_total(1)
4444
{}

src/ifcgeom/IfcGeomRenderStyles.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ namespace IfcGeom {
5858
this->name = sstr.str();
5959
}
6060
SurfaceStyle(const std::string& name) : name(name), original_name_(name) {}
61-
SurfaceStyle(int id, const std::string& name) : id(id), original_name_(name)
61+
SurfaceStyle(int id, const std::string& name) : original_name_(name), id(id)
6262
{
6363
std::stringstream sstr;
6464
std::string sanitized = name;

src/ifcgeomserver/IfcGeomServer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ std::string sread(std::istream& s) {
5858
buf[len] = 0;
5959
while (len++ % 4) s.get();
6060
std::string str(buf);
61-
delete buf;
61+
delete[] buf;
6262
return str;
6363
}
6464

src/ifcmax/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,12 @@ LINK_DIRECTORIES(${LINK_DIRECTORIES} ${IfcOpenShell_BINARY_DIR} ${OCC_LIBRARY_DI
2828

2929
ADD_LIBRARY(IfcMax SHARED IfcMax.h IfcMax.cpp)
3030

31-
TARGET_LINK_LIBRARIES(IfcMax IfcParse IfcGeom Comctl32.lib zlibdll.lib bmm.lib core.lib CustDlg.lib edmodel.lib expr.lib
31+
TARGET_LINK_LIBRARIES(IfcMax ${IFCLIBS} Comctl32.lib zlibdll.lib bmm.lib core.lib CustDlg.lib edmodel.lib expr.lib
3232
flt.lib geom.lib gfx.lib gup.lib imageViewers.lib ManipSys.lib maxnet.lib Maxscrpt.lib
3333
maxutil.lib MenuMan.lib menus.lib mesh.lib MNMath.lib Paramblk2.lib particle.lib Poly.lib RenderUtil.lib
3434
tessint.lib viewfile.lib ${OPENCASCADE_LIBRARIES}
3535
)
3636

3737
SET_TARGET_PROPERTIES(IfcMax PROPERTIES SUFFIX ".dli")
3838

39-
INSTALL(TARGETS IfcMax RUNTIME DESTINATION bin)
39+
INSTALL(TARGETS IfcMax RUNTIME DESTINATION ${BINDIR})

src/ifcparse/IfcParse.cpp

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,6 @@ Token IfcSpfLexer::Next() {
320320

321321
int len = 0;
322322

323-
char p = 0;
324323
while ( ! stream->eof ) {
325324

326325
// Read character and increment pointer if not starting a new token
@@ -331,8 +330,6 @@ Token IfcSpfLexer::Next() {
331330

332331
// If a string is encountered defer processing to the IfcCharacterDecoder
333332
if ( c == '\'' ) decoder->dryRun();
334-
335-
p = c;
336333
}
337334
if ( len ) return TokenPtr(this,pos);
338335
else return TokenPtr();
@@ -348,15 +345,13 @@ std::string IfcSpfLexer::TokenString(unsigned int offset) {
348345
stream->Seek(offset);
349346
std::string buffer;
350347
buffer.reserve(128);
351-
char p = 0;
352348
while ( ! stream->eof ) {
353349
char c = stream->Peek();
354350
if ( buffer.size() && (c == '(' || c == ')' || c == '=' || c == ',' || c == ';' || c == '/') ) break;
355351
stream->Inc();
356352
if ( c == ' ' || c == '\r' || c == '\n' || c == '\t' ) continue;
357353
else if ( c == '\'' ) return *decoder;
358354
else buffer.push_back(c);
359-
p = c;
360355
}
361356
if ( was_eof ) stream->eof = true;
362357
else stream->Seek(old_offset);
@@ -790,7 +785,7 @@ EntityArgument::~EntityArgument() { delete entity; }
790785
//
791786
// Reads an Entity from the list of Tokens
792787
//
793-
Entity::Entity(unsigned int i, IfcFile* f) : _id(i), args(0) {
788+
Entity::Entity(unsigned int i, IfcFile* f) : args(0), _id(i) {
794789
file = f;
795790
Token datatype = f->tokens->Next();
796791
if ( ! TokenFunc::isKeyword(datatype)) throw IfcException("Unexpected token while parsing entity");
@@ -904,10 +899,10 @@ IfcWrite::IfcWritableEntity* Entity::isWritable() {
904899

905900
IfcFile::IfcFile(bool create_latebound_entities)
906901
: _create_latebound_entities(create_latebound_entities)
907-
, stream(0)
908902
, lastId(0)
909-
, tokens(0)
910903
, MaxId(0)
904+
, tokens(0)
905+
, stream(0)
911906
{
912907
setDefaultHeaderValues();
913908
}
@@ -1542,4 +1537,4 @@ std::pair<IfcSchema::IfcNamedUnit*, double> IfcFile::getUnit(IfcSchema::IfcUnitE
15421537
}
15431538
}
15441539
return return_value;
1545-
}
1540+
}

src/ifcparse/IfcSpfHeader.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ class HeaderEntity : public IfcAbstractEntity {
3434
HeaderEntity& operator =(const HeaderEntity&); //N/A
3535
protected:
3636
HeaderEntity(const char * const datatype, IfcSpfLexer* lexer)
37-
: _datatype(datatype), _list(0)
37+
: _list(0), _datatype(datatype)
3838
{
3939
std::vector<unsigned int> ids;
4040
_list = new ArgumentList();
@@ -193,4 +193,4 @@ class IfcSpfHeader {
193193

194194
}
195195

196-
#endif
196+
#endif

0 commit comments

Comments
 (0)