Skip to content

Commit

Permalink
🎨 Replace git submodules with CMake FetchContent
Browse files Browse the repository at this point in the history
  • Loading branch information
heavywatal committed May 28, 2024
1 parent a722dfd commit 9478da1
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 21 deletions.
14 changes: 5 additions & 9 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
name: build

on:
push:
branches:
- master
branches: [main, master]
pull_request:
branches:
- master
branches: [main, master]

name: build

jobs:
build:
Expand All @@ -17,13 +15,11 @@ jobs:
os: [macOS-latest, ubuntu-latest]
steps:
- uses: actions/checkout@v4
with:
submodules: true
- name: cmake
run: cmake -S . -B build -DCMAKE_INSTALL_PREFIX=${HOME}/local
- name: build
run: |
cmake --build build -j2
cmake --build build -j 2
cmake --install build
- name: test
run: cd build; ctest -V -j 2
6 changes: 0 additions & 6 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,6 +0,0 @@
[submodule "clipp"]
path = clipp
url = https://github.com/heavywatal/clipp.git
[submodule "json"]
path = json
url = https://github.com/heavywatal/json.git
40 changes: 37 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,49 @@ project(clippson
VERSION 0.8.6
LANGUAGES CXX)

cmake_policy(SET CMP0076 NEW)
set(CMAKE_VERBOSE_MAKEFILE ON)
include(CMakePrintHelpers)
include(FetchContent)
include(GNUInstallDirs)
cmake_print_variables(CMAKE_INSTALL_PREFIX)

function(import_env variable)
if(DEFINED ENV{${variable}})
set(${variable} $ENV{${variable}} PARENT_SCOPE)
endif()
endfunction()

function(git_fetch package version repo)
string(TOUPPER "${package}" upackage)
import_env("FETCHCONTENT_SOURCE_DIR_${upackage}")
if(IS_DIRECTORY "${FETCHCONTENT_SOURCE_DIR_${upackage}}")
set(tag "HEAD")
else()
set(tag "${version}")
endif()
cmake_print_variables(FETCHCONTENT_SOURCE_DIR_${upackage} tag)
set(FETCHCONTENT_QUIET OFF)
FetchContent_Declare(
${package}
GIT_REPOSITORY https://github.com/${repo}.git
GIT_TAG ${tag}
GIT_SHALLOW ON
)
if(NOT ${package}_POPULATED)
FetchContent_Populate(${package})
endif()
set(${package}_SOURCE_DIR ${${package}_SOURCE_DIR} PARENT_SCOPE)
cmake_print_variables(${package}_SOURCE_DIR)
endfunction()

git_fetch(clipp v1.2.3.1 heavywatal/clipp)
git_fetch(json v3.11.3 heavywatal/json)

set(subrepo_files
clipp/include/clipp.h
json/src/json.hpp
json/src/json_fwd.hpp
${clipp_SOURCE_DIR}/include/clipp.h
${json_SOURCE_DIR}/src/json.hpp
${json_SOURCE_DIR}/src/json_fwd.hpp
)
foreach(file IN LISTS subrepo_files)
configure_file(${file} ${PROJECT_SOURCE_DIR}/include/${PROJECT_NAME}/ COPYONLY)
Expand Down
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ Alternatively, you can get the source code from GitHub manually:
```sh
git clone https://github.com/heavywatal/clippson.git
cd clippson/
git submodule update --init --recursive
DESTINATION=${HOME}/local
cmake -S . -B build -DCMAKE_INSTALL_PREFIX=$DESTINATION
cmake --build build -j2
Expand Down
1 change: 0 additions & 1 deletion clipp
Submodule clipp deleted from bc8045
1 change: 0 additions & 1 deletion json
Submodule json deleted from 3a65cd

0 comments on commit 9478da1

Please sign in to comment.