Skip to content

Commit

Permalink
Fix variety of issues in pxrConfig.cmake
Browse files Browse the repository at this point in the history
- Fix broken checks for empty strings. In CMake all strings
  except for certain special constants evaluate to False.
  This caused the various Python arguments to not be set
  properly.

- Use bracket arguments for file paths to avoid string
  parsing issues. On Windows, paths with backslashes
  could cause string parsing errors since they would
  mistakenly be interpreted as containing invalid escape
  sequences. CMake does not evaluate escape sequences in
  bracket arguments, sidestepping this problem.

Fixes #2091

(Internal change: 2256678)
  • Loading branch information
sunyab authored and pixar-oss committed Dec 8, 2022
1 parent 418df21 commit a7fd465
Showing 1 changed file with 30 additions and 14 deletions.
44 changes: 30 additions & 14 deletions pxr/pxrConfig.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -23,30 +23,42 @@ set(PXR_VERSION "@PXR_VERSION@")
# running cmake.
if(@PXR_ENABLE_PYTHON_SUPPORT@)
if(@PXR_USE_PYTHON_3@)
if (NOT DEFINED Python3_EXECUTABLE AND "@Python3_EXECUTABLE@")
set(Python3_EXECUTABLE "@Python3_EXECUTABLE@")
if (NOT DEFINED Python3_EXECUTABLE)
if (NOT [[@Python3_EXECUTABLE@]] STREQUAL "")
set(Python3_EXECUTABLE [[@Python3_EXECUTABLE@]])
endif()
endif()

if (NOT DEFINED Python3_LIBRARY AND "@Python3_LIBRARY@")
set(Python3_LIBRARY "@Python3_LIBRARY@")
if (NOT DEFINED Python3_LIBRARY)
if (NOT [[@Python3_LIBRARY@]] STREQUAL "")
set(Python3_LIBRARY [[@Python3_LIBRARY@]])
endif()
endif()

if (NOT DEFINED Python3_INCLUDE_DIR AND "@Python3_INCLUDE_DIR@")
set(Python3_INCLUDE_DIR "@Python3_INCLUDE_DIR@")
if (NOT DEFINED Python3_INCLUDE_DIR)
if (NOT [[@Python3_INCLUDE_DIR@]] STREQUAL "")
set(Python3_INCLUDE_DIR [[@Python3_INCLUDE_DIR@]])
endif()
endif()

find_package(Python3 COMPONENTS Development REQUIRED)
else()
if (NOT DEFINED Python2_EXECUTABLE AND "@Python2_EXECUTABLE@")
set(Python2_EXECUTABLE "@Python2_EXECUTABLE@")
if (NOT DEFINED Python2_EXECUTABLE)
if (NOT [[@Python2_EXECUTABLE@]] STREQUAL "")
set(Python2_EXECUTABLE [[@Python2_EXECUTABLE@]])
endif()
endif()

if (NOT DEFINED Python2_LIBRARY AND "@Python2_LIBRARY@")
set(Python2_LIBRARY "@Python2_LIBRARY@")
if (NOT DEFINED Python2_LIBRARY)
if (NOT [[@Python2_LIBRARY@]] STREQUAL "")
set(Python2_LIBRARY [[@Python2_LIBRARY@]])
endif()
endif()

if (NOT DEFINED Python2_INCLUDE_DIR AND "@Python2_INCLUDE_DIR@")
set(Python2_INCLUDE_DIR "@Python2_INCLUDE_DIR@")
if (NOT DEFINED Python2_INCLUDE_DIR)
if (NOT [[@Python2_INCLUDE_DIR@]] STREQUAL "")
set(Python2_INCLUDE_DIR [[@Python2_INCLUDE_DIR@]])
endif()
endif()

find_package(Python2 COMPONENTS Development REQUIRED)
Expand All @@ -60,7 +72,9 @@ endif()
# specifying a different MaterialX_DIR when running cmake.
if(@PXR_ENABLE_MATERIALX_SUPPORT@)
if (NOT DEFINED MaterialX_DIR)
set(MaterialX_DIR "@MaterialX_DIR@")
if (NOT [[@MaterialX_DIR@]] STREQUAL "")
set(MaterialX_DIR [[@MaterialX_DIR@]])
endif()
endif()
find_package(MaterialX REQUIRED)
endif()
Expand All @@ -72,7 +86,9 @@ endif()
# used instead of OpenExr (refer Packages.cmake)
if(@Imath_FOUND@)
if (NOT DEFINED Imath_DIR)
set(Imath_DIR "@Imath_DIR@")
if (NOT [[@Imath_DIR@]] STREQUAL "")
set(Imath_DIR [[@Imath_DIR@]])
endif()
endif()
find_package(Imath REQUIRED)
endif()
Expand Down

0 comments on commit a7fd465

Please sign in to comment.