Skip to content

Commit

Permalink
CMake Python Tests: Multi-Config Hints
Browse files Browse the repository at this point in the history
Make sure that we can find the extra build config suffix directory
that is appended in multi-config generators.
  • Loading branch information
ax3l committed Sep 7, 2022
1 parent 4d16d49 commit 0ec199b
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 5 deletions.
19 changes: 19 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,25 @@ if(ImpactX_PYTHON)
PDB_OUTPUT_DIRECTORY ${CMAKE_PYTHON_OUTPUT_DIRECTORY}/impactx
COMPILE_PDB_OUTPUT_DIRECTORY ${CMAKE_PYTHON_OUTPUT_DIRECTORY}/impactx
)
foreach(CFG IN LISTS CMAKE_CONFIGURATION_TYPES)
string(TOUPPER "${CFG}" CFG_UPPER)
list(LENGTH CMAKE_CONFIGURATION_TYPES NUM_BUILD_CFG)
if(NUM_BUILD_CFG GREATER 1)
set(CFG_SUBDIR "${CFG}/")
else()
set(CFG_SUBDIR "")
endif()

set_target_properties(pyImpactX PROPERTIES
# build output directories - mainly set to run tests from CMake & IDEs
# note: same as above, but for Multi-Config generators
ARCHIVE_OUTPUT_DIRECTORY_${CFG_UPPER} ${CMAKE_PYTHON_OUTPUT_DIRECTORY}/${CFG_SUBDIR}impactx
LIBRARY_OUTPUT_DIRECTORY_${CFG_UPPER} ${CMAKE_PYTHON_OUTPUT_DIRECTORY}/${CFG_SUBDIR}impactx
RUNTIME_OUTPUT_DIRECTORY_${CFG_UPPER} ${CMAKE_PYTHON_OUTPUT_DIRECTORY}/${CFG_SUBDIR}impactx
PDB_OUTPUT_DIRECTORY_${CFG_UPPER} ${CMAKE_PYTHON_OUTPUT_DIRECTORY}/${CFG_SUBDIR}impactx
COMPILE_PDB_OUTPUT_DIRECTORY_${CFG_UPPER} ${CMAKE_PYTHON_OUTPUT_DIRECTORY}/${CFG_SUBDIR}impactx
)
endforeach()
if(EMSCRIPTEN)
set_target_properties(pyImpactX PROPERTIES
PREFIX "")
Expand Down
13 changes: 10 additions & 3 deletions cmake/ImpactXFunctions.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -128,15 +128,22 @@ endmacro()
# this avoids that we need to install our python packages to run ctest
#
function(impactx_test_set_pythonpath test_name)
list(LENGTH CMAKE_CONFIGURATION_TYPES NUM_BUILD_CFG)
if(GENERATOR_IS_MULTI_CONFIG AND NUM_BUILD_CFG GREATER 1)
set(PY_SITE_PACKAGES_BASE ${CMAKE_PYTHON_OUTPUT_DIRECTORY}/$<CONFIG>)
else()
set(PY_SITE_PACKAGES_BASE ${CMAKE_PYTHON_OUTPUT_DIRECTORY})
endif()

if(WIN32)
string(REPLACE ";" "\\;" WIN_PYTHONPATH "$ENV{PYTHONPATH}")
string(REGEX REPLACE "/" "\\\\" WIN_PYTHON_OUTPUT_DIRECTORY ${CMAKE_PYTHON_OUTPUT_DIRECTORY})
string(REGEX REPLACE "/" "\\\\" WIN_PYTHON_OUTPUT_DIRECTORY ${PY_SITE_PACKAGES_BASE})
set_property(TEST ${test_name}
APPEND PROPERTY ENVIRONMENT "PYTHONPATH=${WIN_PYTHON_OUTPUT_DIRECTORY}\;${WIN_PYTHONPATH}"
APPEND PROPERTY ENVIRONMENT "PYTHONPATH=${WIN_PYTHON_OUTPUT_DIRECTORY}\;${WIN_PYTHONPATH}"
)
else()
set_property(TEST ${test_name}
APPEND PROPERTY ENVIRONMENT "PYTHONPATH=${CMAKE_PYTHON_OUTPUT_DIRECTORY}:$ENV{PYTHONPATH}"
APPEND PROPERTY ENVIRONMENT "PYTHONPATH=${PY_SITE_PACKAGES_BASE}:$ENV{PYTHONPATH}"
)
endif()
endfunction()
Expand Down
5 changes: 3 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,9 +143,10 @@ def build_extension(self, ext):

if platform.system() == "Windows":
cmake_args += [
"-DCMAKE_LIBRARY_OUTPUT_DIRECTORY_{}={}".format(
"-DCMAKE_CONFIGURATION_TYPES={}".format(cfg),
"-DCMAKE_LIBRARY_OUTPUT_DIRECTORY_{}={}".format( # ...
cfg.upper(), os.path.join(extdir, "impactx")
)
),
]
if sys.maxsize > 2**32:
cmake_args += ["-A", "x64"]
Expand Down

0 comments on commit 0ec199b

Please sign in to comment.