Skip to content

Commit 4122759

Browse files
committed
Add option to compile (external) schema by cmake
1 parent a583339 commit 4122759

File tree

4 files changed

+79
-16
lines changed

4 files changed

+79
-16
lines changed

cmake/CMakeLists.txt

Lines changed: 67 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ UNIFY_ENVVARS_AND_CACHE(ICU_LIBRARY_DIR)
4747
UNIFY_ENVVARS_AND_CACHE(OPENCOLLADA_INCLUDE_DIR)
4848
UNIFY_ENVVARS_AND_CACHE(OPENCOLLADA_LIBRARY_DIR)
4949
UNIFY_ENVVARS_AND_CACHE(PCRE_LIBRARY_DIR)
50+
UNIFY_ENVVARS_AND_CACHE(PYTHON_EXECUTABLE)
5051

5152
# Find Boost
5253
IF(MSVC)
@@ -274,25 +275,78 @@ if(NOT WIN32)
274275
INCLUDE_DIRECTORIES(${INCLUDE_DIRECTORIES} /usr/inc /usr/local/inc /usr/local/include/oce)
275276
endif()
276277

277-
IF(USE_IFC4)
278-
ADD_DEFINITIONS(-DUSE_IFC4)
279-
SET(IFC_RELEASE_NOT_USED "2x3")
280-
ELSE()
281-
ADD_DEFINITIONS(-DUSE_IFC2x3) # TODO Make all caps? i.e. USE_IFC2X3
282-
SET(IFC_RELEASE_NOT_USED "4")
283-
ENDIF()
278+
function(files_for_ifc_version IFC_VERSION RESULT_NAME)
279+
set(IFC_PARSE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../src/ifcparse)
280+
set(${RESULT_NAME}
281+
${IFC_PARSE_DIR}/Ifc${IFC_VERSION}.h
282+
${IFC_PARSE_DIR}/Ifc${IFC_VERSION}enum.h
283+
${IFC_PARSE_DIR}/Ifc${IFC_VERSION}-latebound.h
284+
${IFC_PARSE_DIR}/Ifc${IFC_VERSION}.cpp
285+
${IFC_PARSE_DIR}/Ifc${IFC_VERSION}-latebound.cpp
286+
PARENT_SCOPE
287+
)
288+
endfunction()
289+
290+
if(COMPILE_SCHEMA)
291+
set(IFC_RELEASE_NOT_USED "2x3" "4")
292+
293+
if(PYTHON_EXECUTABLE)
294+
set(PYTHON_EXECUTABLE_USED ${PYTHON_EXECUTABLE})
295+
else()
296+
set(PYTHON_EXECUTABLE_USED "python")
297+
endif()
298+
299+
# Install pyparsing if necessary
300+
execute_process(COMMAND ${PYTHON_EXECUTABLE_USED} -m pip "list" OUTPUT_VARIABLE PYTHON_PACKAGE_LIST)
301+
string(FIND "${PYTHON_PACKAGE_LIST}" pyparsing PYPARSING_FOUND)
302+
if ("${PYPARSING_FOUND}" STREQUAL "-1")
303+
message(STATUS "Installing pyparsing")
304+
execute_process(COMMAND ${PYTHON_EXECUTABLE_USED} -m pip "install" --user pyparsing)
305+
else()
306+
message(STATUS "Python interpreter with pyparsing found")
307+
endif()
308+
309+
# Bootstrap the parser
310+
message(STATUS "Compiling schema, this will take a while...")
311+
execute_process(COMMAND ${PYTHON_EXECUTABLE_USED} bootstrap.py express.bnf
312+
WORKING_DIRECTORY ../src/ifcexpressparser
313+
OUTPUT_FILE express_parser.py)
314+
315+
# Generate code
316+
execute_process(COMMAND ${PYTHON_EXECUTABLE_USED} ../ifcexpressparser/express_parser.py ../../${COMPILE_SCHEMA}
317+
WORKING_DIRECTORY ../src/ifcparse
318+
OUTPUT_VARIABLE COMPILED_SCHEMA_NAME)
319+
320+
# Prevent the schema that had just been compiled from being excluded
321+
if(${COMPILED_SCHEMA_NAME} STREQUAL "IFC2X3")
322+
list(REMOVE_ITEM IFC_RELEASE_NOT_USED "2x3")
323+
elseif(${COMPILED_SCHEMA_NAME} STREQUAL "IFC4")
324+
list(REMOVE_ITEM IFC_RELEASE_NOT_USED "4")
325+
endif()
326+
else()
327+
if(USE_IFC4)
328+
add_definitions(-DUSE_IFC4)
329+
set(IFC_RELEASE_NOT_USED "2x3")
330+
else()
331+
add_definitions(-DUSE_IFC2x3) # TODO Make all caps? i.e. USE_IFC2X3
332+
set(IFC_RELEASE_NOT_USED "4")
333+
endif()
334+
endif()
284335

285336
# IfcParse
286337
file(GLOB CPP_FILES ../src/ifcparse/*.cpp)
287338
file(GLOB H_FILES ../src/ifcparse/*.h)
288339
set(SOURCE_FILES ${CPP_FILES} ${H_FILES})
289-
# Remove sources specific to an IFC release we are not using
290-
list(REMOVE_ITEM SOURCE_FILES ${CMAKE_CURRENT_SOURCE_DIR}/../src/ifcparse/Ifc${IFC_RELEASE_NOT_USED}.h)
291-
list(REMOVE_ITEM SOURCE_FILES ${CMAKE_CURRENT_SOURCE_DIR}/../src/ifcparse/Ifc${IFC_RELEASE_NOT_USED}enum.h)
292-
list(REMOVE_ITEM SOURCE_FILES ${CMAKE_CURRENT_SOURCE_DIR}/../src/ifcparse/Ifc${IFC_RELEASE_NOT_USED}-latebound.h)
293-
list(REMOVE_ITEM SOURCE_FILES ${CMAKE_CURRENT_SOURCE_DIR}/../src/ifcparse/Ifc${IFC_RELEASE_NOT_USED}.cpp)
294-
list(REMOVE_ITEM SOURCE_FILES ${CMAKE_CURRENT_SOURCE_DIR}/../src/ifcparse/Ifc${IFC_RELEASE_NOT_USED}-latebound.cpp)
340+
341+
foreach(IFC_RELEASE ${IFC_RELEASE_NOT_USED})
342+
files_for_ifc_version(${IFC_RELEASE} SOURCE_FILES_NOT_USED)
343+
foreach(SOURCE_FILE ${SOURCE_FILES_NOT_USED})
344+
list(REMOVE_ITEM SOURCE_FILES ${SOURCE_FILE})
345+
endforeach()
346+
endforeach()
347+
295348
ADD_LIBRARY(IfcParse STATIC ${SOURCE_FILES})
349+
296350
IF(UNICODE_SUPPORT)
297351
TARGET_LINK_LIBRARIES(IfcParse ${ICU_LIBRARIES})
298352
ENDIF()

src/ifcexpressparser/bootstrap.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,4 +184,6 @@ def find_keywords(expr, li = None):
184184
implementation.Implementation(mapping).emit()
185185
latebound_header.LateBoundHeader(mapping).emit()
186186
latebound_implementation.LateBoundImplementation(mapping).emit()
187+
188+
sys.stdout.write(schema.name)
187189
"""%('\n'.join(statements)))

src/ifcexpressparser/documentation.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,30 +27,35 @@
2727
# #
2828
###############################################################################
2929

30-
import re,csv
30+
import re
31+
import os
3132
import csv
33+
3234
try: from html.entities import entitydefs
3335
except: from htmlentitydefs import entitydefs
3436

37+
make_absolute = lambda fn: os.path.join(os.path.dirname(os.path.realpath(__file__)), fn)
38+
3539
name_to_oid = {}
3640
oid_to_desc = {}
3741
oid_to_name = {}
3842
oid_to_pid = {}
3943
regices = list(zip([re.compile(s,re.M) for s in [r'<[\w\n=" \-/\.;_\t:%#,\?\(\)]+>',r'(\n[\t ]*){2,}',r'^[\t ]+']],['','\n\n',' ']))
4044

4145
definition_files = ['DocEntity.csv', 'DocEnumeration.csv', 'DocDefined.csv', 'DocSelect.csv']
46+
definition_files = map(make_absolute, definition_files)
4247
for fn in definition_files:
4348
with open(fn) as f:
4449
for oid, name, desc in csv.reader(f, delimiter=';', quotechar='"'):
4550
name_to_oid[name] = oid
4651
oid_to_name[oid] = name
4752
oid_to_desc[oid] = desc
4853

49-
with open('DocEntityAttributes.csv') as f:
54+
with open(make_absolute('DocEntityAttributes.csv')) as f:
5055
for pid, x, oid in csv.reader(f, delimiter=';', quotechar='"'):
5156
oid_to_pid[oid] = pid
5257

53-
with open('DocAttribute.csv') as f:
58+
with open(make_absolute('DocAttribute.csv')) as f:
5459
for oid, name, desc in csv.reader(f, delimiter=';', quotechar='"'):
5560
pid = oid_to_pid[oid]
5661
pname = oid_to_name[pid]

win/run-cmake.bat

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ if not defined PY_VER_MAJOR_MINOR set PY_VER_MAJOR_MINOR=34
5656
if not defined PYTHONPATH set PYTHONPATH=%INSTALL_DIR%\Python%PY_VER_MAJOR_MINOR%
5757
set PYTHON_INCLUDE_DIR=%PYTHONPATH%\include
5858
set PYTHON_LIBRARY=%PYTHONPATH%\libs\python%PY_VER_MAJOR_MINOR%.lib
59+
set PYTHON_EXECUTABLE=%PYTHONPATH%\python.exe
5960
set SWIG_DIR=%INSTALL_DIR%\swigwin
6061
set PATH=%PATH%;%SWIG_DIR%;%PYTHONPATH%
6162
:: TODO 3ds Max SDK?
@@ -77,6 +78,7 @@ echo OPENCOLLADA_LIBRARY_DIR = %OPENCOLLADA_LIBRARY_DIR%
7778
echo PYTHONPATH = %PYTHONPATH%
7879
echo PYTHON_INCLUDE_DIR = %PYTHON_INCLUDE_DIR%
7980
echo PYTHON_LIBRARY = %PYTHON_LIBRARY%
81+
echo PYTHON_EXECUTABLE = %PYTHON_EXECUTABLE%
8082
echo SWIG_DIR = %SWIG_DIR%
8183
echo.
8284
echo CMAKE_INSTALL_PREFIX = %CMAKE_INSTALL_PREFIX%

0 commit comments

Comments
 (0)