diff --git a/cmake/dependencies/fmt.cmake b/cmake/dependencies/fmt.cmake index 35e6afb6..35f02a9a 100644 --- a/cmake/dependencies/fmt.cmake +++ b/cmake/dependencies/fmt.cmake @@ -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() \ No newline at end of file +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} +) \ No newline at end of file diff --git a/cmake/dependencies/gtest.cmake b/cmake/dependencies/gtest.cmake index 890439f6..60e4815c 100644 --- a/cmake/dependencies/gtest.cmake +++ b/cmake/dependencies/gtest.cmake @@ -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() \ No newline at end of file +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} +) \ No newline at end of file diff --git a/cmake/dependencies/nlohmann_json.cmake b/cmake/dependencies/nlohmann_json.cmake index ad164eea..69b1558d 100644 --- a/cmake/dependencies/nlohmann_json.cmake +++ b/cmake/dependencies/nlohmann_json.cmake @@ -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() \ No newline at end of file +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} +) \ No newline at end of file diff --git a/cmake/dependencies/roar.cmake b/cmake/dependencies/roar.cmake index 5eab5439..207335fa 100644 --- a/cmake/dependencies/roar.cmake +++ b/cmake/dependencies/roar.cmake @@ -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) diff --git a/cmake/fetcher.cmake b/cmake/fetcher.cmake new file mode 100644 index 00000000..b71f64fb --- /dev/null +++ b/cmake/fetcher.cmake @@ -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() \ No newline at end of file diff --git a/cmake/frontend/emscripten.cmake b/cmake/frontend/emscripten.cmake index 490ffbe0..582a4202 100644 --- a/cmake/frontend/emscripten.cmake +++ b/cmake/frontend/emscripten.cmake @@ -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} ) @@ -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} ) diff --git a/nui/src/nui/backend/CMakeLists.txt b/nui/src/nui/backend/CMakeLists.txt index 0a62e8f8..09538469 100644 --- a/nui/src/nui/backend/CMakeLists.txt +++ b/nui/src/nui/backend/CMakeLists.txt @@ -33,7 +33,7 @@ target_link_libraries( fmt webview-iface portable_file_dialogs - nlohmann_json + nlohmann_json::nlohmann_json roar Boost::boost ) diff --git a/tools/inline_parser/src/inline_parser/CMakeLists.txt b/tools/inline_parser/src/inline_parser/CMakeLists.txt index 4975591b..6858da83 100644 --- a/tools/inline_parser/src/inline_parser/CMakeLists.txt +++ b/tools/inline_parser/src/inline_parser/CMakeLists.txt @@ -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) diff --git a/tools/parcel_adapter/CMakeLists.txt b/tools/parcel_adapter/CMakeLists.txt index ec6185b3..8fee2ecb 100644 --- a/tools/parcel_adapter/CMakeLists.txt +++ b/tools/parcel_adapter/CMakeLists.txt @@ -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