Skip to content

Commit

Permalink
Fix CMake Python IPO Control
Browse files Browse the repository at this point in the history
`pybind11::lto` is only defined if `CMAKE_INTERPROCEDURAL_OPTIMIZATION`
is not set in `pybind11Common.cmake`. Package managers like Spack
use the latter.
  • Loading branch information
ax3l committed Jul 17, 2024
1 parent c54eff6 commit ab568a1
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
10 changes: 8 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,7 @@ endif()

# Interprocedural optimization (IPO) / Link-Time Optimization (LTO)
if(WarpX_IPO)
enable_IPO("${_ALL_TARGETS}")
warpx_enable_IPO("${_ALL_TARGETS}")
endif()

# link dependencies
Expand Down Expand Up @@ -488,7 +488,13 @@ foreach(D IN LISTS WarpX_DIMS)
if(WarpX_PYTHON)
target_link_libraries(pyWarpX_${SD} PRIVATE pybind11::module pybind11::windows_extras)
if(WarpX_PYTHON_IPO)
target_link_libraries(pyWarpX_${SD} PRIVATE pybind11::lto)
if(NOT DEFINED CMAKE_INTERPROCEDURAL_OPTIMIZATION)
# conditionally defined target in pybind11
# https://github.com/pybind/pybind11/blob/v2.12.0/tools/pybind11Common.cmake#L397-L403
target_link_libraries(pyWarpX_${SD} PRIVATE pybind11::lto)
else()
warpx_enable_IPO(pyWarpX_${SD})
endif()
endif()
endif()

Expand Down
2 changes: 1 addition & 1 deletion cmake/WarpXFunctions.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ endmacro()

# Enables interprocedural optimization for a list of targets
#
function(enable_IPO all_targets_list)
function(warpx_enable_IPO all_targets_list)
include(CheckIPOSupported)
check_ipo_supported(RESULT is_IPO_available)
if(is_IPO_available)
Expand Down

0 comments on commit ab568a1

Please sign in to comment.