Skip to content

Commit

Permalink
alias approach
Browse files Browse the repository at this point in the history
  • Loading branch information
Equartey committed Sep 20, 2024
1 parent cd79b00 commit 7572f75
Showing 1 changed file with 24 additions and 29 deletions.
53 changes: 24 additions & 29 deletions packages/common/amplify_db_common/windows/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,26 +20,20 @@ add_library(${PLUGIN_NAME} SHARED
# Below here, keep in sync with: https://github.com/simolus3/sqlite3.dart/blob/main/sqlite3_flutter_libs/windows/CMakeLists.txt
# ##

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

# Check if the target 'sqlite3' already exists
if(NOT TARGET sqlite3_amplify_db_common)
include(FetchContent)

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

FetchContent_MakeAvailable(sqlite3)

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

target_include_directories(sqlite3 PRIVATE "${sqlite3_SOURCE_DIR}")
target_compile_options(sqlite3 PRIVATE "$<$<NOT:$<CONFIG:Debug>>:-O2>" "/w")
target_include_directories(sqlite3_amplify_db_common PRIVATE "${sqlite3_SOURCE_DIR}")
target_compile_options(sqlite3_amplify_db_common PRIVATE "$<$<NOT:$<CONFIG:Debug>>:-O2>" "/w")

# Note: Keep in sync with https://github.com/simolus3/sqlite-native-libraries/blob/master/sqlite3-native-library/cpp/CMakeLists.txt
target_compile_definitions(sqlite3 PRIVATE
target_compile_definitions(sqlite3_amplify_db_common PRIVATE
SQLITE_ENABLE_DBSTAT_VTAB
SQLITE_ENABLE_FTS5
SQLITE_ENABLE_RTREE
Expand All @@ -82,13 +77,13 @@ if(NOT TARGET sqlite3)
SQLITE_HAVE_LOCALTIME_R
SQLITE_HAVE_LOCALTIME_S
)
endif()

# Ensure sqlite3 actually gets built
add_dependencies(${PLUGIN_NAME} sqlite3)
# Ensure sqlite3_amplify_db_common is used by the plugin
add_dependencies(${PLUGIN_NAME} sqlite3_amplify_db_common)

# List of absolute paths to libraries that should be bundled with the plugin
set(amplify_db_common_bundled_libraries
"$<TARGET_FILE:sqlite3>"
PARENT_SCOPE
)
endif()
# List of absolute paths to libraries that should be bundled with the plugin
set(amplify_db_common_bundled_libraries
"$<TARGET_FILE:sqlite3_amplify_db_common>"
PARENT_SCOPE
)

0 comments on commit 7572f75

Please sign in to comment.