Skip to content

First Bindigns: Module, IntVect, Box #2

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

Merged
merged 1 commit into from
Feb 12, 2021
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
180 changes: 180 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,180 @@
# Preamble ####################################################################
#
cmake_minimum_required(VERSION 3.18.0)
project(pyAMReX VERSION 21.02)

include(${pyAMReX_SOURCE_DIR}/cmake/pyAMReXFunctions.cmake)

# In-source tree builds are messy and can screw up the build system.
# Avoid building at least in the same dir as the root dir:
if(CMAKE_BINARY_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
message(FATAL_ERROR "Building in-source is not supported! "
"Create a build directory and remove "
"${CMAKE_SOURCE_DIR}/CMakeCache.txt ${CMAKE_SOURCE_DIR}/CMakeFiles/")
endif()


# CMake policies ##############################################################
#
# TBD
#if(POLICY CMPXXXX)
# cmake_policy(SET CMPXXXX NEW)
#endif()


# CCache Support ##############################################################
#
# this is an optional tool that stores compiled object files; allows fast
# re-builds even with "make clean" in between. Mainly used to store AMReX
# objects
set_ccache()


# Output Directories ##########################################################
#
# temporary build directories
set_default_build_dirs()

# install directories
set_default_install_dirs()


# Options and Variants ########################################################
#
# change the default build type to RelWithDebInfo (or Release) instead of Debug
set_default_build_type("RelWithDebInfo")

# this defined the variable BUILD_TESTING which is ON by default
#include(CTest)


# Dependencies ################################################################
#

# AMReX
# builds AMReX from source (default) or finds an existing install
include(${pyAMReX_SOURCE_DIR}/cmake/dependencies/AMReX.cmake)

# Python
find_package(Python COMPONENTS Interpreter Development.Module REQUIRED)

# pybind11
# builds pybind11 from git (default), form local source or
# finds an existing install
include(${pyAMReX_SOURCE_DIR}/cmake/dependencies/pybind11.cmake)


# Targets #####################################################################
#
# collect all objects for compilation
add_library(pyAMReX MODULE src/pyAMReX.cpp)
add_library(pyAMReX::pyAMReX ALIAS pyAMReX)

# own headers
target_include_directories(pyAMReX PUBLIC
$<BUILD_INTERFACE:${pyAMReX_SOURCE_DIR}/src>
)

# if we include <AMReX_buildInfo.H> we will need to call:
include(AMReXBuildInfo)
generate_buildinfo(pyAMReX "${pyAMReX_SOURCE_DIR}")
target_link_libraries(pyAMReX PRIVATE buildInfo::pyAMReX)

# add sources
add_subdirectory(src)

# C++ properties: at least a C++14 capable compiler is needed
target_compile_features(pyAMReX PUBLIC cxx_std_14)
set_target_properties(pyAMReX PROPERTIES
CXX_EXTENSIONS OFF
CXX_STANDARD_REQUIRED ON
)

# link dependencies
target_link_libraries(pyAMReX PUBLIC AMReX::amrex)
target_link_libraries(pyAMReX PRIVATE pybind11::module pybind11::lto pybind11::windows_extras)

# binary name: we will encoded 1D, 2D and 3D in here so we can provide a
# wrapper library that pre-compiled all three geometry variants of AMReX
#set_pyAMReX_binary_name()

# set Python module properties
pybind11_extension(pyAMReX)
pybind11_strip(pyAMReX)
set_target_properties(pyAMReX PROPERTIES CXX_VISIBILITY_PRESET "hidden"
CUDA_VISIBILITY_PRESET "hidden")

# AMReX helper function: propagate CUDA specific target & source properties
if(AMReX_GPU_BACKEND STREQUAL CUDA)
setup_target_for_cuda_compilation(pyAMReX)
target_compile_features(pyAMReX PUBLIC cuda_std_14)
set_target_properties(pyAMReX PROPERTIES
CUDA_EXTENSIONS OFF
CUDA_STANDARD_REQUIRED ON
)
endif()


# Defines #####################################################################
#
# TBD


# Warnings ####################################################################
#
set_cxx_warnings()


# Generate Configuration and .pc Files ########################################
#
# these files are used if pyAMReX is installed and picked up by a downstream
# project (not needed yet)

#include(CMakePackageConfigHelpers)
#write_basic_package_version_file("pyAMReXConfigVersion.cmake"
# VERSION ${pyAMReX_VERSION}
# COMPATIBILITY SameMajorVersion
#)


# Installs ####################################################################
#
# headers, libraries and executables
set(pyAMReX_INSTALL_TARGET_NAMES pyAMReX)

install(TARGETS ${pyAMReX_INSTALL_TARGET_NAMES}
EXPORT pyAMReXTargets
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
)

# CMake package file for find_package(pyAMReX::pyAMReX) in depending projects
#install(EXPORT pyAMReXTargets
# FILE pyAMReXTargets.cmake
# NAMESPACE pyAMReX::
# DESTINATION ${CMAKE_INSTALL_CMAKEDIR}
#)
#install(
# FILES
# ${pyAMReX_BINARY_DIR}/pyAMReXConfig.cmake
# ${pyAMReX_BINARY_DIR}/pyAMReXConfigVersion.cmake
# DESTINATION ${CMAKE_INSTALL_CMAKEDIR}
#)


# Tests #######################################################################
#
# TBD

#if(BUILD_TESTING)
# enable_testing()
#
# add_test(...)
#endif()


# Status Summary for Build Options ############################################
#
pyAMReX_print_summary()
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ We will add further information here once first development versions are ready f
pyAMReX depends on the following popular third party software.

- a mature [C++14](https://en.wikipedia.org/wiki/C%2B%2B14) compiler: e.g. g++ 5.0+, clang 5.0+, VS 2017+
- [CMake 3.15.0+](https://cmake.org/)
- [CMake 3.18.0+](https://cmake.org)
- [AMReX *development*](https://amrex-codes.github.io): we automatically download and compile a copy of AMReX
- [pybind11](https://github.com/pybind/pybind11/) 2.6.2+: we automatically download and compile a copy of pybind11 ([new BSD](https://github.com/pybind/pybind11/blob/master/LICENSE))
- [Python](https://python.org) 3.6+
Expand Down Expand Up @@ -46,7 +46,7 @@ brew update
brew install ccache cmake fftw libomp mpi4py numpy open-mpi python
```

Now, `cmake --version` should be at version 3.15.0 or newer.
Now, `cmake --version` should be at version 3.18.0 or newer.

Or go:
```bash
Expand Down
88 changes: 88 additions & 0 deletions cmake/dependencies/AMReX.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
macro(find_amrex)
if(pyAMReX_amrex_src)
message(STATUS "Compiling local AMReX ...")
message(STATUS "AMReX source path: ${pyAMReX_amrex_src}")
elseif(pyAMReX_amrex_internal)
message(STATUS "Downloading AMReX ...")
message(STATUS "AMReX repository: ${pyAMReX_amrex_repo} (${pyAMReX_amrex_branch})")
include(FetchContent)
endif()
if(pyAMReX_amrex_internal OR pyAMReX_amrex_src)
set(CMAKE_POLICY_DEFAULT_CMP0077 NEW)

# see https://amrex-codes.github.io/amrex/docs_html/BuildingAMReX.html#customization-options
if("${CMAKE_BUILD_TYPE}" MATCHES "Debug")
set(AMReX_ASSERTIONS ON CACHE BOOL "")
# note: floating-point exceptions can slow down debug runs a lot
set(AMReX_FPE ON CACHE BOOL "")
else()
set(AMReX_ASSERTIONS OFF CACHE BOOL "")
set(AMReX_FPE OFF CACHE BOOL "")
endif()

set(AMReX_PIC ON CACHE INTERNAL "")
set(AMReX_ENABLE_TESTS OFF CACHE INTERNAL "")
set(AMReX_FORTRAN OFF CACHE INTERNAL "")
set(AMReX_FORTRAN_INTERFACES OFF CACHE INTERNAL "")
set(AMReX_BUILD_TUTORIALS OFF CACHE INTERNAL "")
# potentially worth changing default:
#set(AMReX_PARTICLES ON CACHE INTERNAL "")

if(pyAMReX_amrex_src)
list(APPEND CMAKE_MODULE_PATH "${pyAMReX_amrex_src}/Tools/CMake")
if(pyAMReX_COMPUTE STREQUAL CUDA)
enable_language(CUDA)
include(AMReX_SetupCUDA)
endif()
add_subdirectory(${pyAMReX_amrex_src} _deps/localamrex-build/)
else()
FetchContent_Declare(fetchedamrex
GIT_REPOSITORY ${pyAMReX_amrex_repo}
GIT_TAG ${pyAMReX_amrex_branch}
BUILD_IN_SOURCE 0
)
FetchContent_GetProperties(fetchedamrex)

if(NOT fetchedamrex_POPULATED)
FetchContent_Populate(fetchedamrex)
list(APPEND CMAKE_MODULE_PATH "${fetchedamrex_SOURCE_DIR}/Tools/CMake")
if(pyAMReX_COMPUTE STREQUAL CUDA)
enable_language(CUDA)
include(AMReX_SetupCUDA)
endif()
add_subdirectory(${fetchedamrex_SOURCE_DIR} ${fetchedamrex_BINARY_DIR})
endif()

# advanced fetch options
mark_as_advanced(FETCHCONTENT_BASE_DIR)
mark_as_advanced(FETCHCONTENT_FULLY_DISCONNECTED)
mark_as_advanced(FETCHCONTENT_QUIET)
mark_as_advanced(FETCHCONTENT_SOURCE_DIR_FETCHEDAMREX)
mark_as_advanced(FETCHCONTENT_UPDATES_DISCONNECTED)
mark_as_advanced(FETCHCONTENT_UPDATES_DISCONNECTED_FETCHEDAMREX)
endif()

message(STATUS "AMReX: Using version '${AMREX_PKG_VERSION}' (${AMREX_GIT_VERSION})")
else()
message(STATUS "Searching for pre-installed AMReX ...")
# https://amrex-codes.github.io/amrex/docs_html/BuildingAMReX.html#importing-amrex-into-your-cmake-project
find_package(AMReX 21.02 CONFIG REQUIRED COMPONENTS PIC)
message(STATUS "AMReX: Found version '${AMReX_VERSION}'")
endif()
endmacro()

# local source-tree
set(pyAMReX_amrex_src ""
CACHE PATH
"Local path to AMReX source directory (preferred if set)")

# Git fetcher
option(pyAMReX_amrex_internal "Download & build AMReX" ON)
set(pyAMReX_amrex_repo "https://github.com/AMReX-Codes/amrex.git"
CACHE STRING
"Repository URI to pull and build AMReX from if(pyAMReX_amrex_internal)")
set(pyAMReX_amrex_branch "development"
CACHE STRING
"Repository branch for pyAMReX_amrex_repo if(pyAMReX_amrex_internal)")

find_amrex()
56 changes: 56 additions & 0 deletions cmake/dependencies/pybind11.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
function(find_pybind11)
if(pyAMReX_pybind11_src)
message(STATUS "Compiling local pybind11 ...")
message(STATUS "pybind11 source path: ${pyAMReX_pybind11_src}")
elseif(pyAMReX_pybind11_internal)
message(STATUS "Downloading pybind11 ...")
message(STATUS "pybind11 repository: ${pyAMReX_pybind11_repo} (${pyAMReX_pybind11_branch})")
include(FetchContent)
endif()
if(pyAMReX_pybind11_internal OR pyAMReX_pybind11_src)
set(CMAKE_POLICY_DEFAULT_CMP0077 NEW)

if(pyAMReX_pybind11_src)
add_subdirectory(${pyAMReX_pybind11_src} _deps/localpybind11-build/)
else()
FetchContent_Declare(fetchedpybind11
GIT_REPOSITORY ${pyAMReX_pybind11_repo}
GIT_TAG ${pyAMReX_pybind11_branch}
BUILD_IN_SOURCE 0
)
FetchContent_GetProperties(fetchedpybind11)

if(NOT fetchedpybind11_POPULATED)
FetchContent_Populate(fetchedpybind11)
add_subdirectory(${fetchedpybind11_SOURCE_DIR} ${fetchedpybind11_BINARY_DIR})
endif()

# advanced fetch options
mark_as_advanced(FETCHCONTENT_BASE_DIR)
mark_as_advanced(FETCHCONTENT_FULLY_DISCONNECTED)
mark_as_advanced(FETCHCONTENT_QUIET)
mark_as_advanced(FETCHCONTENT_SOURCE_DIR_FETCHEDpybind11)
mark_as_advanced(FETCHCONTENT_UPDATES_DISCONNECTED)
mark_as_advanced(FETCHCONTENT_UPDATES_DISCONNECTED_FETCHEDpybind11)
endif()
else()
find_package(pybind11 2.6.2 CONFIG REQUIRED)
message(STATUS "pybind11: Found version '${pybind11_VERSION}'")
endif()
endfunction()

# local source-tree
set(pyAMReX_pybind11_src ""
CACHE PATH
"Local path to pybind11 source directory (preferred if set)")

# Git fetcher
option(pyAMReX_pybind11_internal "Download & build pybind11" ON)
set(pyAMReX_pybind11_repo "https://github.com/pybind/pybind11.git"
CACHE STRING
"Repository URI to pull and build pybind11 from if(pyAMReX_pybind11_internal)")
set(pyAMReX_pybind11_branch "v2.6.2"
CACHE STRING
"Repository branch for pyAMReX_pybind11_repo if(pyAMReX_pybind11_internal)")

find_pybind11()
Loading