Skip to content

Commit

Permalink
PyTrilinos2: CMake cleanup
Browse files Browse the repository at this point in the history
Signed-off-by: Christian Glusa <[email protected]>
  • Loading branch information
cgcgcg committed Jan 10, 2025
1 parent 21444c5 commit 132611d
Showing 1 changed file with 23 additions and 27 deletions.
50 changes: 23 additions & 27 deletions packages/PyTrilinos2/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,18 @@
# Set the package name
TRIBITS_PACKAGE(PyTrilinos2 DISABLE_STRONG_WARNINGS)

ASSERT_DEFINED(
BUILD_SHARED_LIBS
Python3_EXECUTABLE
Python3_VERSION_MAJOR
Python3_VERSION_MINOR
${PACKAGE_NAME}_ENABLE_MueLu
Tpetra_INST_OPENMP
BINDER_EXECUTABLE
)

###################################################################################################

IF(NOT BUILD_SHARED_LIBS)
MESSAGE(WARNING "PyTrilinos2 can be built with static linking, but might require building with position-independent code. If you encounter build errors please add \"-fPIC\" to CMAKE_C_FLAGS, CMAKE_C_FLAGS and CMAKE_Fortran_FLAGS.")
ENDIF()
Expand Down Expand Up @@ -28,6 +40,8 @@ TRIBITS_ADD_OPTION_AND_DEFINE(PyTrilinos2_BINDER_VERBOSE
"Increase the verbosity of binder."
OFF )

###################################################################################################

SET(PyTrilinos2_BINDER_NUM_FILES "150" CACHE STRING "Maxinum number of generated files by binder.")

function(get_all_include_dirs LIBRARY_NAME all_include_dirs all_visited_libs)
Expand All @@ -54,7 +68,6 @@ endfunction()
FILE(GLOB PyTrilinos2PyFiles ${CMAKE_CURRENT_SOURCE_DIR}/python/*.py)
file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/PyTrilinos2)

set(PyTrilinos2_BINDER_EXECUTABLE ${BINDER_EXECUTABLE})
file(REMOVE_RECURSE ${CMAKE_CURRENT_BINARY_DIR}/include_tmp)
file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/include_tmp)
file(REMOVE_RECURSE ${CMAKE_CURRENT_BINARY_DIR}/binder)
Expand Down Expand Up @@ -127,6 +140,7 @@ file(WRITE ${all_include_list} ${CONTENTS})
set(eti_files_with_dir "")
set(eti_files_without_dir "")

###################################################################################################
# Get ETI files for Tpetra:
file(GLOB tpetra_ETI_files
"${CMAKE_CURRENT_BINARY_DIR}/../tpetra/core/src/*.cpp"
Expand Down Expand Up @@ -191,10 +205,6 @@ add_custom_command(
add_custom_target(generate_include_name DEPENDS ${binder_include_name})
add_dependencies(generate_include_name generate_ETI_name)

ASSERT_DEFINED(
${PACKAGE_NAME}_ENABLE_MueLu
)

set(BINDER_OPTIONS "")
list(APPEND BINDER_OPTIONS --root-module PyTrilinos2)
list(APPEND BINDER_OPTIONS --prefix ${CMAKE_CURRENT_BINARY_DIR}/binder)
Expand Down Expand Up @@ -245,10 +255,6 @@ IF(NOT DEFINED PyTrilinos2_BINDER_GCC_TOOLCHAIN)
ELSE()
list(APPEND BINDER_OPTIONS --gcc-toolchain=${PyTrilinos2_BINDER_GCC_TOOLCHAIN})
ENDIF()

ASSERT_DEFINED(
Tpetra_INST_OPENMP
)
IF (Tpetra_INST_OPENMP)
list(APPEND BINDER_OPTIONS "-fopenmp")
ENDIF()
Expand All @@ -261,7 +267,7 @@ message("BINDER_OPTIONS='${BINDER_OPTIONS}'")

add_custom_command(
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/binder/PyTrilinos2.cpp
COMMAND ${PyTrilinos2_BINDER_EXECUTABLE} ${binder_include_name} ${BINDER_OPTIONS}
COMMAND ${BINDER_EXECUTABLE} ${binder_include_name} ${BINDER_OPTIONS}
DEPENDS ${binder_include_name} generate_include_name
)
add_custom_target(binder_call DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/binder/PyTrilinos2.cpp)
Expand All @@ -273,29 +279,14 @@ ELSE()
SET(PyTrilinos2_DEFAULT_INSTALL_PREFIX ${CMAKE_INSTALL_PREFIX})
ENDIF()

###################################################################################################
# Set the PyTrilinos2 install prefix
SET(PyTrilinos2_INSTALL_PREFIX ${PyTrilinos2_DEFAULT_INSTALL_PREFIX}
CACHE PATH "The path prefix for where PyTrilinos2 will be installed, e.g. /usr/local")

# Get the python version
EXECUTE_PROCESS(COMMAND ${Python3_EXECUTABLE} -c
"import sys; print(sys.version_info.major)"
OUTPUT_VARIABLE PYTHON_MAJOR_VERSION
OUTPUT_STRIP_TRAILING_WHITESPACE
)
EXECUTE_PROCESS(COMMAND ${Python3_EXECUTABLE} -c
"import sys; print(sys.version_info.minor)"
OUTPUT_VARIABLE PYTHON_MINOR_VERSION
OUTPUT_STRIP_TRAILING_WHITESPACE
)

SET(PYTHON_VERSION ${PYTHON_MAJOR_VERSION}.${PYTHON_MINOR_VERSION})

SET(PYBIND11_PYTHON_VERSION ${PYTHON_VERSION})

# Determine the install directory
SET(PyTrilinos2_INSTALL_DIR
${PyTrilinos2_INSTALL_PREFIX}/lib/python${PYTHON_VERSION}/site-packages/PyTrilinos2
${PyTrilinos2_INSTALL_PREFIX}/lib/python${Python3_VERSION_MAJOR}.${Python3_VERSION_MINOR}/site-packages/PyTrilinos2
CACHE PATH "The path where PyTrilinos2 will be installed"
)
MESSAGE(STATUS "PyTrilinos2 installation path: ${PyTrilinos2_INSTALL_DIR}")
Expand All @@ -304,6 +295,9 @@ INSTALL(FILES
${CMAKE_CURRENT_BINARY_DIR}/python/getTpetraTypeName.py
DESTINATION ${PyTrilinos2_INSTALL_DIR})

###################################################################################################
# mpi4py

EXECUTE_PROCESS(COMMAND
${Python3_EXECUTABLE} -c "import mpi4py; print(mpi4py.get_include())"
OUTPUT_VARIABLE Mpi4Py_INCLUDE_DIR
Expand All @@ -327,6 +321,8 @@ IF(NOT ${Mpi4Py_MPICXX} STREQUAL ${CMAKE_CXX_COMPILER})
MESSAGE(WARNING "the cpp compiler used to compile mpi4py ${Mpi4Py_MPICXX} is not consistent with CMAKE_CXX_COMPILER = ${CMAKE_CXX_COMPILER}")
ENDIF()

###################################################################################################

ADD_SUBDIRECTORY( src )

#file (GLOB PyTrilinos2PyFilesSo "${CMAKE_CURRENT_BINARY_DIR}/src/*.so")
Expand Down

0 comments on commit 132611d

Please sign in to comment.