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

Fixes #593, others - issues with pyilmbase install #609

Merged
merged 9 commits into from
Nov 7, 2019
60 changes: 29 additions & 31 deletions PyIlmBase/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -55,48 +55,47 @@ endif()
# for our other dependency - boost.
# Boost Python has some .. annoyances in that the python module
# has version names attached to it
function(PYILMBASE_EXTRACT_REL_SITEARCH varname pyver pyexe pysitearch)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I bet it's going to be far less work to port Imath to pybind11, than to deal with endless boost::python/cmake curveballs!

get_filename_component(_exedir ${pyexe} DIRECTORY)
# we do this such that cmake will canonicalize the slashes
# so the directory search will work under windows and unix
# consistently
get_filename_component(_basedir ${pysitearch} DIRECTORY)
get_filename_component(_basename ${pysitearch} NAME)
set(_basedir "${_basedir}/${_basename}")
string(FIND ${_basedir} ${_exedir} _findloc)
string(LENGTH ${_exedir} _elen)
while(_findloc EQUAL -1 AND _elen GREATER 0)
get_filename_component(_nexedir ${_exedir} DIRECTORY)
string(FIND ${_basedir} ${_nexedir} _findloc)
if (_nexedir STREQUAL _exedir)
message(WARNING "Unable to get parent directory for ${_exedir}, using absolute python site arch folder ${pysitearch}")
set(_elen -1)
break()
else()
set(_exedir ${_nexedir})
endif()
string(LENGTH ${_exedir} _elen)
endwhile()
math(EXPR _elen "${_elen}+1")
string(SUBSTRING ${_basedir} ${_elen} -1 _reldir)
set(${varname} ${_reldir} CACHE STRING "Destination sub-folder (relative) for the python ${pyver} modules")
endfunction()

if (TARGET Python2::Python)
set(PYILMBASE_BOOST_PY2_COMPONENT "python${Python2_VERSION_MAJOR}${Python2_VERSION_MINOR}")
message(STATUS "Found Python2 libraries: ${Python2_VERSION_MAJOR}${Python2_VERSION_MINOR}")
# we can't just use the Python2_SITEARCH variable as that then will
# ignore CMAKE_INSTALL_PREFIX. Could extract this to a function somewhere
# if it is generally useful
get_filename_component(_exedir ${Python2_EXECUTABLE} DIRECTORY)
string(FIND ${Python2_SITEARCH} ${_exedir} _findloc)
string(LENGTH ${_exedir} _elen)
while(_findloc EQUAL -1 AND _elen GREATER 0)
get_filename_component(_exedir ${_exedir} DIRECTORY)
string(FIND ${Python2_SITEARCH} ${_exedir} _findloc)
string(LENGTH ${_exedir} _elen)
endwhile()
math(EXPR _elen "${_elen}+1")
string(SUBSTRING ${Python2_SITEARCH} ${_elen} -1 _reldir)
set(PyIlmBase_Python2_SITEARCH_REL ${_reldir} CACHE STRING "Destination sub-folder (relative) for the python 2 modules")
unset(_elen)
unset(_exedir)
unset(_findloc)
unset(_reldir)
pyilmbase_extract_rel_sitearch(PyIlmBase_Python2_SITEARCH_REL 2 ${Python2_EXECUTABLE} ${Python2_SITEARCH})
message(STATUS " -> Installing to: \${CMAKE_INSTALL_PREFIX}/${PyIlmBase_Python2_SITEARCH_REL}")
endif()
if (TARGET Python3::Python)
set(PYILMBASE_BOOST_PY3_COMPONENT "python${Python3_VERSION_MAJOR}${Python3_VERSION_MINOR}")
message(STATUS "Found Python3 libraries: ${Python3_VERSION_MAJOR}${Python3_VERSION_MINOR}")
# and figure out the install root here
get_filename_component(_exedir ${Python3_EXECUTABLE} DIRECTORY)
string(FIND ${Python3_SITEARCH} ${_exedir} _findloc)
string(LENGTH ${_exedir} _elen)
while(_findloc EQUAL -1 AND _elen GREATER 0)
get_filename_component(_exedir ${_exedir} DIRECTORY)
string(FIND ${Python3_SITEARCH} ${_exedir} _findloc)
string(LENGTH ${_exedir} _elen)
endwhile()
math(EXPR _elen "${_elen}+1")
string(SUBSTRING ${Python3_SITEARCH} ${_elen} -1 _reldir)
set(PyIlmBase_Python3_SITEARCH_REL ${_reldir} CACHE STRING "Destination sub-folder (relative) for the python 3 modules")
unset(_elen)
unset(_exedir)
unset(_findloc)
unset(_reldir)
pyilmbase_extract_rel_sitearch(PyIlmBase_Python3_SITEARCH_REL 3 ${Python3_EXECUTABLE} ${Python3_SITEARCH})
message(STATUS " -> Installing to: \${CMAKE_INSTALL_PREFIX}/${PyIlmBase_Python3_SITEARCH_REL}")
endif()
# different flavors of O.S. have multiple versions of python
Expand All @@ -106,7 +105,6 @@ endif()
# let's run a search and see what we get instead of making it
# an explicit required. The older names are not portable, but
# we'll do the best we can
meshula marked this conversation as resolved.
Show resolved Hide resolved
set(Boost_NO_BOOST_CMAKE ON)
find_package(Boost OPTIONAL_COMPONENTS
python
python2
Expand Down