diff --git a/CMakeLists.txt b/CMakeLists.txt index 742690b..182523d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4,10 +4,14 @@ project(WarthogJPS VERSION 0.2.0 LANGUAGES CXX C) +set_property(GLOBAL PROPERTY WARTHOG_warthog-jps ON) + set(CMAKE_CXX_STANDARD 20) set(CMAKE_CXX_STANDARD_REQUIRED TRUE) -include(cmake/submodule.cmake) +include(cmake/warthog.cmake) +warthog_module_declare(warthog-core v0.5.0) +warthog_module(warthog-core) add_library(warthog_libjps) add_library(warthog::libjps ALIAS warthog_libjps) @@ -26,4 +30,3 @@ target_link_libraries(warthog_jps PUBLIC warthog::libjps) add_subdirectory(src) add_subdirectory(apps) -warthog_submodule(warthog-core) diff --git a/cmake/submodule.cmake b/cmake/submodule.cmake deleted file mode 100644 index da47f29..0000000 --- a/cmake/submodule.cmake +++ /dev/null @@ -1,35 +0,0 @@ -cmake_minimum_required(VERSION 3.13) - -# include this file to check submodule include - -set(WARTHOG_SUBMODULE_ROOT_ONLY ON CACHE BOOL "add submodule if present only allowed for root project") - -function(warthog_top_level) -set(_is_top OFF) -if(${CMAKE_VERSION} VERSION_GREATER_EQUAL 3.21) - if(${PROJECT_IS_TOP_LEVEL}) - set(_is_top ON) - endif() -else() - if(${CMAKE_SOURCE_DIR} STREQUAL ${PROJECT_SOURCE_DIR}) - set(_is_top ON) - endif() -endif() -set(_is_top ${_is_top} PARENT_SCOPE) -endfunction() - -function(warthog_submodule dirname) -set(_is_top OFF) -if(NOT ${WARTHOG_SUBMODULE_ROOT_ONLY}) - set(_is_top ON) -else() - warthog_top_level() -endif() -if(${_is_top}) - if(NOT EXISTS "${PROJECT_SOURCE_DIR}/extern/${dirname}/.git") - message(SEND_ERROR "Failed to find submodule ${dirname}") - else() - add_subdirectory("${PROJECT_SOURCE_DIR}/extern/${dirname}" EXCLUDE_FROM_ALL) - endif() -endif() -endfunction() diff --git a/cmake/warthog.cmake b/cmake/warthog.cmake new file mode 100644 index 0000000..635f050 --- /dev/null +++ b/cmake/warthog.cmake @@ -0,0 +1,76 @@ +cmake_minimum_required(VERSION 3.13) + +# include this file to check submodule include + +# set here as only +set(warthog_https_warthog-core "https://github.com/ShortestPathLab/warthog-core.git" CACHE INTERNAL "") +set(warthog_https_warthog-jps "https://github.com/ShortestPathLab/warthog-jps.git" CACHE INTERNAL "") + +if(COMMAND warthog_module) + return() # do not redefine +endif() + +include(FetchContent) + +set(WARTHOG_MODULE_ROOT_ONLY ON CACHE BOOL "add submodule if present only allowed for root project") + +function(warthog_top_level) +set(_is_top OFF) +if(${CMAKE_VERSION} VERSION_GREATER_EQUAL 3.21) + if(${PROJECT_IS_TOP_LEVEL}) + set(_is_top ON) + endif() +else() + if(${CMAKE_SOURCE_DIR} STREQUAL ${PROJECT_SOURCE_DIR}) + set(_is_top ON) + endif() +endif() +set(_warthog_is_top ${_is_top} PARENT_SCOPE) +endfunction() + +# warthog_module module [override_top] +# adds a module to warthog +# has checks to insure module is only added once +# if called from the top level project (or optional variable override_top is true) +# then if extern/${module}/CMakeLists.txt exists, adds that version instead +# intended for use with git module/subtree. +# otherwise, fetchcontent ${module} is made available +# user must add FetchContent_Declare +function(warthog_module module) +get_property(_module_added GLOBAL PROPERTY WARTHOG_${module} SET) +if(${_module_added}) # module already added + return() +endif() +if((${ARGC} GREATER 1) AND (${ARGV1})) + set(is_top_level ON) +else() + warthog_top_level() + set(is_top_level ${_warthog_is_top}) +endif() +if(${is_top_level}) + if(EXISTS "${PROJECT_SOURCE_DIR}/extern/${module}/CMakeLists.txt") + # module or subtree, include and exit + add_subdirectory("${PROJECT_SOURCE_DIR}/extern/${module}") + set_property(GLOBAL PROPERTY WARTHOG_${module} ON) + return() + endif() +endif() +# failed to add module, fetch if able +warthog_module_declare(${module}) +FetchContent_MakeAvailable(${module}) +set_property(GLOBAL PROPERTY WARTHOG_${module} ON) +endfunction() + +function(warthog_module_declare module) +if(NOT DEFINED warthog_https_${module}) + return() +endif() +if((${ARGC} GREATER 1)) + set(git_tag ${ARGV1}) +else() + set(git_tag "main") +endif() +FetchContent_Declare(${module} + GIT_REPOSITORY ${warthog_https_${module}} + GIT_TAG ${git_tag}) +endfunction() diff --git a/extern/warthog-core b/extern/warthog-core index deec8ce..f379ef2 160000 --- a/extern/warthog-core +++ b/extern/warthog-core @@ -1 +1 @@ -Subproject commit deec8ce4310b08196dc943a9fdbef9ccedfbafe2 +Subproject commit f379ef257335bb8bb6645c6efaeef031763273ea