Skip to content

Commit 7572f75

Browse files
committed
alias approach
1 parent cd79b00 commit 7572f75

File tree

1 file changed

+24
-29
lines changed

1 file changed

+24
-29
lines changed

packages/common/amplify_db_common/windows/CMakeLists.txt

Lines changed: 24 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -20,26 +20,20 @@ add_library(${PLUGIN_NAME} SHARED
2020
# Below here, keep in sync with: https://github.com/simolus3/sqlite3.dart/blob/main/sqlite3_flutter_libs/windows/CMakeLists.txt
2121
# ##
2222

23-
# Only fetch and build sqlite3 if it hasn't been added yet
24-
if(NOT TARGET sqlite3)
25-
# Essentially, the idea of this build script is to compile a sqlite3.dll
26-
# and make Flutter bundle that with the final app.
27-
# It looks like we can't avoid building a sqlite3_flutter_libs.dll too,
28-
# but that's not on me.
29-
apply_standard_settings(${PLUGIN_NAME})
30-
set_target_properties(${PLUGIN_NAME} PROPERTIES
31-
CXX_VISIBILITY_PRESET hidden)
32-
target_compile_definitions(${PLUGIN_NAME} PRIVATE FLUTTER_PLUGIN_IMPL)
33-
target_include_directories(${PLUGIN_NAME} INTERFACE
34-
"${CMAKE_CURRENT_SOURCE_DIR}/include")
35-
target_link_libraries(${PLUGIN_NAME} PRIVATE flutter flutter_wrapper_plugin)
23+
# Apply standard settings for the plugin
24+
apply_standard_settings(${PLUGIN_NAME})
25+
set_target_properties(${PLUGIN_NAME} PROPERTIES
26+
CXX_VISIBILITY_PRESET hidden)
27+
target_compile_definitions(${PLUGIN_NAME} PRIVATE FLUTTER_PLUGIN_IMPL)
28+
target_include_directories(${PLUGIN_NAME} INTERFACE
29+
"${CMAKE_CURRENT_SOURCE_DIR}/include")
30+
target_link_libraries(${PLUGIN_NAME} PRIVATE flutter flutter_wrapper_plugin)
3631

32+
# Check if the target 'sqlite3' already exists
33+
if(NOT TARGET sqlite3_amplify_db_common)
3734
include(FetchContent)
3835

3936
if(CMAKE_VERSION VERSION_GREATER_EQUAL "3.24.0")
40-
# cmake 3.24.0 added the `DOWNLOAD_EXTRACT_TIMESTAMP` and prints an ugly warning when
41-
# the default is used, so override it to the recommended behavior.
42-
# We can't really ask users to use a cmake that recent, so there's this if here.
4337
FetchContent_Declare(
4438
sqlite3
4539
URL https://sqlite.org/2024/sqlite-autoconf-3460000.tar.gz
@@ -54,13 +48,14 @@ if(NOT TARGET sqlite3)
5448

5549
FetchContent_MakeAvailable(sqlite3)
5650

57-
add_library(sqlite3 SHARED "sqlite3_flutter.c")
51+
# Create an alias for the sqlite3 library specifically for amplify_db_common
52+
# Must be preserved to avoid collisions, ie consumer has a dependency on sqlite3 too
53+
add_library(sqlite3_amplify_db_common SHARED "sqlite3_flutter.c")
5854

59-
target_include_directories(sqlite3 PRIVATE "${sqlite3_SOURCE_DIR}")
60-
target_compile_options(sqlite3 PRIVATE "$<$<NOT:$<CONFIG:Debug>>:-O2>" "/w")
55+
target_include_directories(sqlite3_amplify_db_common PRIVATE "${sqlite3_SOURCE_DIR}")
56+
target_compile_options(sqlite3_amplify_db_common PRIVATE "$<$<NOT:$<CONFIG:Debug>>:-O2>" "/w")
6157

62-
# Note: Keep in sync with https://github.com/simolus3/sqlite-native-libraries/blob/master/sqlite3-native-library/cpp/CMakeLists.txt
63-
target_compile_definitions(sqlite3 PRIVATE
58+
target_compile_definitions(sqlite3_amplify_db_common PRIVATE
6459
SQLITE_ENABLE_DBSTAT_VTAB
6560
SQLITE_ENABLE_FTS5
6661
SQLITE_ENABLE_RTREE
@@ -82,13 +77,13 @@ if(NOT TARGET sqlite3)
8277
SQLITE_HAVE_LOCALTIME_R
8378
SQLITE_HAVE_LOCALTIME_S
8479
)
80+
endif()
8581

86-
# Ensure sqlite3 actually gets built
87-
add_dependencies(${PLUGIN_NAME} sqlite3)
82+
# Ensure sqlite3_amplify_db_common is used by the plugin
83+
add_dependencies(${PLUGIN_NAME} sqlite3_amplify_db_common)
8884

89-
# List of absolute paths to libraries that should be bundled with the plugin
90-
set(amplify_db_common_bundled_libraries
91-
"$<TARGET_FILE:sqlite3>"
92-
PARENT_SCOPE
93-
)
94-
endif()
85+
# List of absolute paths to libraries that should be bundled with the plugin
86+
set(amplify_db_common_bundled_libraries
87+
"$<TARGET_FILE:sqlite3_amplify_db_common>"
88+
PARENT_SCOPE
89+
)

0 commit comments

Comments
 (0)