Skip to content

Commit 8f09398

Browse files
authored
Merge pull request #113 from NuiCpp/feat/cmake-updates
Feat/cmake updates 2
2 parents 718f252 + df88da9 commit 8f09398

File tree

9 files changed

+82
-36
lines changed

9 files changed

+82
-36
lines changed

cmake/dependencies/fmt.cmake

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
option(NUI_FETCH_FMT "Fetch fmt" ON)
1+
option(NUI_FIND_FMT "Find fmt first before fetch content" ON)
2+
option(NUI_FETCH_FMT "Try FetchContent for fmt" ON)
23
set(NUI_FMT_GIT_REPOSITORY "https://github.com/fmtlib/fmt.git" CACHE STRING "fmt git repository")
3-
set(NUI_FMT_GIT_TAG "4e8640ed90ac8751d4a8ca500b893cc8c4bb9668" CACHE STRING "fmt git tag")
4+
set(NUI_FMT_GIT_TAG "7a8b54a0ef7ca1791b0a5491b6e0593e1cf2dd5e" CACHE STRING "fmt git tag")
45

5-
if (NUI_FETCH_FMT)
6-
include(FetchContent)
7-
FetchContent_Declare(
8-
fmt
9-
GIT_REPOSITORY ${NUI_FMT_GIT_REPOSITORY}
10-
GIT_TAG ${NUI_FMT_GIT_TAG}
11-
)
6+
include("${CMAKE_CURRENT_LIST_DIR}/../fetcher.cmake")
127

13-
FetchContent_MakeAvailable(fmt)
14-
endif()
8+
nui_fetch_dependency(
9+
LIBRARY_NAME fmt
10+
FIND ${NUI_FIND_FMT}
11+
FETCH ${NUI_FETCH_FMT}
12+
GIT_REPOSITORY ${NUI_FMT_GIT_REPOSITORY}
13+
GIT_TAG ${NUI_FMT_GIT_TAG}
14+
)

cmake/dependencies/gtest.cmake

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1+
option(NUI_FIND_GTEST "Find gtest" ON)
12
option(NUI_FETCH_GTEST "Fetch gtest" ON)
23
set(NUI_GTEST_GIT_REPOSITORY "https://github.com/google/googletest.git" CACHE STRING "gtest git repository")
34
set(NUI_GTEST_GIT_TAG "beb552fb47e9e8a6ddab20526663c2dddd601ec6" CACHE STRING "gtest git tag")
45

5-
if(NUI_FETCH_GTEST)
6-
include(FetchContent)
7-
FetchContent_Declare(
8-
gtest
9-
GIT_REPOSITORY ${NUI_GTEST_GIT_REPOSITORY}
10-
GIT_TAG ${NUI_GTEST_GIT_TAG}
11-
)
6+
include("${CMAKE_CURRENT_LIST_DIR}/../fetcher.cmake")
127

13-
FetchContent_MakeAvailable(gtest)
14-
endif()
8+
nui_fetch_dependency(
9+
LIBRARY_NAME GTest
10+
FIND ${NUI_FIND_GTEST}
11+
FETCH ${NUI_FETCH_GTEST}
12+
GIT_REPOSITORY ${NUI_GTEST_GIT_REPOSITORY}
13+
GIT_TAG ${NUI_GTEST_GIT_TAG}
14+
)
Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
option(NUI_FETCH_NLOHMANN_JSON "Fetch nlohmann_json" ON)
1+
option(NUI_FIND_NLOHMANN_JSON "Try find_package to find nlohmann_json" ON)
2+
option(NUI_FETCH_NLOHMANN_JSON "Try fetch nlohmann json" ON)
23
set(NUI_NLOHMANN_JSON_GIT_REPOSITORY "https://github.com/nlohmann/json.git" CACHE STRING "nlohmann_json git repository")
34
set(NUI_NLOHMANN_JSON_GIT_TAG "8c391e04fe4195d8be862c97f38cfe10e2a3472e" CACHE STRING "nlohmann_json git tag")
45

5-
if(NUI_FETCH_NLOHMANN_JSON)
6-
include(FetchContent)
7-
FetchContent_Declare(
8-
nlohmann_json
9-
GIT_REPOSITORY ${NUI_NLOHMANN_JSON_GIT_REPOSITORY}
10-
GIT_TAG ${NUI_NLOHMANN_JSON_GIT_TAG}
11-
)
6+
include("${CMAKE_CURRENT_LIST_DIR}/../fetcher.cmake")
127

13-
FetchContent_MakeAvailable(nlohmann_json)
14-
endif()
8+
nui_fetch_dependency(
9+
LIBRARY_NAME nlohmann_json
10+
FIND ${NUI_FIND_NLOHMANN_JSON}
11+
FETCH ${NUI_FETCH_NLOHMANN_JSON}
12+
GIT_REPOSITORY ${NUI_NLOHMANN_JSON_GIT_REPOSITORY}
13+
GIT_TAG ${NUI_NLOHMANN_JSON_GIT_TAG}
14+
)

cmake/dependencies/roar.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
option(NUI_FETCH_ROAR "Fetch roar" ON)
22
set(NUI_ROAR_REPOSITORY "https://github.com/5cript/roar.git" CACHE STRING "roar repository")
3-
set(NUI_ROAR_TAG "45230b49703e8bb29cecb07c65927eb905b7c7fe" CACHE STRING "roar tag")
3+
set(NUI_ROAR_TAG "f2f03784a77e03f83b6de3120a3c54cbc427b46e" CACHE STRING "roar tag")
44

55
if(NUI_FETCH_ROAR)
66
include(FetchContent)

cmake/fetcher.cmake

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
include(FetchContent)
2+
3+
function(nui_fetch_dependency)
4+
cmake_parse_arguments(
5+
NUI_FETCH_ARGS
6+
"FIND;FETCH"
7+
"LIBRARY_NAME;PACKAGE_NAME;FETCH_NAME;GIT_REPOSITORY;GIT_TAG"
8+
""
9+
${ARGN}
10+
)
11+
12+
if (NOT NUI_FETCH_ARGS_PACKAGE_NAME)
13+
if (NOT NUI_FETCH_ARGS_LIBRARY_NAME)
14+
message(FATAL_ERROR "NUI_FETCH_ARGS_PACKAGE_NAME is not set")
15+
endif()
16+
set(NUI_FETCH_ARGS_PACKAGE_NAME ${NUI_FETCH_ARGS_LIBRARY_NAME})
17+
endif()
18+
if (NOT NUI_FETCH_ARGS_FETCH_NAME)
19+
if (NOT NUI_FETCH_ARGS_LIBRARY_NAME)
20+
message(FATAL_ERROR "NUI_FETCH_ARGS_FETCH_NAME is not set")
21+
endif()
22+
set(NUI_FETCH_ARGS_FETCH_NAME ${NUI_FETCH_ARGS_LIBRARY_NAME})
23+
endif()
24+
25+
if (NUI_FETCH_ARGS_FIND)
26+
find_package(${NUI_FETCH_ARGS_PACKAGE_NAME} QUIET)
27+
28+
if (${NUI_FETCH_ARGS_PACKAGE_NAME}_FOUND)
29+
return()
30+
endif()
31+
endif()
32+
33+
if (NUI_FETCH_ARGS_FETCH AND ${NUI_FETCH_ARGS_FETCH})
34+
message(STATUS "Fetching ${NUI_FETCH_ARGS_FETCH_NAME}")
35+
FetchContent_Declare(
36+
${NUI_FETCH_ARGS_FETCH_NAME}
37+
GIT_REPOSITORY ${NUI_FETCH_ARGS_GIT_REPOSITORY}
38+
GIT_TAG ${NUI_FETCH_ARGS_GIT_TAG}
39+
)
40+
FetchContent_MakeAvailable(${NUI_FETCH_ARGS_FETCH_NAME})
41+
endif()
42+
endfunction()

cmake/frontend/emscripten.cmake

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ function(nui_prepare_emscripten_target)
33
NUI_PREPARE_EMSCRIPTEN_TARGET_ARGS
44
"NO_INLINE;NO_INLINE_INJECT"
55
"TARGET;PREJS;STATIC;UNPACKED_MODE"
6-
"EMSCRIPTEN_LINK_OPTIONS;EMSCRIPTEN_COMPILE_OPTIONS;PARCEL_ARGS"
6+
"EMSCRIPTEN_LINK_OPTIONS;EMSCRIPTEN_COMPILE_OPTIONS;PARCEL_ARGS;NPM_INSTALL_ARGS"
77
${ARGN}
88
)
99

@@ -28,7 +28,7 @@ function(nui_prepare_emscripten_target)
2828

2929
add_custom_target(
3030
${NUI_PREPARE_EMSCRIPTEN_TARGET_ARGS_TARGET}-npm-install
31-
COMMAND ${NUI_NPM} install
31+
COMMAND ${NUI_NPM} install ${NUI_PREPARE_EMSCRIPTEN_TARGET_ARGS_NPM_INSTALL_ARGS}
3232
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
3333
)
3434

nui/src/nui/backend/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ target_link_libraries(
3333
fmt
3434
webview-iface
3535
portable_file_dialogs
36-
nlohmann_json
36+
nlohmann_json::nlohmann_json
3737
roar
3838
Boost::boost
3939
)

tools/inline_parser/src/inline_parser/CMakeLists.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,14 @@ cmake_minimum_required(VERSION 3.16)
22

33
project(inline-parser VERSION 0.1.0)
44

5+
include("${CMAKE_CURRENT_LIST_DIR}/../../../../cmake/dependencies/nlohmann_json.cmake")
6+
57
add_library(inline-parser-lib
68
STATIC
79
inline_extractor.cpp
810
section_cache.cpp
911
)
10-
target_link_libraries(inline-parser-lib PUBLIC nlohmann_json roar)
12+
target_link_libraries(inline-parser-lib PUBLIC nlohmann_json::nlohmann_json roar)
1113
target_compile_features(inline-parser-lib PUBLIC cxx_std_20)
1214
target_include_directories(inline-parser-lib PUBLIC ${CMAKE_CURRENT_LIST_DIR}/../../include)
1315

tools/parcel_adapter/CMakeLists.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@ cmake_minimum_required(VERSION 3.16)
22

33
project(parcel-adapter VERSION 0.1.0)
44

5+
include("${CMAKE_CURRENT_LIST_DIR}/../../cmake/dependencies/nlohmann_json.cmake")
6+
57
add_executable(parcel-adapter main.cpp)
6-
target_link_libraries(parcel-adapter PRIVATE nlohmann_json)
8+
target_link_libraries(parcel-adapter PRIVATE nlohmann_json::nlohmann_json)
79
target_compile_features(parcel-adapter PRIVATE cxx_std_20)
810

911
set_target_properties(parcel-adapter

0 commit comments

Comments
 (0)