Skip to content

Commit

Permalink
Updated how to fetch dependencies.
Browse files Browse the repository at this point in the history
  • Loading branch information
5cript committed Jul 7, 2024
1 parent bb5f13f commit a44bbd9
Show file tree
Hide file tree
Showing 9 changed files with 82 additions and 36 deletions.
22 changes: 11 additions & 11 deletions cmake/dependencies/fmt.cmake
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
option(NUI_FETCH_FMT "Fetch fmt" ON)
option(NUI_FIND_FMT "Find fmt first before fetch content" ON)
option(NUI_FETCH_FMT "Try FetchContent for fmt" ON)
set(NUI_FMT_GIT_REPOSITORY "https://github.com/fmtlib/fmt.git" CACHE STRING "fmt git repository")
set(NUI_FMT_GIT_TAG "4e8640ed90ac8751d4a8ca500b893cc8c4bb9668" CACHE STRING "fmt git tag")
set(NUI_FMT_GIT_TAG "7a8b54a0ef7ca1791b0a5491b6e0593e1cf2dd5e" CACHE STRING "fmt git tag")

if (NUI_FETCH_FMT)
include(FetchContent)
FetchContent_Declare(
fmt
GIT_REPOSITORY ${NUI_FMT_GIT_REPOSITORY}
GIT_TAG ${NUI_FMT_GIT_TAG}
)
include("${CMAKE_CURRENT_LIST_DIR}/../fetcher.cmake")

FetchContent_MakeAvailable(fmt)
endif()
nui_fetch_dependency(
LIBRARY_NAME fmt
FIND ${NUI_FIND_FMT}
FETCH ${NUI_FETCH_FMT}
GIT_REPOSITORY ${NUI_FMT_GIT_REPOSITORY}
GIT_TAG ${NUI_FMT_GIT_TAG}
)
18 changes: 9 additions & 9 deletions cmake/dependencies/gtest.cmake
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
option(NUI_FIND_GTEST "Find gtest" ON)
option(NUI_FETCH_GTEST "Fetch gtest" ON)
set(NUI_GTEST_GIT_REPOSITORY "https://github.com/google/googletest.git" CACHE STRING "gtest git repository")
set(NUI_GTEST_GIT_TAG "beb552fb47e9e8a6ddab20526663c2dddd601ec6" CACHE STRING "gtest git tag")

if(NUI_FETCH_GTEST)
include(FetchContent)
FetchContent_Declare(
gtest
GIT_REPOSITORY ${NUI_GTEST_GIT_REPOSITORY}
GIT_TAG ${NUI_GTEST_GIT_TAG}
)
include("${CMAKE_CURRENT_LIST_DIR}/../fetcher.cmake")

FetchContent_MakeAvailable(gtest)
endif()
nui_fetch_dependency(
LIBRARY_NAME GTest
FIND ${NUI_FIND_GTEST}
FETCH ${NUI_FETCH_GTEST}
GIT_REPOSITORY ${NUI_GTEST_GIT_REPOSITORY}
GIT_TAG ${NUI_GTEST_GIT_TAG}
)
20 changes: 10 additions & 10 deletions cmake/dependencies/nlohmann_json.cmake
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
option(NUI_FETCH_NLOHMANN_JSON "Fetch nlohmann_json" ON)
option(NUI_FIND_NLOHMANN_JSON "Try find_package to find nlohmann_json" ON)
option(NUI_FETCH_NLOHMANN_JSON "Try fetch nlohmann json" ON)
set(NUI_NLOHMANN_JSON_GIT_REPOSITORY "https://github.com/nlohmann/json.git" CACHE STRING "nlohmann_json git repository")
set(NUI_NLOHMANN_JSON_GIT_TAG "8c391e04fe4195d8be862c97f38cfe10e2a3472e" CACHE STRING "nlohmann_json git tag")

if(NUI_FETCH_NLOHMANN_JSON)
include(FetchContent)
FetchContent_Declare(
nlohmann_json
GIT_REPOSITORY ${NUI_NLOHMANN_JSON_GIT_REPOSITORY}
GIT_TAG ${NUI_NLOHMANN_JSON_GIT_TAG}
)
include("${CMAKE_CURRENT_LIST_DIR}/../fetcher.cmake")

FetchContent_MakeAvailable(nlohmann_json)
endif()
nui_fetch_dependency(
LIBRARY_NAME nlohmann_json
FIND ${NUI_FIND_NLOHMANN_JSON}
FETCH ${NUI_FETCH_NLOHMANN_JSON}
GIT_REPOSITORY ${NUI_NLOHMANN_JSON_GIT_REPOSITORY}
GIT_TAG ${NUI_NLOHMANN_JSON_GIT_TAG}
)
2 changes: 1 addition & 1 deletion cmake/dependencies/roar.cmake
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
option(NUI_FETCH_ROAR "Fetch roar" ON)
set(NUI_ROAR_REPOSITORY "https://github.com/5cript/roar.git" CACHE STRING "roar repository")
set(NUI_ROAR_TAG "45230b49703e8bb29cecb07c65927eb905b7c7fe" CACHE STRING "roar tag")
set(NUI_ROAR_TAG "f2f03784a77e03f83b6de3120a3c54cbc427b46e" CACHE STRING "roar tag")

if(NUI_FETCH_ROAR)
include(FetchContent)
Expand Down
42 changes: 42 additions & 0 deletions cmake/fetcher.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
include(FetchContent)

function(nui_fetch_dependency)
cmake_parse_arguments(
NUI_FETCH_ARGS
"FIND;FETCH"
"LIBRARY_NAME;PACKAGE_NAME;FETCH_NAME;GIT_REPOSITORY;GIT_TAG"
""
${ARGN}
)

if (NOT NUI_FETCH_ARGS_PACKAGE_NAME)
if (NOT NUI_FETCH_ARGS_LIBRARY_NAME)
message(FATAL_ERROR "NUI_FETCH_ARGS_PACKAGE_NAME is not set")
endif()
set(NUI_FETCH_ARGS_PACKAGE_NAME ${NUI_FETCH_ARGS_LIBRARY_NAME})
endif()
if (NOT NUI_FETCH_ARGS_FETCH_NAME)
if (NOT NUI_FETCH_ARGS_LIBRARY_NAME)
message(FATAL_ERROR "NUI_FETCH_ARGS_FETCH_NAME is not set")
endif()
set(NUI_FETCH_ARGS_FETCH_NAME ${NUI_FETCH_ARGS_LIBRARY_NAME})
endif()

if (NUI_FETCH_ARGS_FIND)
find_package(${NUI_FETCH_ARGS_PACKAGE_NAME} QUIET)

if (${NUI_FETCH_ARGS_PACKAGE_NAME}_FOUND)
return()
endif()
endif()

if (NUI_FETCH_ARGS_FETCH AND ${NUI_FETCH_ARGS_FETCH})
message(STATUS "Fetching ${NUI_FETCH_ARGS_FETCH_NAME}")
FetchContent_Declare(
${NUI_FETCH_ARGS_FETCH_NAME}
GIT_REPOSITORY ${NUI_FETCH_ARGS_GIT_REPOSITORY}
GIT_TAG ${NUI_FETCH_ARGS_GIT_TAG}
)
FetchContent_MakeAvailable(${NUI_FETCH_ARGS_FETCH_NAME})
endif()
endfunction()
4 changes: 2 additions & 2 deletions cmake/frontend/emscripten.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ function(nui_prepare_emscripten_target)
NUI_PREPARE_EMSCRIPTEN_TARGET_ARGS
"NO_INLINE;NO_INLINE_INJECT"
"TARGET;PREJS;STATIC;UNPACKED_MODE"
"EMSCRIPTEN_LINK_OPTIONS;EMSCRIPTEN_COMPILE_OPTIONS;PARCEL_ARGS"
"EMSCRIPTEN_LINK_OPTIONS;EMSCRIPTEN_COMPILE_OPTIONS;PARCEL_ARGS;NPM_INSTALL_ARGS"
${ARGN}
)

Expand All @@ -28,7 +28,7 @@ function(nui_prepare_emscripten_target)

add_custom_target(
${NUI_PREPARE_EMSCRIPTEN_TARGET_ARGS_TARGET}-npm-install
COMMAND ${NUI_NPM} install
COMMAND ${NUI_NPM} install ${NUI_PREPARE_EMSCRIPTEN_TARGET_ARGS_NPM_INSTALL_ARGS}
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
)

Expand Down
2 changes: 1 addition & 1 deletion nui/src/nui/backend/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ target_link_libraries(
fmt
webview-iface
portable_file_dialogs
nlohmann_json
nlohmann_json::nlohmann_json
roar
Boost::boost
)
Expand Down
4 changes: 3 additions & 1 deletion tools/inline_parser/src/inline_parser/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@ cmake_minimum_required(VERSION 3.16)

project(inline-parser VERSION 0.1.0)

include("${CMAKE_CURRENT_LIST_DIR}/../../../../cmake/dependencies/nlohmann_json.cmake")

add_library(inline-parser-lib
STATIC
inline_extractor.cpp
section_cache.cpp
)
target_link_libraries(inline-parser-lib PUBLIC nlohmann_json roar)
target_link_libraries(inline-parser-lib PUBLIC nlohmann_json::nlohmann_json roar)
target_compile_features(inline-parser-lib PUBLIC cxx_std_20)
target_include_directories(inline-parser-lib PUBLIC ${CMAKE_CURRENT_LIST_DIR}/../../include)

Expand Down
4 changes: 3 additions & 1 deletion tools/parcel_adapter/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ cmake_minimum_required(VERSION 3.16)

project(parcel-adapter VERSION 0.1.0)

include("${CMAKE_CURRENT_LIST_DIR}/../../cmake/dependencies/nlohmann_json.cmake")

add_executable(parcel-adapter main.cpp)
target_link_libraries(parcel-adapter PRIVATE nlohmann_json)
target_link_libraries(parcel-adapter PRIVATE nlohmann_json::nlohmann_json)
target_compile_features(parcel-adapter PRIVATE cxx_std_20)

set_target_properties(parcel-adapter
Expand Down

0 comments on commit a44bbd9

Please sign in to comment.