简体   繁体   English

CMAKE + SQLite3.dll

[英]CMAKE + SQLite3.dll

Anyone know how to copy the SQLite3.dll into the executable directory using CMAKE?任何人都知道如何使用 CMAKE 将 SQLite3.dll 复制到可执行目录中吗? I am able to use sqlite in generated VS project but when i try to run the exe it cannot find the dll.我可以在生成的 VS 项目中使用 sqlite 但是当我尝试运行 exe 时它找不到 dll。

I am guessing that CMAKE would write a copy command into the post-build events in the VS project settings?我猜 CMAKE 会在 VS 项目设置中的构建后事件中写入复制命令吗? But how is that done through CMAKE.但是如何通过 CMAKE 完成。

cmake_minimum_required(VERSION 3.10)
add_executable(APP)
target_sources(APP 
                PRIVATE
                    include/box.hpp
                    src/box.cpp
                    src/main.cpp
                )       
target_include_directories(APP PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include)                    


# SQlite
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/../cmake/Modules)
set(SQLite3_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../external/sqlite3/include)
set(SQLite3_LIBRARY ${CMAKE_CURRENT_SOURCE_DIR}/../external/sqlite3/libraries/win10/x64)
find_package (SQLite3)
if (SQLITE3_FOUND)
  include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../external/sqlite3/include)
  list(APPEND EXTRA_LIBS ${CMAKE_CURRENT_SOURCE_DIR}/../external/sqlite3/libraries/win10/x64/sqlite3.lib)
endif (SQLITE3_FOUND)



list(APPEND EXTRA_LIBS LIBCORE)
list(APPEND EXTRA_LIBS Boost::filesystem)
target_link_libraries(APP PRIVATE ${EXTRA_LIBS})




# INSTALL

install(TARGETS APP DESTINATION ${PROJECT_BINARY_DIR}/TEMP/bin)

It is possible to use cmake in CMakeLists.txt as a tool and it has file copy functionality可以在 CMakeLists.txt 中使用 cmake 作为工具,它具有文件复制功能

Something like this might be a start这样的事情可能是一个开始

set(source_file  "D:/temp/from/sqlite3.dll")
set(target_file "D:\\temp\\to\\sqlite3.dll")
execute_process( COMMAND  ${CMAKE_COMMAND} -E copy_if_different "${source_file}" "${target_file}" RESULT_VARIABLE sResult )

CMake tutorial CMake教程

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM