Skip to content

Commit 03d32e5

Browse files
committed
Refactor platform-specific CMake logic
Reordered and consolidated platform-specific source file and library linking logic in CMakeLists.txt for improved clarity and maintainability. Android and iOS conditions are now prioritized, and redundant checks have been removed.
1 parent 4dcd31d commit 03d32e5

File tree

1 file changed

+14
-14
lines changed

1 file changed

+14
-14
lines changed

src/CMakeLists.txt

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -22,24 +22,24 @@ list(FILTER COMMON_SOURCES EXCLUDE REGEX "platform/*")
2222
file(GLOB CAPI_SOURCES "capi/*.cpp" "capi/*.c")
2323

2424
# Platform-specific source files
25-
if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
25+
if(ANDROID)
26+
file(GLOB PLATFORM_SOURCES "platform/android/*.cpp")
27+
elseif(CMAKE_SYSTEM_NAME STREQUAL "iOS")
28+
file(GLOB PLATFORM_SOURCES "platform/ios/*.mm")
29+
elseif(CMAKE_SYSTEM_NAME STREQUAL "Linux")
2630
file(GLOB PLATFORM_SOURCES "platform/linux/*.cpp")
2731
# Find packages for Linux
2832
find_package(PkgConfig REQUIRED)
2933
pkg_check_modules(GTK REQUIRED IMPORTED_TARGET gtk+-3.0)
3034
pkg_check_modules(X11 REQUIRED IMPORTED_TARGET x11)
3135
pkg_check_modules(XI REQUIRED IMPORTED_TARGET xi)
3236
pkg_check_modules(AYATANA_APPINDICATOR REQUIRED IMPORTED_TARGET ayatana-appindicator3-0.1)
33-
elseif(CMAKE_SYSTEM_NAME STREQUAL "iOS")
34-
file(GLOB PLATFORM_SOURCES "platform/ios/*.mm")
3537
elseif(APPLE)
3638
file(GLOB PLATFORM_SOURCES "platform/macos/*.mm")
37-
elseif(WIN32)
38-
file(GLOB PLATFORM_SOURCES "platform/windows/*.cpp")
39-
elseif(ANDROID)
40-
file(GLOB PLATFORM_SOURCES "platform/android/*.cpp")
4139
elseif(CMAKE_SYSTEM_NAME STREQUAL "OHOS")
4240
file(GLOB PLATFORM_SOURCES "platform/ohos/*.cpp")
41+
elseif(WIN32)
42+
file(GLOB PLATFORM_SOURCES "platform/windows/*.cpp")
4343
else()
4444
set(PLATFORM_SOURCES "")
4545
endif()
@@ -67,18 +67,18 @@ if (CMAKE_SYSTEM_NAME STREQUAL "Linux")
6767
endif ()
6868

6969
# Link required frameworks and libraries
70-
if(CMAKE_SYSTEM_NAME STREQUAL "iOS")
70+
if(ANDROID)
71+
target_link_libraries(nativeapi PUBLIC log android)
72+
elseif(CMAKE_SYSTEM_NAME STREQUAL "iOS")
7173
target_link_libraries(nativeapi PUBLIC "-framework UIKit" "-framework Foundation" "-framework CoreGraphics")
7274
target_compile_options(nativeapi PRIVATE "-x" "objective-c++")
75+
elseif (CMAKE_SYSTEM_NAME STREQUAL "Linux")
76+
target_link_libraries(nativeapi PUBLIC PkgConfig::GTK PkgConfig::X11 PkgConfig::XI PkgConfig::AYATANA_APPINDICATOR pthread)
7377
elseif(APPLE)
7478
target_link_libraries(nativeapi PUBLIC "-framework Cocoa")
7579
target_compile_options(nativeapi PRIVATE "-x" "objective-c++")
76-
elseif (CMAKE_SYSTEM_NAME STREQUAL "Linux")
77-
target_link_libraries(nativeapi PUBLIC PkgConfig::GTK PkgConfig::X11 PkgConfig::XI PkgConfig::AYATANA_APPINDICATOR pthread)
78-
elseif(WIN32)
79-
target_link_libraries(nativeapi PUBLIC user32 shell32 dwmapi gdiplus crypt32)
80-
elseif(ANDROID)
81-
target_link_libraries(nativeapi PUBLIC log android)
8280
elseif(CMAKE_SYSTEM_NAME STREQUAL "OHOS")
8381
target_link_libraries(nativeapi PUBLIC hilog_ndk.z)
82+
elseif(WIN32)
83+
target_link_libraries(nativeapi PUBLIC user32 shell32 dwmapi gdiplus crypt32)
8484
endif ()

0 commit comments

Comments
 (0)