Skip to content

Commit c2d0363

Browse files
authored
update jps to warthog-core v0.5.0, added new module system (#17)
1 parent 377753d commit c2d0363

4 files changed

Lines changed: 82 additions & 38 deletions

File tree

CMakeLists.txt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,14 @@ project(WarthogJPS
44
VERSION 0.2.0
55
LANGUAGES CXX C)
66

7+
set_property(GLOBAL PROPERTY WARTHOG_warthog-jps ON)
8+
79
set(CMAKE_CXX_STANDARD 20)
810
set(CMAKE_CXX_STANDARD_REQUIRED TRUE)
911

10-
include(cmake/submodule.cmake)
12+
include(cmake/warthog.cmake)
13+
warthog_module_declare(warthog-core v0.5.0)
14+
warthog_module(warthog-core)
1115

1216
add_library(warthog_libjps)
1317
add_library(warthog::libjps ALIAS warthog_libjps)
@@ -26,4 +30,3 @@ target_link_libraries(warthog_jps PUBLIC warthog::libjps)
2630
add_subdirectory(src)
2731
add_subdirectory(apps)
2832

29-
warthog_submodule(warthog-core)

cmake/submodule.cmake

Lines changed: 0 additions & 35 deletions
This file was deleted.

cmake/warthog.cmake

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
cmake_minimum_required(VERSION 3.13)
2+
3+
# include this file to check submodule include
4+
5+
# set here as only
6+
set(warthog_https_warthog-core "https://github.com/ShortestPathLab/warthog-core.git" CACHE INTERNAL "")
7+
set(warthog_https_warthog-jps "https://github.com/ShortestPathLab/warthog-jps.git" CACHE INTERNAL "")
8+
9+
if(COMMAND warthog_module)
10+
return() # do not redefine
11+
endif()
12+
13+
include(FetchContent)
14+
15+
set(WARTHOG_MODULE_ROOT_ONLY ON CACHE BOOL "add submodule if present only allowed for root project")
16+
17+
function(warthog_top_level)
18+
set(_is_top OFF)
19+
if(${CMAKE_VERSION} VERSION_GREATER_EQUAL 3.21)
20+
if(${PROJECT_IS_TOP_LEVEL})
21+
set(_is_top ON)
22+
endif()
23+
else()
24+
if(${CMAKE_SOURCE_DIR} STREQUAL ${PROJECT_SOURCE_DIR})
25+
set(_is_top ON)
26+
endif()
27+
endif()
28+
set(_warthog_is_top ${_is_top} PARENT_SCOPE)
29+
endfunction()
30+
31+
# warthog_module module [override_top]
32+
# adds a module to warthog
33+
# has checks to insure module is only added once
34+
# if called from the top level project (or optional variable override_top is true)
35+
# then if extern/${module}/CMakeLists.txt exists, adds that version instead
36+
# intended for use with git module/subtree.
37+
# otherwise, fetchcontent ${module} is made available
38+
# user must add FetchContent_Declare
39+
function(warthog_module module)
40+
get_property(_module_added GLOBAL PROPERTY WARTHOG_${module} SET)
41+
if(${_module_added}) # module already added
42+
return()
43+
endif()
44+
if((${ARGC} GREATER 1) AND (${ARGV1}))
45+
set(is_top_level ON)
46+
else()
47+
warthog_top_level()
48+
set(is_top_level ${_warthog_is_top})
49+
endif()
50+
if(${is_top_level})
51+
if(EXISTS "${PROJECT_SOURCE_DIR}/extern/${module}/CMakeLists.txt")
52+
# module or subtree, include and exit
53+
add_subdirectory("${PROJECT_SOURCE_DIR}/extern/${module}")
54+
set_property(GLOBAL PROPERTY WARTHOG_${module} ON)
55+
return()
56+
endif()
57+
endif()
58+
# failed to add module, fetch if able
59+
warthog_module_declare(${module})
60+
FetchContent_MakeAvailable(${module})
61+
set_property(GLOBAL PROPERTY WARTHOG_${module} ON)
62+
endfunction()
63+
64+
function(warthog_module_declare module)
65+
if(NOT DEFINED warthog_https_${module})
66+
return()
67+
endif()
68+
if((${ARGC} GREATER 1))
69+
set(git_tag ${ARGV1})
70+
else()
71+
set(git_tag "main")
72+
endif()
73+
FetchContent_Declare(${module}
74+
GIT_REPOSITORY ${warthog_https_${module}}
75+
GIT_TAG ${git_tag})
76+
endfunction()

0 commit comments

Comments
 (0)