From 456445dbc363f17871bb54b87c632421b7e336b7 Mon Sep 17 00:00:00 2001
From: Jonah Miller <jonahm@lanl.gov>
Date: Tue, 10 Sep 2024 12:40:50 -0600
Subject: [PATCH 1/4] add use_system_packages

---
 CMakeLists.txt | 18 ++++++++++++++++--
 1 file changed, 16 insertions(+), 2 deletions(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index c398d34eae29..abf6c16e4587 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -60,6 +60,17 @@ option(CODE_COVERAGE "Enable code coverage reporting" OFF)
 option(ENABLE_ASAN "Turn on ASAN" OFF)
 option(ENABLE_HWASAN "Turn on HWASAN (currently ARM-only)" OFF)
 
+option(PARTHENON_USE_SYSTEM_PACKAGES "Enables search for system packages when available" OFF)
+if (PARTHENON_USE_SYSTEM_PACKAGES)
+  option(PARTHENON_IMPORT_KOKKOS
+    "If ON, attempt to link to an external Kokkos library. If OFF, build Kokkos from source and package with Parthenon"
+    ON)
+else()
+  option(PARTHENON_IMPORT_KOKKOS
+    "If ON, attempt to link to an external Kokkos library. If OFF, build Kokkos from source and package with Parthenon"
+    OFF)
+endif()
+
 include(cmake/Format.cmake)
 include(cmake/Lint.cmake)
 
@@ -204,7 +215,6 @@ endif()
 set(CMAKE_CXX_STANDARD_REQUIRED ON)
 set(CMAKE_CXX_STANDARD 17)
 
-option(PARTHENON_IMPORT_KOKKOS "If ON, attempt to link to an external Kokkos library. If OFF, build Kokkos from source and package with Parthenon" OFF)
 if (NOT TARGET Kokkos::kokkos)
   if (PARTHENON_IMPORT_KOKKOS)
     find_package(Kokkos 4)
@@ -367,7 +377,11 @@ if (PARTHENON_ENABLE_UNIT_TESTS OR PARTHENON_ENABLE_INTEGRATION_TESTS OR PARTHEN
 endif()
 
 if (PARTHENON_ENABLE_ASCENT)
-  find_package(Ascent REQUIRED NO_DEFAULT_PATH)
+  if (PARTHENON_USE_SYSTEM_PACKAGES)
+    find_package(Ascent REQUIRED)
+  else()
+    find_package(Ascent REQUIRED NO_DEFAULT_PATH)
+  endif()
 endif()
 
 # Installation configuration

From ad1e8aec608403b58a9c7c3c5c6692418b3a16ea Mon Sep 17 00:00:00 2001
From: Jonah Miller <jonahm@lanl.gov>
Date: Tue, 10 Sep 2024 12:43:29 -0600
Subject: [PATCH 2/4] update docs

---
 doc/sphinx/src/building.rst | 1 +
 1 file changed, 1 insertion(+)

diff --git a/doc/sphinx/src/building.rst b/doc/sphinx/src/building.rst
index 29559f1b1101..b0ce186002b0 100644
--- a/doc/sphinx/src/building.rst
+++ b/doc/sphinx/src/building.rst
@@ -45,6 +45,7 @@ General list of cmake options:
 || PARTHENON\_COPYRIGHT\_CHECK\_DEFAULT     || OFF                           || Option || Check copyright as part of the default target (otherwise use the `check-copyright` target)                                                                  |
 || CMAKE\_INSTALL\_PREFIX                   || machine specific              || String || Optional path for library installation                                                                                                                      |
 || Kokkos\_ROOT                             || unset                         || String || Path to a Kokkos source directory (containing CMakeLists.txt)                                                                                               |
+|| PARTHENON\_USE\_SYSTEM\_PACKAGES         || OFF                           || Option || If ON, attempt to link to system dependencies for Kokkos and Ascent if possible. If off, will avoid doing so by default.                                    |
 || PARTHENON\_IMPORT\_KOKKOS                || ON/OFF                        || Option || If ON, attempt to link to an external Kokkos library. If OFF, build Kokkos from source and package with Parthenon                                           |
 || BUILD\_SHARED\_LIBS                      || OFF                           || Option || If installing Parthenon, whether to build as shared rather than static                                                                                      |
 +-------------------------------------------+--------------------------------+---------+--------------------------------------------------------------------------------------------------------------------------------------------------------------+

From 37cb89c14aa1c3017abf111807b2d1962b234dbe Mon Sep 17 00:00:00 2001
From: Jonah Miller <jonahm@lanl.gov>
Date: Tue, 10 Sep 2024 12:50:26 -0600
Subject: [PATCH 3/4] changelog and CC

---
 CHANGELOG.md   | 4 ++++
 CMakeLists.txt | 2 +-
 2 files changed, 5 insertions(+), 1 deletion(-)

diff --git a/CHANGELOG.md b/CHANGELOG.md
index 62b1ea9c5c78..edf4b18a8011 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -2,6 +2,10 @@
 
 ## Current develop
 
+### Added (new features/APIs/variables/...)
+- [[PR 1171]](https://github.com/parthenon-hpc-lab/parthenon/pull/1171) Add PARTHENON_USE_SYSTEM_PACKAGES build option
+
+
 ### Changed (changing behavior/API/variables/...)
 
 
diff --git a/CMakeLists.txt b/CMakeLists.txt
index abf6c16e4587..24a7a3b2ebfb 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -3,7 +3,7 @@
 # Copyright(C) 2020-2024 The Parthenon collaboration
 # Licensed under the 3-clause BSD License, see LICENSE file for details
 #=========================================================================================
-# (C) (or copyright) 2020-2023. Triad National Security, LLC. All rights reserved.
+# (C) (or copyright) 2020-2024. Triad National Security, LLC. All rights reserved.
 #
 # This program was produced under U.S. Government contract 89233218CNA000001 for Los
 # Alamos National Laboratory (LANL), which is operated by Triad National Security, LLC

From ec124755660466a303ec155d117fb329164bbe86 Mon Sep 17 00:00:00 2001
From: Jonah Miller <jonahm@lanl.gov>
Date: Tue, 10 Sep 2024 12:58:35 -0600
Subject: [PATCH 4/4] LFR suggestion

---
 doc/sphinx/src/building.rst | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/doc/sphinx/src/building.rst b/doc/sphinx/src/building.rst
index b0ce186002b0..b3a42bd4caec 100644
--- a/doc/sphinx/src/building.rst
+++ b/doc/sphinx/src/building.rst
@@ -45,8 +45,8 @@ General list of cmake options:
 || PARTHENON\_COPYRIGHT\_CHECK\_DEFAULT     || OFF                           || Option || Check copyright as part of the default target (otherwise use the `check-copyright` target)                                                                  |
 || CMAKE\_INSTALL\_PREFIX                   || machine specific              || String || Optional path for library installation                                                                                                                      |
 || Kokkos\_ROOT                             || unset                         || String || Path to a Kokkos source directory (containing CMakeLists.txt)                                                                                               |
-|| PARTHENON\_USE\_SYSTEM\_PACKAGES         || OFF                           || Option || If ON, attempt to link to system dependencies for Kokkos and Ascent if possible. If off, will avoid doing so by default.                                    |
-|| PARTHENON\_IMPORT\_KOKKOS                || ON/OFF                        || Option || If ON, attempt to link to an external Kokkos library. If OFF, build Kokkos from source and package with Parthenon                                           |
+|| PARTHENON\_USE\_SYSTEM\_PACKAGES         || OFF                           || Option || If ON, attempt to link to system dependencies for Kokkos and Ascent if possible. If OFF, will avoid doing so by default.                                    |
+|| PARTHENON\_IMPORT\_KOKKOS                || OFF/ON                        || Option || If ON, attempt to link to an external Kokkos library. Else build from source. Default is ON if PARTHENON\_USE\_SYSTEM\_PACKAGES and OFF otherwise.          |
 || BUILD\_SHARED\_LIBS                      || OFF                           || Option || If installing Parthenon, whether to build as shared rather than static                                                                                      |
 +-------------------------------------------+--------------------------------+---------+--------------------------------------------------------------------------------------------------------------------------------------------------------------+