Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix CMake Python IPO Control #644

Merged
merged 1 commit into from
Jul 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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(DEFINED CMAKE_INTERPROCEDURAL_OPTIMIZATION)
impactx_enable_IPO(pyImpactX)
else()
# 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)
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
Loading