简体   繁体   中英

CMAKE + SQLite3.dll

Anyone know how to copy the SQLite3.dll into the executable directory using CMAKE? I am able to use sqlite in generated VS project but when i try to run the exe it cannot find the dll.

I am guessing that CMAKE would write a copy command into the post-build events in the VS project settings? But how is that done through 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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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