Copy DLL files to the binary directory on Mac and Linux.

According to the CMake documentation, we can use the following command to copy DLL files to the binary directory under the Windows operating system:

if(WIN32)
    
	add_custom_command(TARGET ${EXECUTABLE_NAME} POST_BUILD
		COMMAND ${CMAKE_COMMAND} -E copy_if_different
		$<TARGET_RUNTIME_DLLS:${EXECUTABLE_NAME}>
		$<TARGET_FILE_DIR:${EXECUTABLE_NAME}>
		COMMAND_EXPAND_LISTS
		COMMENT "Copying DLLs to target directory")
endif()

However, for MacOS and Linux operating systems, the process isn’t as straightforward. I was wondering if there is something similar in nature for them as well?

MacOS and Linux have RPATH so you don’t need to copy SHARED libraries into the same directory as your executable. Windows lacks RPATH functionality.

1 Like

Great, so I don’t need to copy anything. But, do I need to include any special command to instruct the system to take advantage of RPATH or are they just self aware?

IIRC by default RPATH will be used in the build tree when it’s available.

1 Like