Skip to content

Commit

Permalink
Extract to function, protect against infinite loop
Browse files Browse the repository at this point in the history
Seems like under windows, the introduced relative path search can cause
an infinite loop if it doesn't match. Test for that, may need
adjustment.

Signed-off-by: Kimball Thurston <kdt3rd@gmail.com>
  • Loading branch information
kdt3rd committed Nov 7, 2019
1 parent 599e521 commit 89dceca
Showing 1 changed file with 21 additions and 30 deletions.
51 changes: 21 additions & 30 deletions PyIlmBase/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -55,48 +55,39 @@ 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)
get_filename_component(_exedir ${pyexe} DIRECTORY)
string(FIND ${pysitearch} ${_exedir} _findloc)
string(LENGTH ${_exedir} _elen)
while(_findloc EQUAL -1 AND _elen GREATER 0)
get_filename_component(_nexedir ${_exedir} DIRECTORY)
string(FIND ${pysitearch} ${_nexedir} _findloc)
if (_nexedir STREQUAL _exedir)
message(FATAL_ERROR "Unable to get parent directory for ${_exedir}")
else()
set(_exedir ${_nexedir})
endif()
string(LENGTH ${_exedir} _elen)
endwhile()
math(EXPR _elen "${_elen}+1")
string(SUBSTRING ${pysitearch} ${_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 Down

0 comments on commit 89dceca

Please sign in to comment.