-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
84 lines (73 loc) · 2.82 KB
/
CMakeLists.txt
File metadata and controls
84 lines (73 loc) · 2.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# The Flutter tooling requires that developers have CMake 3.10 or later
# installed. You should not increase this version, as doing so will cause
# the plugin to fail to compile for some customers of the plugin.
cmake_minimum_required(VERSION 3.10)
project(nativeapi VERSION 0.0.1 LANGUAGES CXX)
# Enable Objective-C++
if(APPLE)
enable_language(OBJCXX)
endif()
# Set C++ standard
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
# Common source files
file(GLOB COMMON_SOURCES "*.cpp" "foundation/*.cpp")
list(FILTER COMMON_SOURCES EXCLUDE REGEX "platform/*")
# C API source files
file(GLOB CAPI_SOURCES "capi/*.cpp" "capi/*.c")
# Platform-specific source files
if(ANDROID)
file(GLOB PLATFORM_SOURCES "platform/android/*.cpp")
elseif(CMAKE_SYSTEM_NAME STREQUAL "iOS")
file(GLOB PLATFORM_SOURCES "platform/ios/*.mm")
elseif(CMAKE_SYSTEM_NAME STREQUAL "Linux")
file(GLOB PLATFORM_SOURCES "platform/linux/*.cpp")
# Find packages for Linux
find_package(PkgConfig REQUIRED)
pkg_check_modules(GTK REQUIRED IMPORTED_TARGET gtk+-3.0)
pkg_check_modules(X11 REQUIRED IMPORTED_TARGET x11)
pkg_check_modules(XI REQUIRED IMPORTED_TARGET xi)
elseif(APPLE)
file(GLOB PLATFORM_SOURCES "platform/macos/*.mm")
elseif(CMAKE_SYSTEM_NAME STREQUAL "OHOS")
file(GLOB PLATFORM_SOURCES "platform/ohos/*.cpp")
elseif(WIN32)
file(GLOB PLATFORM_SOURCES "platform/windows/*.cpp")
else()
set(PLATFORM_SOURCES "")
endif()
# Add library target
add_library(nativeapi STATIC
${COMMON_SOURCES}
${PLATFORM_SOURCES}
${CAPI_SOURCES}
)
# Set library properties
set_target_properties(nativeapi PROPERTIES
PUBLIC_HEADER "${CMAKE_CURRENT_SOURCE_DIR}/../include/**/*.h"
)
# Set library include directories
target_include_directories(nativeapi PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/../include>
$<INSTALL_INTERFACE:include>
)
if (CMAKE_SYSTEM_NAME STREQUAL "Linux")
target_include_directories(nativeapi PUBLIC ${GTK_INCLUDE_DIRS})
endif ()
# Link required frameworks and libraries
if(ANDROID)
target_link_libraries(nativeapi PUBLIC log android)
elseif(CMAKE_SYSTEM_NAME STREQUAL "iOS")
target_link_libraries(nativeapi PUBLIC "-framework UIKit" "-framework Foundation" "-framework CoreGraphics")
target_compile_options(nativeapi PRIVATE "-x" "objective-c++")
elseif (CMAKE_SYSTEM_NAME STREQUAL "Linux")
target_link_libraries(nativeapi PUBLIC PkgConfig::GTK PkgConfig::X11 PkgConfig::XI pthread)
elseif(APPLE)
target_link_libraries(nativeapi PUBLIC "-framework Cocoa")
target_link_libraries(nativeapi PUBLIC "-framework Carbon")
target_compile_options(nativeapi PRIVATE "-x" "objective-c++")
elseif(CMAKE_SYSTEM_NAME STREQUAL "OHOS")
target_link_libraries(nativeapi PUBLIC hilog_ndk.z)
elseif(WIN32)
target_link_libraries(nativeapi PUBLIC user32 shell32 dwmapi gdiplus crypt32 advapi32)
endif ()