Flutter windows: can I use relative path to bundle `.dll` library in CMakeLists.txt?
Just use:
set(server_bundled_libraries "${CMAKE_CURRENT_SOURCE_DIR}/lib.dll" PARENT_SCOPE)
The CMAKE_CURRENT_SOURCE_DIR
variable will expand to current source directory as tracked by add_subdirectory
. This is usually, but not always, the directory in which the present CMakeLists.txt
resides. Presumably, this is E:/_Projects/mahesabu/client/packages/server/windows
on your computer (given your remark that you expect ./lib.dll
to work), but will be somewhere else on CI or elsewhere.
Admin
Updated on January 04, 2023Comments
-
Admin over 1 year
I am building a flutter plugin which calls native functions from
lib.dll
file and everything works as expected in my computer.But I use relative path to link that
lib
such asE:/_Projects/mahesabu/client/packages/server/windows/lib.dll
Now I want to move the build process in CI/CD which I believe using relative path such as
./lib.dll
would be very easy.Of cource I am new to cmake configuration. And in one comment it is written
List of absolute paths to libraries that should be bundled with the plugin
I wonder how can I use relative path there, because if I try build fails. The following is CMakeLists.txt
cmake_minimum_required(VERSION 3.14) set(PROJECT_NAME "server") project(${PROJECT_NAME} LANGUAGES CXX) # This value is used when generating builds using this plugin, so it must # not be changed set(PLUGIN_NAME "server_plugin") add_library(${PLUGIN_NAME} SHARED "server_plugin.cpp" ) 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) # List of absolute paths to libraries that should be bundled with the plugin set(server_bundled_libraries "" "E:/_Projects/mahesabu/client/packages/server/windows/lib.dll" #USE RELATIVE PATH HERE PARENT_SCOPE )
Any help will be appreciated.
-
Nux almost 2 yearsThanks for answering. I tried as suggested but
CMAKE_CURRENT_SOURCE_DIR
is what worked. -
Alex Reinking almost 2 years@Nux glad it worked! Those two variables often have the same value, but I wasn't sure how your source tree was laid out.