Jason
Jason

Reputation: 2298

cannot get .dll file copied to executable folder with CMake

via this answer:

How to copy DLL files into the same folder as the executable using CMake?

I'm trying to copy SDL2.dll to where my .exe is being stored. However, this isn't working for me. Here is my CMakeLists.txt file with the add_custom_command that is, theoretically, responsible for copying the dll to the target exe directory:

cmake_minimum_required(VERSION 2.8.11)

project(Another)
set (CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})

add_executable(Test "${CMAKE_SOURCE_DIR}/SourCe/MAin.cpp")

find_path(SDL2_INCLUDE_DIR SDL.h HINTS "${CMAKE_SOURCE_DIR}/ThirdParty/SDL2/Include/")
find_library(SDL2_LIBRARY_DIR SDL2 HINTS "${CMAKE_SOURCE_DIR}/ThirdParty/SDL2/Lib/x86")
find_library(SDL2MAIN_LIBRARY_DIR SDL2main HINTS "${CMAKE_SOURCE_DIR}/ThirdParty/SDL2/Lib/x86")

add_custom_command(TARGET Test POST_BUILD
     COMMAND ${CMAKE_COMMAND} -E copy_directory
         "${CMAKE_SOURCE_DIR}/ThirdParty/SDL2/lib/x86/SDL2.dll"
         $<TARGET_FILE_DIR:Test>)

include_directories(${SDL2_INCLUDE_DIR})
target_link_libraries(Test ${SDL2_LIBRARY_DIR})
target_link_libraries(Test ${SDL2MAIN_LIBRARY_DIR})

This is the only CMakelists.txt file in my project so I haven't altered where my exe is being stored (which it seems by default to be in the build folder under 'debug'). I'm still new to cmake so I was wondering if someone could guide me in the direction of my error. Thanks!

Upvotes: 2

Views: 1668

Answers (1)

Jason
Jason

Reputation: 2298

I discovered the issue. The command I was looking for was "copy_if_different" and not "copy_directory" within the add_custom_command() function.

Upvotes: 3

Related Questions