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 bbc2093 commit 63de713
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 @@ -101,10 +101,19 @@ set_default_build_type("Release")

# Option to enable interprocedural optimization
# (also know as "link-time optimization" or "whole program optimization")
option(ImpactX_IPO "Compile ImpactX with interprocedural optimization (will take more time)" OFF)
set(_ImpactX_IPO_DEFAULT OFF)
set(_ImpactX_PYTHON_IPO_DEFAULT ON)
if(DEFINED CMAKE_INTERPROCEDURAL_OPTIMIZATION)
set(_ImpactX_IPO_DEFAULT ${CMAKE_INTERPROCEDURAL_OPTIMIZATION})
set(_ImpactX_PYTHON_IPO_DEFAULT ${CMAKE_INTERPROCEDURAL_OPTIMIZATION})
endif()
option(ImpactX_IPO
"Compile ImpactX with interprocedural optimization (will take more time)"
${_ImpactX_IPO_DEFAULT}
)
option(ImpactX_PYTHON_IPO
"Compile Python bindings with interprocedural optimization (IPO) / link-time optimization (LTO)"
ON
${_ImpactX_PYTHON_IPO_DEFAULT}
)

if(ImpactX_FFT)
Expand Down Expand Up @@ -244,15 +253,21 @@ set_target_properties(${_ALL_TARGETS} PROPERTIES

# Interprocedural optimization
if(ImpactX_IPO)
enable_IPO("${_ALL_TARGETS}")
impactx_enable_IPO("${_ALL_TARGETS}")
endif()

# link dependencies
target_link_libraries(lib PUBLIC ImpactX::thirdparty::ablastr_3d)
if(ImpactX_PYTHON)
target_link_libraries(pyImpactX PRIVATE pybind11::module pybind11::windows_extras)
if(ImpactX_PYTHON_IPO)
target_link_libraries(pyImpactX 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(pyImpactX PRIVATE pybind11::lto)
else()
impactx_enable_IPO(pyImpactX)
endif()
endif()
endif()

Expand Down
2 changes: 1 addition & 1 deletion cmake/ImpactXFunctions.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(impactx_enable_IPO all_targets_list)
include(CheckIPOSupported)
check_ipo_supported(RESULT is_IPO_available)
if(is_IPO_available)
Expand Down

0 comments on commit 63de713

Please sign in to comment.