Skip to content

Commit

Permalink
Merge pull request #112 from NuiCpp/feat/cmake-updates
Browse files Browse the repository at this point in the history
Update cmake files for 3.30
  • Loading branch information
5cript authored Jul 7, 2024
2 parents 36fbcce + 0fa3983 commit 718f252
Show file tree
Hide file tree
Showing 8 changed files with 64 additions and 49 deletions.
6 changes: 1 addition & 5 deletions cmake/dependencies/binaryen.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,5 @@ if (NUI_FETCH_BINARYEN)
DOWNLOAD_EXTRACT_TIMESTAMP TRUE
URL "${NUI_BINARYEN_URL}"
)
FetchContent_GetProperties(binaryen_release)
if (binaryen_release_POPULATED)
else()
FetchContent_Populate(binaryen_release)
endif()
FetchContent_MakeAvailable(binaryen_release)
endif()
5 changes: 5 additions & 0 deletions cmake/dependencies/boost.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
if (CMAKE_VERSION VERSION_LESS "3.30")
find_package(Boost 1.81.0 REQUIRED COMPONENTS system)
else()
find_package(Boost CONFIG 1.81.0 REQUIRED COMPONENTS system)
endif()
5 changes: 1 addition & 4 deletions cmake/dependencies/libcpppre.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,7 @@ if(NUI_FETCH_LIBCPPPRE)
GIT_TAG ffc013750515f9e73342eb2a51efed284826ead3
)

FetchContent_GetProperties(libcpppre)
if(NOT libcpppre_POPULATED)
FetchContent_Populate(libcpppre)
endif()
FetchContent_MakeAvailable(libcpppre)

add_library(libcpppre INTERFACE)
target_include_directories(libcpppre INTERFACE ${CMAKE_BINARY_DIR}/_deps/libcpppre-src)
Expand Down
2 changes: 1 addition & 1 deletion cmake/dependencies/nlohmann_json.cmake
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
option(NUI_FETCH_NLOHMANN_JSON "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 "9dfa7226693012ed5bcf5ab3bc5d8e69d58006ab" CACHE STRING "nlohmann_json git tag")
set(NUI_NLOHMANN_JSON_GIT_TAG "8c391e04fe4195d8be862c97f38cfe10e2a3472e" CACHE STRING "nlohmann_json git tag")

if(NUI_FETCH_NLOHMANN_JSON)
include(FetchContent)
Expand Down
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 "f88b5f46e145376d392c43dc621690f58278582c" CACHE STRING "roar tag")
set(NUI_ROAR_TAG "45230b49703e8bb29cecb07c65927eb905b7c7fe" CACHE STRING "roar tag")

if(NUI_FETCH_ROAR)
include(FetchContent)
Expand Down
79 changes: 48 additions & 31 deletions cmake/dependencies/webview.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -13,43 +13,57 @@ set(NUI_WEBVIEW_TAG "c962bbe343c82d58ecfdfb2942d49cc2c1410705" CACHE STRING "Web

if (NUI_FETCH_WEBVIEW)
include(FetchContent)
FetchContent_Declare(
webview_raw
GIT_REPOSITORY ${NUI_WEBVIEW_REPOSITORY}
GIT_TAG ${NUI_WEBVIEW_TAG}
)
FetchContent_Populate(webview_raw)
add_library(webview INTERFACE)
if (CMAKE_VERSION VERSION_LESS "3.28.0")
FetchContent_Declare(
webview_raw
GIT_REPOSITORY ${NUI_WEBVIEW_REPOSITORY}
GIT_TAG ${NUI_WEBVIEW_TAG}
)
else()
FetchContent_Declare(
webview_raw
EXCLUDE_FROM_ALL
GIT_REPOSITORY ${NUI_WEBVIEW_REPOSITORY}
GIT_TAG ${NUI_WEBVIEW_TAG}
)
endif()
FetchContent_GetProperties(webview_raw)
if (webview_raw_POPULATED)
else()
FetchContent_Populate(webview_raw)
endif()

add_library(webview-iface INTERFACE)

add_custom_target(
webview-prep
webview-nui-prep
COMMAND ${CMAKE_COMMAND} -E make_directory "${CMAKE_BINARY_DIR}/include"
COMMAND ${CMAKE_COMMAND} -E copy_if_different "${CMAKE_BINARY_DIR}/_deps/webview_raw-src/webview.h" "${CMAKE_BINARY_DIR}/include/webview.h"
COMMAND_EXPAND_LISTS
)

target_include_directories(webview INTERFACE "${CMAKE_BINARY_DIR}/include")
add_dependencies(webview webview-prep)
target_include_directories(webview-iface INTERFACE "${CMAKE_BINARY_DIR}/include")
add_dependencies(webview-iface webview-nui-prep)

set_target_properties(webview PROPERTIES INTERFACE_SYSTEM_INCLUDE_DIRECTORIES $<TARGET_PROPERTY:webview,INTERFACE_INCLUDE_DIRECTORIES>)
set_target_properties(webview-iface PROPERTIES INTERFACE_SYSTEM_INCLUDE_DIRECTORIES $<TARGET_PROPERTY:webview-iface,INTERFACE_INCLUDE_DIRECTORIES>)

target_link_libraries(
webview
webview-iface
INTERFACE
$<$<PLATFORM_ID:Linux>:
PkgConfig::webkit2
>
)
target_link_libraries(
webview
webview-iface
INTERFACE
$<$<PLATFORM_ID:Windows>:
Version.lib
WebView2Loader.lib
>
)
target_link_libraries(
webview
webview-iface
INTERFACE
$<$<PLATFORM_ID:Darwin>:
"-framework WebKit"
Expand All @@ -58,53 +72,56 @@ if (NUI_FETCH_WEBVIEW)

if (WIN32)
option(NUI_FETCH_WEBVIEW_BINARY "Fetch webview binary" ON)
set(NUI_WEBVIEW_BINARY_URL "https://www.nuget.org/api/v2/package/Microsoft.Web.WebView2" CACHE STRING "Webview binary url")
set(NUI_WEBVIEW_BINARY_URL "http://www.nuget.org/api/v2/package/Microsoft.Web.WebView2" CACHE STRING "Webview binary url")

if (NUI_FETCH_WEBVIEW_BINARY)
include(FetchContent)
FetchContent_Declare(
webview_binary
URL ${NUI_WEBVIEW_BINARY_URL}
DOWNLOAD_EXTRACT_TIMESTAMP true
)
FetchContent_GetProperties(webview_binary)
if (webview_binary_POPULATED)
if (CMAKE_VERSION VERSION_LESS "3.24")
FetchContent_Declare(
webview-binary-nui
URL ${NUI_WEBVIEW_BINARY_URL}
)
else()
FetchContent_Populate(webview_binary)
FetchContent_Declare(
webview-binary-nui
DOWNLOAD_EXTRACT_TIMESTAMP true
URL ${NUI_WEBVIEW_BINARY_URL}
)
endif()
FetchContent_MakeAvailable(webview-binary-nui)

if (CMAKE_SIZEOF_VOID_P EQUAL 8)
set(WEBVIEW_DLL_SUBDIRECTORY "x64")
else()
set(WEBVIEW_DLL_SUBDIRECTORY "x86")
endif()

target_include_directories(webview INTERFACE "${CMAKE_BINARY_DIR}/_deps/webview_binary-src/build/native/include")
target_include_directories(webview-iface INTERFACE "${CMAKE_BINARY_DIR}/_deps/webview-binary-nui-src/build/native/include")
target_link_directories(
webview
webview-iface
INTERFACE
"${CMAKE_BINARY_DIR}/_deps/webview_binary-src/build/native/${WEBVIEW_DLL_SUBDIRECTORY}"
"${CMAKE_BINARY_DIR}/_deps/webview-binary-nui-src/build/native/${WEBVIEW_DLL_SUBDIRECTORY}"
"${CMAKE_BINARY_DIR}/lib"
)
add_dependencies(webview webview2-win)
add_dependencies(webview-iface webview2-win-nui)

add_custom_command(
OUTPUT "${CMAKE_BINARY_DIR}/bin/WebView2Loader.dll"
COMMAND ${CMAKE_COMMAND} -E make_directory "${CMAKE_BINARY_DIR}/bin"
COMMAND ${CMAKE_COMMAND} -E copy "${CMAKE_BINARY_DIR}/_deps/webview_binary-src/build/native/${WEBVIEW_DLL_SUBDIRECTORY}/WebView2Loader.dll" "${CMAKE_BINARY_DIR}/bin"
COMMAND ${CMAKE_COMMAND} -E copy "${CMAKE_BINARY_DIR}/_deps/webview-binary-nui-src/build/native/${WEBVIEW_DLL_SUBDIRECTORY}/WebView2Loader.dll" "${CMAKE_BINARY_DIR}/bin"
)
add_custom_command(
OUTPUT "${CMAKE_BINARY_DIR}/lib/WebView2Loader.lib"
COMMAND ${CMAKE_COMMAND} -E make_directory "${CMAKE_BINARY_DIR}/lib"
COMMAND ${CMAKE_COMMAND} -E copy "${CMAKE_BINARY_DIR}/_deps/webview_binary-src/build/native/${WEBVIEW_DLL_SUBDIRECTORY}/WebView2Loader.dll.lib" "${CMAKE_BINARY_DIR}/lib/WebView2Loader.lib"
COMMAND ${CMAKE_COMMAND} -E copy "${CMAKE_BINARY_DIR}/_deps/webview-binary-nui-src/build/native/${WEBVIEW_DLL_SUBDIRECTORY}/WebView2Loader.dll.lib" "${CMAKE_BINARY_DIR}/lib/WebView2Loader.lib"
)
add_custom_command(
OUTPUT "${CMAKE_BINARY_DIR}/include/webview2_iids.h"
COMMAND ${CMAKE_COMMAND} -E make_directory "${CMAKE_BINARY_DIR}/include"
COMMAND $<TARGET_FILE:webview-uuid> "${CMAKE_BINARY_DIR}/_deps/webview_binary-src/build/native/include/WebView2.h" "${CMAKE_BINARY_DIR}/include/webview2_iids.h"
COMMAND $<TARGET_FILE:webview-uuid> "${CMAKE_BINARY_DIR}/_deps/webview-binary-nui-src/build/native/include/WebView2.h" "${CMAKE_BINARY_DIR}/include/webview2_iids.h"
)
add_custom_target(
webview2-win
webview2-win-nui
DEPENDS "${CMAKE_BINARY_DIR}/bin/WebView2Loader.dll"
DEPENDS "${CMAKE_BINARY_DIR}/lib/WebView2Loader.lib"
DEPENDS "${CMAKE_BINARY_DIR}/include/webview2_iids.h"
Expand Down
12 changes: 6 additions & 6 deletions nui/src/nui/backend/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,21 @@ add_library(Nui::backend ALIAS nui-backend)
target_include_directories(
nui-backend
PUBLIC
${CMAKE_CURRENT_LIST_DIR}/../../../include
${CMAKE_CURRENT_LIST_DIR}/../../../windows
${CMAKE_BINARY_DIR}/include
"${CMAKE_CURRENT_LIST_DIR}/../../../include"
"${CMAKE_CURRENT_LIST_DIR}/../../../windows"
"${CMAKE_BINARY_DIR}/include"
)
nui_set_project_warnings(nui-backend)

find_package(Boost 1.80.0 REQUIRED COMPONENTS system)
find_package(Boost CONFIG 1.80.0 REQUIRED COMPONENTS system)

target_link_libraries(
nui-backend
PRIVATE
project-settings
PUBLIC
fmt
webview
webview-iface
portable_file_dialogs
nlohmann_json
roar
Expand All @@ -47,7 +47,7 @@ if (APPLE)
endif()

if (WIN32)
target_include_directories(nui-backend PUBLIC ${CMAKE_BINARY_DIR}/libs/webview2/build/native/include)
target_include_directories(nui-backend PUBLIC "${CMAKE_BINARY_DIR}/libs/webview2/build/native/include")
target_link_libraries(nui-backend PUBLIC WebView2Loader.dll ole32 shell32 shlwapi user32)
target_sources(nui-backend
PRIVATE
Expand Down
2 changes: 1 addition & 1 deletion nui/src/nui/frontend/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ add_library(Nui::frontend ALIAS nui-frontend)
target_include_directories(
nui-frontend
PUBLIC
${CMAKE_CURRENT_LIST_DIR}/../../../include
"${CMAKE_CURRENT_LIST_DIR}/../../../include"
)
target_link_libraries(
nui-frontend
Expand Down

0 comments on commit 718f252

Please sign in to comment.