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 3db8f0c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
23 changes: 19 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -146,10 +146,19 @@ set_default_build_type("Release")

# Option to enable interprocedural optimization
# (also know as "link-time optimization" or "whole program optimization")
option(WarpX_IPO "Compile WarpX with interprocedural optimization (will take more time)" OFF)
set(_WarpX_IPO_DEFAULT OFF)
set(_WarpX_PYTHON_IPO_DEFAULT ON)
if(DEFINED CMAKE_INTERPROCEDURAL_OPTIMIZATION)
set(_WarpX_IPO_DEFAULT ${CMAKE_INTERPROCEDURAL_OPTIMIZATION})
set(_WarpX_PYTHON_IPO_DEFAULT ${CMAKE_INTERPROCEDURAL_OPTIMIZATION})
endif()
option(WarpX_IPO
"Compile WarpX with interprocedural optimization (will take more time)"
${_WarpX_IPO_DEFAULT}
)
option(WarpX_PYTHON_IPO
"Compile Python bindings with interprocedural optimization (IPO) / link-time optimization (LTO)"
ON
${_WarpX_PYTHON_IPO_DEFAULT}
)

set(pyWarpX_VERSION_INFO "" CACHE STRING
Expand Down Expand Up @@ -455,7 +464,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 +497,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(DEFINED CMAKE_INTERPROCEDURAL_OPTIMIZATION)
warpx_enable_IPO(pyWarpX_${SD})
else()
# 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)
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 3db8f0c

Please sign in to comment.