Skip to content

Commit

Permalink
Add cache entries for external library (#169)
Browse files Browse the repository at this point in the history
- Fetched external libraries are now cached in .cache
- Cache entry todo for pybind11
  • Loading branch information
chengcli authored Jul 20, 2024
1 parent 17c25fd commit 7024e25
Show file tree
Hide file tree
Showing 13 changed files with 104 additions and 101 deletions.
Empty file added .cache/.dummy
Empty file.
13 changes: 4 additions & 9 deletions cmake/application.cmake
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
include(FetchContent)

set(FETCHCONTENT_QUIET FALSE)

FetchContent_Declare(
application
DOWNLOAD_EXTRACT_TIMESTAMP TRUE
URL https://github.com/chengcli/application/archive/refs/tags/v0.7.tar.gz)

FetchContent_MakeAvailable(application)

include_directories(${application_SOURCE_DIR})
set(PACKAGE_NAME application)
set(REPO_URL "https://github.com/chengcli/application")
set(REPO_TAG "v0.7")
add_package(${PACKAGE_NAME} ${REPO_URL} ${REPO_TAG} "" ON)
20 changes: 10 additions & 10 deletions cmake/athena.cmake
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
include(FetchContent)

set(FETCHCONTENT_QUIET FALSE)

set(patch_command
Expand All @@ -18,15 +17,16 @@ set(patch_command
${CMAKE_CURRENT_SOURCE_DIR}/patches/33.bvals_cc_cpp.patch
${CMAKE_CURRENT_SOURCE_DIR}/patches/34.bvals_cc_hpp.patch)

FetchContent_Declare(
athenapp
GIT_REPOSITORY https://github.com/chengcli/athenapp/
GIT_TAG snap-mods
PATCH_COMMAND ${patch_command}
UPDATE_DISCONNECTED TRUE)
# DOWNLOAD_EXTRACT_TIMESTAMP TRUE URL
set(PACKAGE_NAME athenapp)
set(REPO_URL "https://github.com/chengcli/athenapp")
set(REPO_TAG "12b11a6004827ba4732c248c021be55b2906ab82")
add_package(${PACKAGE_NAME} ${REPO_URL} ${REPO_TAG} "${patch_command}" ON)

# FetchContent_Declare( athenapp GIT_REPOSITORY
# https://github.com/chengcli/athenapp/ GIT_TAG snap-mods PATCH_COMMAND
# ${patch_command} UPDATE_DISCONNECTED TRUE) DOWNLOAD_EXTRACT_TIMESTAMP TRUE URL
# https://github.com/chengcli/athenapp/archive/refs/tags/v0.8.tar.gz)

FetchContent_MakeAvailable(athenapp)
# FetchContent_MakeAvailable(athenapp)

include_directories(${athenapp_SOURCE_DIR})
# include_directories(${athenapp_SOURCE_DIR})
15 changes: 4 additions & 11 deletions cmake/disort.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,7 @@ set(FETCHCONTENT_QUIET FALSE)
set_if_empty(ACCOUNT $ENV{GH_ACCOUNT})
set_if_empty(TOKEN $ENV{GH_TOKEN})

option(DISORT "Build DISORT" OFF)

if(DISORT)
FetchContent_Declare(
pydisort
DOWNLOAD_EXTRACT_TIMESTAMP TRUE
URL https://${ACCOUNT}:${TOKEN}@github.com/zoeyzyhu/pydisort/archive/refs/tags/v0.8.0.tar.gz
)

FetchContent_MakeAvailable(pydisort)
endif()
set(PACKAGE_NAME disort)
set(REPO_URL "https://${ACCOUNT}:${TOKEN}@github.com/zoeyzyhu/pydisort")
set(REPO_TAG "v0.8.0")
add_package(${PACKAGE_NAME} ${REPO_URL} ${REPO_TAG} "" OFF)
2 changes: 1 addition & 1 deletion cmake/exofmsrt.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ set(FETCHCONTENT_QUIET FALSE)
set(PACKAGE_NAME exofmsrt)
set(REPO_URL "https://github.com/chengcli/Exo-FMS_column_ck")
set(REPO_TAG "36ba9fad0f87339c3c7b83dd9bf2b53eaba8223f")
add_package(${PACKAGE_NAME} ${REPO_URL} ${REPO_TAG} OFF)
add_package(${PACKAGE_NAME} ${REPO_URL} ${REPO_TAG} "" OFF)
12 changes: 5 additions & 7 deletions cmake/gtest.cmake
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
include(FetchContent)

set(FETCHCONTENT_QUIET TRUE)

FetchContent_Declare(
gtest
DOWNLOAD_EXTRACT_TIMESTAMP TRUE
URL https://github.com/google/googletest/archive/refs/tags/v1.13.0.tar.gz)

set(PACKAGE_NAME gtest)
set(REPO_URL "https://github.com/google/googletest")
set(REPO_TAG "v1.13.0")
set(INSTALL_GTEST OFF)
FetchContent_MakeAvailable(gtest)

add_package(${PACKAGE_NAME} ${REPO_URL} ${REPO_TAG} "" ON)
28 changes: 16 additions & 12 deletions cmake/macros/macro_add_package.cmake
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
macro(add_package name url tag option)
macro(add_package name url tag patch option)
string(ASCII 27 Esc)
set(ColorReset "${Esc}[m")
set(Yellow "${Esc}[33m")
Expand All @@ -9,30 +9,34 @@ macro(add_package name url tag option)
string(TOUPPER ${name} nameu)
option(${nameu} "Build ${name}" ${option})

if(${nameu})
if(${${nameu}})
if(EXISTS ${CACHE_FILE})
if(NOT EXISTS ${CMAKE_BINARY_DIR}/_deps/${name}-src)
message(
STATUS "${Yellow}Find cached file ${name}-${tag}.tar.gz${ColorReset}")
execute_process(COMMAND tar -xzf ${CACHE_FILE} -C ${CACHE_DIR})
execute_process(COMMAND mv ${CACHE_DIR}/${name}-src
${CMAKE_BINARY_DIR}/_deps/)
if(NOT EXISTS ${CMAKE_BINARY_DIR}/_deps)
file(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/_deps)
endif()

FetchContent_Declare(${name} SOURCE_DIR
${CMAKE_BINARY_DIR}/_deps/${name}-src)
message(
STATUS
"${Yellow}Using cached library ${name}-${tag}.tar.gz${ColorReset}")

FetchContent_Declare(${name} DOWNLOAD_COMMAND tar -xzf ${CACHE_FILE} -C
${CMAKE_BINARY_DIR}/_deps)
else()
FetchContent_Declare(
${name}
GIT_REPOSITORY ${url}
GIT_TAG ${tag})
GIT_TAG ${tag}
PATCH_COMMAND ${patch}
UPDATE_DISCONNECTED TRUE)
endif()

FetchContent_MakeAvailable(${name})
include_directories(${${name}_SOURCE_DIR})

if(NOT EXISTS ${CACHE_FILE})
message(STATUS "Creating ${CACHE_FILE}")
message(
STATUS
"${Yellow}Creating cached library ${name}-${tag}.tar.gz${ColorReset}")
execute_process(COMMAND tar -czf ${CACHE_DIR}/${name}-${tag}.tar.gz -C
${CMAKE_BINARY_DIR}/_deps ${name}-src)
endif()
Expand Down
45 changes: 45 additions & 0 deletions cmake/macros/macro_add_package_noinclude.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
macro(add_package_noinclude name url tag patch option)
string(ASCII 27 Esc)
set(ColorReset "${Esc}[m")
set(Yellow "${Esc}[33m")

set(CACHE_DIR "${CMAKE_SOURCE_DIR}/.cache")
set(CACHE_FILE "${CACHE_DIR}/${name}-${tag}.tar.gz")

string(TOUPPER ${name} nameu)
option(${nameu} "Build ${name}" ${option})

if(${${nameu}})
if(EXISTS ${CACHE_FILE})
if(NOT EXISTS ${CMAKE_BINARY_DIR}/_deps)
file(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/_deps)
endif()

message(
STATUS
"${Yellow}Using cached library ${name}-${tag}.tar.gz${ColorReset}")

FetchContent_Declare(${name} DOWNLOAD_COMMAND tar -xzf ${CACHE_FILE} -C
${CMAKE_BINARY_DIR}/_deps)
else()
FetchContent_Declare(
${name}
GIT_REPOSITORY ${url}
GIT_TAG ${tag}
PATCH_COMMAND ${patch}
UPDATE_DISCONNECTED TRUE)
endif()

FetchContent_MakeAvailable(${name})

if(NOT EXISTS ${CACHE_FILE})
message(
STATUS
"${Yellow}Creating cached library ${name}-${tag}.tar.gz${ColorReset}")
execute_process(COMMAND tar -czf ${CACHE_DIR}/${name}-${tag}.tar.gz -C
${CMAKE_BINARY_DIR}/_deps ${name}-src)
endif()
else()
message(STATUS "${Yellow}Not building ${name}${ColorReset}")
endif()
endmacro()
17 changes: 4 additions & 13 deletions cmake/minichem.cmake
Original file line number Diff line number Diff line change
@@ -1,16 +1,7 @@
include(FetchContent)

set(FETCHCONTENT_QUIET FALSE)

option(MINICHEM "Build minichem" OFF)

if(MINICHEM)
FetchContent_Declare(
minichem
GIT_REPOSITORY https://github.com/chengcli/mini_chem
GIT_TAG main)
FetchContent_MakeAvailable(minichem)

include_directories(${minichem_SOURCE_DIR})
endif()

set(PACKAGE_NAME minichem)
set(REPO_URL "https://github.com/chengcli/mini_chem")
set(REPO_TAG "3372a500f038f83228c9f8f944b3fb6b2dedc572")
add_package(${PACKAGE_NAME} ${REPO_URL} ${REPO_TAG} "" OFF)
10 changes: 7 additions & 3 deletions cmake/modules/FindNetCDF.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,14 @@ if(NETCDF_INCLUDES AND NETCDF_LIBRARIES)
set(NETCDF_FIND_QUIETLY TRUE)
endif(NETCDF_INCLUDES AND NETCDF_LIBRARIES)

find_path(NETCDF_INCLUDES netcdf.h HINTS /opt/homebrew/include NETCDF_DIR ENV
NETCDF_DIR)
find_path(NETCDF_INCLUDES netcdf.h
HINTS /opt/homebrew/include NETCDF_DIR $ENV{NETCDF_DIR}
$ENV{NETCDF}/include $ENV{NC_ROOT}/include)

find_library(NETCDF_LIBRARIES_C NAMES netcdf)
find_library(
NETCDF_LIBRARIES_C
NAMES netcdf
HINTS $ENV{NETCDF}/lib $ENV{NC_ROOT}/lib)
mark_as_advanced(NETCDF_LIBRARIES_C)

set(NetCDF_has_interfaces "YES") # will be set to NO if we're missing any
Expand Down
1 change: 0 additions & 1 deletion cmake/pybind11.cmake
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
include(FetchContent)

set(FETCHCONTENT_QUIET FALSE)

option(PYTHON_BINDINGS "Build Python Bindings" OFF)
Expand Down
22 changes: 4 additions & 18 deletions cmake/rfm.cmake
Original file line number Diff line number Diff line change
@@ -1,24 +1,10 @@
include(FetchContent)

set(FETCHCONTENT_QUIET FALSE)

macro(set_if_empty _variable)
if("${${_variable}}" STREQUAL "")
set(${_variable} ${ARGN})
endif()
endmacro()

set_if_empty(ACCOUNT $ENV{GH_ACCOUNT})
set_if_empty(TOKEN $ENV{GH_TOKEN})

option(RFM "Build RFM" OFF)

if(RFM)
FetchContent_Declare(
rfm
DOWNLOAD_EXTRACT_TIMESTAMP TRUE
URL https://${ACCOUNT}:${TOKEN}@github.com/luminoctum/rfm/archive/refs/tags/v5.20.2.tar.gz
)

FetchContent_MakeAvailable(rfm)
endif()
set(PACKAGE_NAME rfm)
set(REPO_URL "https://${ACCOUNT}:${TOKEN}@github.com/luminoctum/rfm")
set(REPO_TAG "v5.20.2")
add_package_noinclude(${PACKAGE_NAME} ${REPO_URL} ${REPO_TAG} "" OFF)
20 changes: 4 additions & 16 deletions cmake/yamlpp.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,10 @@ if(CANTERA_FOUND)
return()
endif()

FetchContent_Declare(
yaml-cpp
DOWNLOAD_EXTRACT_TIMESTAMP TRUE
URL https://github.com/jbeder/yaml-cpp/archive/refs/tags/0.8.0.tar.gz)
set(PACKAGE_NAME yaml-cpp)
set(REPO_URL "https://github.com/jbeder/yaml-cpp")
set(REPO_TAG "0.8.0")
add_package(${PACKAGE_NAME} ${REPO_URL} ${REPO_TAG} "" ON)

FetchContent_GetProperties(yaml-cpp)

if(NOT yaml-cpp_POPULATED)
message(STATUS "Fetching yaml-cpp...")
FetchContent_Populate(yaml-cpp)
add_subdirectory(${yaml-cpp_SOURCE_DIR} ${yaml-cpp_BINARY_DIR})
endif()

# FetchContent_MakeAvailable(yamlcpp)

# Where yaml-cpp's .h files can be found.
include_directories(${yaml-cpp_SOURCE_DIR}/include)

set(YAML_CPP_LIBRARIES yaml-cpp)

0 comments on commit 7024e25

Please sign in to comment.