Skip to content

Commit

Permalink
Support pykokkos-base as subproject with existing kokkos (#35)
Browse files Browse the repository at this point in the history
* Support pykokkos-base as subproject with existing kokkos

* Check for pybind11::pybind11 target
  • Loading branch information
jrmadsen authored Apr 27, 2022
1 parent fad4a42 commit c646c40
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 8 deletions.
6 changes: 6 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ PROJECT(
LANGUAGES C CXX
VERSION ${pykokkos-base_VERSION})

IF("${CMAKE_SOURCE_DIR}" STREQUAL "${PROJECT_SOURCE_DIR}")
SET(PYKOKKOS_BASE_MAIN_PROJECT ON)
ELSE()
SET(PYKOKKOS_BASE_MAIN_PROJECT OFF)
ENDIF()

INCLUDE(KokkosPythonUtilities) # miscellaneous macros and functions

ADD_OPTION(BUILD_SHARED_LIBS "Build shared libraries" ON)
Expand Down
21 changes: 19 additions & 2 deletions cmake/Modules/KokkosPythonKokkos.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -9,27 +9,44 @@ INCLUDE(KokkosPythonUtilities) # miscellaneous macros and functions

# if first time cmake is run and no external/internal preference is specified,
# try to find already installed kokkos
IF(NOT DEFINED ENABLE_INTERNAL_KOKKOS)
IF(NOT DEFINED ENABLE_INTERNAL_KOKKOS AND NOT TARGET Kokkos::kokkoscore)
FIND_PACKAGE(Kokkos)
# set the default cache value
IF(Kokkos_FOUND)
SET(_INTERNAL_KOKKOS OFF)
ELSE()
SET(_INTERNAL_KOKKOS ON)
ENDIF()
ELSEIF(TARGET Kokkos::kokkoscore)
SET(_INTERNAL_KOKKOS OFF)
ELSE()
# make sure ADD_OPTION in KokkosPythonOptions has a value
SET(_INTERNAL_KOKKOS ${ENABLE_INTERNAL_KOKKOS})
ENDIF()

# force an error
IF(NOT _INTERNAL_KOKKOS)
IF(NOT _INTERNAL_KOKKOS AND NOT TARGET Kokkos::kokkoscore)
FIND_PACKAGE(Kokkos REQUIRED COMPONENTS launch_compiler)
kokkos_compilation(GLOBAL)
IF(NOT Kokkos_INCLUDE_DIR)
GET_TARGET_PROPERTY(Kokkos_INCLUDE_DIR Kokkos::kokkoscore INTERFACE_INCLUDE_DIRECTORIES)
ENDIF()

FIND_FILE(Kokkos_InterOp_Header
NO_DEFAULT_PATH
NAMES Kokkos_InterOp.hpp KokkosExp_InterOp.hpp
PATHS ${Kokkos_INCLUDE_DIR} ${Kokkos_DIR}
HINTS ${Kokkos_INCLUDE_DIR} ${Kokkos_DIR}
DOC "Path to Kokkos InterOp header"
PATH_SUFFIXES include ../../../include)

ADD_FEATURE(Kokkos_CXX_COMPILER "Compiler used to build Kokkos")
ADD_FEATURE(Kokkos_CXX_COMPILER_ID "Compiler ID used to build Kokkos")
ELSEIF(TARGET Kokkos::kokkoscore)
IF(NOT Kokkos_INCLUDE_DIR)
GET_TARGET_PROPERTY(Kokkos_INCLUDE_DIR Kokkos::kokkoscore INTERFACE_INCLUDE_DIRECTORIES)
ENDIF()

FIND_FILE(Kokkos_InterOp_Header
NO_DEFAULT_PATH
NAMES Kokkos_InterOp.hpp KokkosExp_InterOp.hpp
Expand Down
11 changes: 7 additions & 4 deletions cmake/Modules/KokkosPythonOptions.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,14 @@ ADD_OPTION(ENABLE_LAYOUTS "Build support for layouts (long NVCC compile times)"
ADD_OPTION(ENABLE_MEMORY_TRAITS "Build support for memory traits (long NVCC compile times)"
${_ENABLE_MEM_DEFAULT})
ADD_OPTION(ENABLE_PRECOMPILED_HEADERS "Enable precompiling kokkos and pybind11 headers" OFF)
ADD_OPTION(CMAKE_UNITY_BUILD "Enable unity build" ${_UNITY_BUILD})

IF(CMAKE_UNITY_BUILD)
SET(CMAKE_UNITY_BUILD_BATCH_SIZE 8 CACHE STRING "Unity build batch size")
ADD_FEATURE(CMAKE_UNITY_BUILD_BATCH_SIZE "Unity build batch size")
IF(PYKOKKOS_BASE_MAIN_PROJECT)
ADD_OPTION(CMAKE_UNITY_BUILD "Enable unity build" ${_UNITY_BUILD})

IF(CMAKE_UNITY_BUILD)
SET(CMAKE_UNITY_BUILD_BATCH_SIZE 8 CACHE STRING "Unity build batch size")
ADD_FEATURE(CMAKE_UNITY_BUILD_BATCH_SIZE "Unity build batch size")
ENDIF()
ENDIF()

SET(ENABLE_VIEW_RANKS "4" CACHE STRING "${_VIEW_RANK_MSG}")
Expand Down
4 changes: 2 additions & 2 deletions cmake/Modules/KokkosPythonPackages.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ ADD_FEATURE(Python3_INCLUDE_DIR "Python include directory")
ADD_FEATURE(Python3_LIBRARY "Python library")

# python binding library
IF(ENABLE_INTERNAL_PYBIND11)
IF(ENABLE_INTERNAL_PYBIND11 AND NOT TARGET pybind11::pybind11)
CHECKOUT_GIT_SUBMODULE(
RECURSIVE
RELATIVE_PATH external/pybind11
Expand All @@ -57,7 +57,7 @@ IF(ENABLE_INTERNAL_PYBIND11)
REPO_BRANCH master)
ADD_SUBDIRECTORY(external/pybind11)
SET(pybind11_INCLUDE_DIR external/pybind11/include)
ELSE()
ELSEIF(NOT TARGET pybind11::pybind11)
FIND_PACKAGE(pybind11 REQUIRED)
ENDIF()

Expand Down

0 comments on commit c646c40

Please sign in to comment.