Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfix cmake build for easybuild #121

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 25 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,33 @@ endif()

find_package(Python REQUIRED COMPONENTS Interpreter Development)

if (NOT PIVY_Python_SITEARCH)
SET(PIVY_Python_SITEARCH ${Python_SITEARCH})
endif()

if (Python_FOUND)
MESSAGE(STATUS "Python_FOUND: TRUE")
MESSAGE(STATUS "PIVY_Python_SITEARCH: ${PIVY_Python_SITEARCH}")
endif()

if (Coin_FOUND)
MESSAGE(STATUS "COIN_FOUND: TRUE")
MESSAGE(STATUS "COIN_INCLUDE_DIR: ${Coin_INCLUDE_DIR}")
MESSAGE(STATUS "COIN_LIB_DIR: ${Coin_LIB_DIR}")
MESSAGE(STATUS "COIN_VERSION: ${Coin_VERSION}")
endif()

if (SoQt_FOUND)
MESSAGE(STATUS "SOQT_FOUND: True")
MESSAGE(STATUS "SOQT_INCLUDE_DIRS: ${SoQt_INCLUDE_DIRS}")
MESSAGE(STATUS "SOQT_LIB_DIRS: ${SoQt_LIBRARY_DIRS}")
MESSAGE(STATUS "SOQT_VERSION: ${SoQt_VERSION}")
endif()

# SWIGIFY HEADERS
# doing this with the origin python functions

execute_process(COMMAND ${Python_EXECUTABLE} -c
"import sys; sys.path.append('${CMAKE_SOURCE_DIR}'); \
import install_helpers; install_helpers.swigify('${CMAKE_SOURCE_DIR}', '${Coin_INCLUDE_DIR}');")
execute_process(COMMAND ${Python_EXECUTABLE} ${CMAKE_SOURCE_DIR}/install_helpers.py ${CMAKE_SOURCE_DIR} ${Coin_INCLUDE_DIR})


# copy the python module
Expand All @@ -42,7 +63,7 @@ add_subdirectory(interfaces)

install(DIRECTORY
${CMAKE_BINARY_DIR}/pivy
DESTINATION ${Python_SITEARCH}
DESTINATION ${PIVY_Python_SITEARCH}
FILES_MATCHING
PATTERN "*.py"
PATTERN "*.so"
Expand Down
135 changes: 75 additions & 60 deletions install_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,63 +10,78 @@

"""

def copy_and_swigify_headers(includedir, dirname, files):
"""Copy the header files to the local include directories. Add an
#include line at the beginning for the SWIG interface files..."""

for file in files:
if not os.path.isfile(os.path.join(dirname, file)):
continue

if file[-2:] == ".i":
file = os.path.join(dirname, file)

file_i = file.split(os.path.sep)
file_i = [i for i in file_i if i != ".."]
file_i = os.path.join(*file_i)

file_h = file_i[:-2] + ".h"
from_file = os.path.join(includedir, file_h)

file_h = file[:-2] + ".h"
to_file = os.path.abspath(file_h)

if os.path.exists(from_file):
shutil.copyfile(from_file, to_file)
sys.stdout.write('create swigified header: ' + to_file + '\n')
fd = open(to_file, 'r+')
contents = fd.readlines()

ins_line_nr = -1
for line in contents:
ins_line_nr += 1
if line.find("#include ") != -1:
break

if ins_line_nr != -1:
contents.insert(ins_line_nr, PIVY_HEADER % (file_i))
fd.seek(0)
fd.writelines(contents)
else:
print("[failed]")
sys.exit(1)
fd.close
# fixes for SWIG 1.3.21 and upwards
# (mostly workarounding swig's preprocessor "function like macros"
# preprocessor bug when no parameters are provided which then results
# in no constructors being created in the wrapper)
elif file[-4:] == ".fix":
sys.stdout.write(' ' + os.path.join(dirname, file)[:-4])
shutil.copyfile(os.path.join(dirname, file),
os.path.join(dirname, file)[:-4])
# had to introduce this because windows is a piece of crap
elif sys.platform == "win32" and file[-6:] == ".win32":
sys.stdout.write(' ' + os.path.join(dirname, file)[:-6])
shutil.copyfile(os.path.join(dirname, file),
os.path.join(dirname, file)[:-6])


def swigify(interface_dir, include_dir):
dir_gen = os.walk(os.path.relpath(os.path.join(interface_dir, "Inventor")))
for _dir, _, names in dir_gen:
copy_and_swigify_headers(include_dir, _dir, names)

def swigify_header(header_file, include_file):
sys.stdout.write("create swigified header: " + header_file + "\n")

fd = open(header_file, "r+")
contents = fd.readlines()

ins_line_nr = -1
for line in contents:
ins_line_nr += 1
if line.find("#include ") != -1:
break

if ins_line_nr != -1:
contents.insert(ins_line_nr, PIVY_HEADER % (include_file))
fd.seek(0)
fd.writelines(contents)
else:
print("[failed]")
sys.exit(1)
fd.close


def copy_and_swigify_header(interface_dir, include_dir, fname):
"""Copy the header file to the local include directory. Add an
#include line at the beginning for the SWIG interface file..."""

if fname.endswith(".i"): # consider ".i" files
fname_h = fname[:-2] + ".h" # corresponding ".h" file
from_file = os.path.join(include_dir, fname_h)
to_file = os.path.join(interface_dir, fname_h)

elif fname.endswith(".fix"): # just drop the suffix
# fixes for SWIG 1.3.21 and upwards
# (mostly workarounding swig's preprocessor "function like macros"
# preprocessor bug when no parameters are provided which then results
# in no constructors being created in the wrapper)
fname_nosuffix = fname[:-4]
from_file = os.path.join(interface_dir, fname)
to_file = os.path.join(interface_dir, fname_nosuffix)

elif sys.platform == "win32" and fname.endswith(".win32"): # just drop the suffix
# had to introduce this because windows is a piece of crap
fname_nosuffix = fname[:-6]
from_file = os.path.join(interface_dir, fname)
to_file = os.path.join(interface_dir, fname_nosuffix)

else: # ignore other extensions
return

if not os.path.isfile(os.path.join(from_file)):
return

# copy
shutil.copyfile(from_file, to_file)

# and swigify
if fname.endswith(".i"): # consider ".i" files
swigify_header(to_file, fname)


def swigify(interface_dir, include_dir, component="Inventor"):
"""Prepare header files for SWIG"""

# find files within interface_dir/component
interface_walker = os.walk(os.path.join(interface_dir, component))
for dirpath, _, fnames in interface_walker:
for fname in fnames:
# only the filename relative to below interface_dir is needed
relative_fname = os.path.join(dirpath[1+len(interface_dir):], fname)
copy_and_swigify_header(interface_dir, include_dir, relative_fname)


if __name__ == "__main__":
swigify(sys.argv[1], sys.argv[2])
6 changes: 4 additions & 2 deletions interfaces/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ target_include_directories(coin
)

target_link_libraries(coin PUBLIC Coin::Coin)
install(TARGETS coin DESTINATION ${Python_SITEARCH}/pivy)
install(TARGETS coin DESTINATION ${PIVY_Python_SITEARCH}/pivy)


if (SoQt_FOUND)
Expand All @@ -52,6 +52,7 @@ if (SoQt_FOUND)
set_property(SOURCE soqt.i PROPERTY INCLUDE_DIRECTORIES "${CMAKE_SOURCE_DIR}")
set_property(SOURCE soqt.i APPEND PROPERTY INCLUDE_DIRECTORIES "${CMAKE_SOURCE_DIR}/fake_headers")
set_property(SOURCE soqt.i APPEND PROPERTY INCLUDE_DIRECTORIES "${SoQt_INCLUDE_DIRS}")
set_property(SOURCE soqt.i APPEND PROPERTY INCLUDE_DIRECTORIES "${Coin_INCLUDE_DIR}")


swig_add_library(soqt
Expand All @@ -68,6 +69,7 @@ if (SoQt_FOUND)

target_include_directories(soqt
PUBLIC
${Coin_INCLUDE_DIR}
${SoQt_INCLUDE_DIRS}
${Qt5Gui_INCLUDE_DIRS}
${Qt5Widgets_INCLUDE_DIRS}
Expand All @@ -77,5 +79,5 @@ if (SoQt_FOUND)
)

target_link_libraries(soqt PUBLIC SoQt::SoQt)
install(TARGETS soqt DESTINATION ${Python_SITEARCH}/pivy/gui)
install(TARGETS soqt DESTINATION ${PIVY_Python_SITEARCH}/pivy/gui)
endif()
Loading