Skip to content

Commit d068371

Browse files
committed
CMake: Tarball Support
This speeds up the configure step from 20.1sec to 6.5sec by just downloading a shallow copy of AMReX & pybind11.
1 parent 7d23493 commit d068371

File tree

5 files changed

+90
-38
lines changed

5 files changed

+90
-38
lines changed

CMakeLists.txt

+3
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,9 @@ option(pyAMReX_INSTALL
8080
"Enable install targets for pyAMReX"
8181
ON
8282
)
83+
option(pyAMReX_SUPERBUILD
84+
"Download & build extra dependencies"
85+
ON)
8386

8487
# change the default build type to Release (or RelWithDebInfo) instead of Debug
8588
set_default_build_type("Release")

README.md

+6-4
Original file line numberDiff line numberDiff line change
@@ -175,8 +175,9 @@ If you are using the pip-driven install, selected [AMReX CMake options](https://
175175
| `AMREX_SRC` | *None* | Absolute path to AMReX source directory (preferred if set) |
176176
| `AMREX_REPO` | `https://github.com/AMReX-Codes/amrex.git` | Repository URI to pull and build AMReX from |
177177
| `AMREX_BRANCH` | `development` | Repository branch for `AMREX_REPO` |
178-
| `AMREX_INTERNAL` | **ON**/OFF | Needs a pre-installed AMReX library if set to `OFF` |
179-
| `PYBIND11_INTERNAL` | **ON**/OFF | Needs a pre-installed pybind11 library if set to `OFF` |
178+
| `AMREX_INTERNAL` | `SUPERBUILD` | Needs a pre-installed AMReX library if set to `OFF` |
179+
| `PYBIND11_INTERNAL` | `SUPERBUILD` | Needs a pre-installed pybind11 library if set to `OFF` |
180+
| `SUPERBUILD` | **ON**/OFF | Download & build extra dependencies |
180181
| `CMAKE_BUILD_PARALLEL_LEVEL` | 2 | Number of parallel build threads |
181182
| `PYAMREX_LIBDIR` | *None* | If set, search for pre-built a pyAMReX library |
182183
| `PYAMREX_CCACHE` | **ON**/OFF | Search and use CCache to speed up rebuilds |
@@ -192,12 +193,13 @@ Furthermore, pyAMReX adds a few selected CMake build options:
192193
| `pyAMReX_CCACHE` | **ON**/OFF | Search and use CCache to speed up rebuilds |
193194
| `pyAMReX_IPO` | **ON**/OFF | Compile with interprocedural/link optimization (IPO/LTO) |
194195
| `pyAMReX_INSTALL` | **ON**/OFF | Enable install targets for pyAMReX |
196+
| `pyAMReX_SUPERBUILD` | **ON**/OFF | Download & build extra dependencies |
195197
| `pyAMReX_amrex_src` | *None* | Absolute path to AMReX source directory (preferred if set) |
196-
| `pyAMReX_amrex_internal` | **ON**/OFF | Needs a pre-installed AMReX library if set to `OFF` |
198+
| `pyAMReX_amrex_internal` | `pyAMReX_SUPERBUILD` | Needs a pre-installed AMReX library if set to `OFF` |
197199
| `pyAMReX_amrex_repo` | `https://github.com/AMReX-Codes/amrex.git` | Repository URI to pull and build AMReX from |
198200
| `pyAMReX_amrex_branch` | `development` | Repository branch for `pyAMReX_amrex_repo` |
199201
| `pyAMReX_pybind11_src` | *None* | Absolute path to pybind11 source directory (preferred if set) |
200-
| `pyAMReX_pybind11_internal` | **ON**/OFF | Needs a pre-installed pybind11 library if set to `OFF` |
202+
| `pyAMReX_pybind11_internal` | `pyAMReX_SUPERBUILD` | Needs a pre-installed pybind11 library if set to `OFF` |
201203
| `pyAMReX_pybind11_repo` | `https://github.com/pybind/pybind11.git` | Repository URI to pull and build pybind11 from |
202204
| `pyAMReX_pybind11_branch` | `v2.12.0` | Repository branch for `pyAMReX_pybind11_repo` |
203205
| `Python_EXECUTABLE` | (newest found) | Path to Python executable |

cmake/dependencies/AMReX.cmake

+39-16
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,25 @@
11
macro(find_amrex)
22
if(TARGET AMReX::amrex)
33
message(STATUS "AMReX::amrex target already imported")
4-
elseif(pyAMReX_amrex_src)
5-
message(STATUS "Compiling local AMReX ...")
6-
message(STATUS "AMReX source path: ${pyAMReX_amrex_src}")
7-
if(NOT IS_DIRECTORY ${pyAMReX_amrex_src})
8-
message(FATAL_ERROR "Specified directory pyAMReX_amrex_src='${pyAMReX_amrex_src}' does not exist!")
9-
endif()
104
elseif(pyAMReX_amrex_internal)
11-
message(STATUS "Downloading AMReX ...")
12-
message(STATUS "AMReX repository: ${pyAMReX_amrex_repo} (${pyAMReX_amrex_branch})")
13-
include(FetchContent)
5+
if(pyAMReX_amrex_src)
6+
message(STATUS "Compiling local AMReX ...")
7+
message(STATUS "AMReX source path: ${pyAMReX_amrex_src}")
8+
if(NOT IS_DIRECTORY ${pyAMReX_amrex_src})
9+
message(FATAL_ERROR "Specified directory pyAMReX_amrex_src='${pyAMReX_amrex_src}' does not exist!")
10+
endif()
11+
elseif(pyAMReX_amrex_tar)
12+
message(STATUS "Downloading AMReX ...")
13+
message(STATUS "AMReX source: ${pyAMReX_amrex_tar}")
14+
elseif(pyAMReX_amrex_branch)
15+
message(STATUS "Downloading AMReX ...")
16+
message(STATUS "AMReX repository: ${pyAMReX_amrex_repo} (${pyAMReX_amrex_branch})")
17+
include(FetchContent)
18+
endif()
1419
endif()
1520
if(TARGET AMReX::amrex)
1621
# nothing to do, target already exists in the superbuild
17-
elseif(pyAMReX_amrex_internal OR pyAMReX_amrex_src)
22+
elseif(pyAMReX_amrex_internal)
1823
set(CMAKE_POLICY_DEFAULT_CMP0077 NEW)
1924

2025
# see https://amrex-codes.github.io/amrex/docs_html/BuildingAMReX.html#customization-options
@@ -45,11 +50,20 @@ macro(find_amrex)
4550
if(AMReX_GPU_BACKEND STREQUAL CUDA)
4651
enable_language(CUDA)
4752
endif()
48-
FetchContent_Declare(fetchedamrex
49-
GIT_REPOSITORY ${pyAMReX_amrex_repo}
50-
GIT_TAG ${pyAMReX_amrex_branch}
51-
BUILD_IN_SOURCE 0
52-
)
53+
include(FetchContent)
54+
if(pyAMReX_amrex_tar)
55+
FetchContent_Declare(fetchedamrex
56+
URL ${pyAMReX_amrex_tar}
57+
URL_HASH ${pyAMReX_amrex_tar_hash}
58+
BUILD_IN_SOURCE OFF
59+
)
60+
else()
61+
FetchContent_Declare(fetchedamrex
62+
GIT_REPOSITORY ${pyAMReX_amrex_repo}
63+
GIT_TAG ${pyAMReX_amrex_branch}
64+
BUILD_IN_SOURCE 0
65+
)
66+
endif()
5367
FetchContent_MakeAvailable(fetchedamrex)
5468
list(APPEND CMAKE_MODULE_PATH "${fetchedamrex_SOURCE_DIR}/Tools/CMake")
5569

@@ -76,13 +90,22 @@ macro(find_amrex)
7690
endif()
7791
endmacro()
7892

93+
option(pyAMReX_amrex_internal "Download & build AMReX" ${pyAMReX_SUPERBUILD})
94+
7995
# local source-tree
8096
set(pyAMReX_amrex_src ""
8197
CACHE PATH
8298
"Local path to AMReX source directory (preferred if set)")
8399

100+
# tarball fetcher
101+
set(pyAMReX_amrex_tar "https://github.com/AMReX-Codes/amrex/archive/24.10.zip"
102+
CACHE STRING
103+
"Remote tarball link to pull and build AMReX from if(pyAMReX_amrex_internal)")
104+
set(pyAMReX_amrex_tar_hash "SHA256=245232a7218f4352892e00b42db9b510f2e66f9b4a33e89bb5fa8c956a18d55c"
105+
CACHE STRING
106+
"Hash checksum of the tarball of AMReX if(pyAMReX_amrex_internal)")
107+
84108
# Git fetcher
85-
option(pyAMReX_amrex_internal "Download & build AMReX" ON)
86109
set(pyAMReX_amrex_repo "https://github.com/AMReX-Codes/amrex.git"
87110
CACHE STRING
88111
"Repository URI to pull and build AMReX from if(pyAMReX_amrex_internal)")

cmake/dependencies/pybind11.cmake

+39-16
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,44 @@
11
function(find_pybind11)
22
if(TARGET pybind11::module)
33
message(STATUS "pybind11::module target already imported")
4-
elseif(pyAMReX_pybind11_src)
5-
message(STATUS "Compiling local pybind11 ...")
6-
message(STATUS "pybind11 source path: ${pyAMReX_pybind11_src}")
7-
if(NOT IS_DIRECTORY ${pyAMReX_pybind11_src})
8-
message(FATAL_ERROR "Specified directory pyAMReX_pybind11_src='${pyAMReX_pybind11_src}' does not exist!")
9-
endif()
104
elseif(pyAMReX_pybind11_internal)
11-
message(STATUS "Downloading pybind11 ...")
12-
message(STATUS "pybind11 repository: ${pyAMReX_pybind11_repo} (${pyAMReX_pybind11_branch})")
13-
include(FetchContent)
5+
if(pyAMReX_pybind11_src)
6+
message(STATUS "Compiling local pybind11 ...")
7+
message(STATUS "pybind11 source path: ${pyAMReX_pybind11_src}")
8+
if(NOT IS_DIRECTORY ${pyAMReX_pybind11_src})
9+
message(FATAL_ERROR "Specified directory pyAMReX_pybind11_src='${pyAMReX_pybind11_src}' does not exist!")
10+
endif()
11+
elseif(pyAMReX_pybind11_tar)
12+
message(STATUS "Downloading pybind11 ...")
13+
message(STATUS "pybind11 source: ${pyAMReX_pybind11_tar}")
14+
elseif(pyAMReX_pybind11_branch)
15+
message(STATUS "Downloading pybind11 ...")
16+
message(STATUS "pybind11 repository: ${pyAMReX_pybind11_repo} (${pyAMReX_pybind11_branch})")
17+
include(FetchContent)
18+
endif()
1419
endif()
1520
if(TARGET pybind11::module)
1621
# nothing to do, target already exists in the superbuild
17-
elseif(pyAMReX_pybind11_internal OR pyAMReX_pybind11_src)
22+
elseif(pyAMReX_pybind11_internal)
1823
set(CMAKE_POLICY_DEFAULT_CMP0077 NEW)
1924

2025
if(pyAMReX_pybind11_src)
2126
add_subdirectory(${pyAMReX_pybind11_src} _deps/localpybind11-build/)
2227
else()
23-
FetchContent_Declare(fetchedpybind11
24-
GIT_REPOSITORY ${pyAMReX_pybind11_repo}
25-
GIT_TAG ${pyAMReX_pybind11_branch}
26-
BUILD_IN_SOURCE 0
27-
)
28+
include(FetchContent)
29+
if(pyAMReX_pybind11_tar)
30+
FetchContent_Declare(fetchedpybind11
31+
URL ${pyAMReX_pybind11_tar}
32+
URL_HASH ${pyAMReX_pybind11_tar_hash}
33+
BUILD_IN_SOURCE OFF
34+
)
35+
else()
36+
FetchContent_Declare(fetchedpybind11
37+
GIT_REPOSITORY ${pyAMReX_pybind11_repo}
38+
GIT_TAG ${pyAMReX_pybind11_branch}
39+
BUILD_IN_SOURCE 0
40+
)
41+
endif()
2842
FetchContent_MakeAvailable(fetchedpybind11)
2943

3044
# advanced fetch options
@@ -41,13 +55,22 @@ function(find_pybind11)
4155
endif()
4256
endfunction()
4357

58+
option(pyAMReX_pybind11_internal "Download & build pybind11" ${pyAMReX_SUPERBUILD})
59+
4460
# local source-tree
4561
set(pyAMReX_pybind11_src ""
4662
CACHE PATH
4763
"Local path to pybind11 source directory (preferred if set)")
4864

65+
# tarball fetcher
66+
set(pyAMReX_pybind11_tar "https://github.com/pybind/pybind11/archive/refs/tags/v2.13.6.tar.gz"
67+
CACHE STRING
68+
"Remote tarball link to pull and build pybind11 from if(pyAMReX_pybind11_internal)")
69+
set(pyAMReX_pybind11_tar_hash "SHA256=e08cb87f4773da97fa7b5f035de8763abc656d87d5773e62f6da0587d1f0ec20"
70+
CACHE STRING
71+
"Hash checksum of the tarball of pybind11 if(pyAMReX_pybind11_internal)")
72+
4973
# Git fetcher
50-
option(pyAMReX_pybind11_internal "Download & build pybind11" ON)
5174
set(pyAMReX_pybind11_repo "https://github.com/pybind/pybind11.git"
5275
CACHE STRING
5376
"Repository URI to pull and build pybind11 from if(pyAMReX_pybind11_internal)")

setup.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -171,11 +171,12 @@ def build_extension(self, ext):
171171
AMReX_SPACEDIM = os.environ.get("AMREX_SPACEDIM", "1;2;3")
172172
BUILD_SHARED_LIBS = os.environ.get("AMREX_BUILD_SHARED_LIBS", "OFF")
173173
# CMake dependency control (developers & package managers)
174+
Superbuild = os.environ.get("SUPERBUILD", "ON")
174175
AMReX_src = os.environ.get("AMREX_SRC")
175-
AMReX_internal = os.environ.get("AMREX_INTERNAL", "ON")
176+
AMReX_internal = os.environ.get("AMREX_INTERNAL", Superbuild)
176177
AMReX_repo = os.environ.get("AMREX_REPO")
177178
AMReX_branch = os.environ.get("AMREX_BRANCH")
178-
pybind11_internal = os.environ.get("PYBIND11_INTERNAL", "ON")
179+
pybind11_internal = os.environ.get("PYBIND11_INTERNAL", Superbuild)
179180

180181
# https://cmake.org/cmake/help/v3.0/command/if.html
181182
if AMReX_MPI.upper() in ["1", "ON", "TRUE", "YES"]:

0 commit comments

Comments
 (0)