I'm trying to make a simple sfml/c++ application using cmake.
Suppose I need to refer to a simple foo.png
somewhere in my code. I found out that I can only do so if it lies inside of the build
folder. This is the folder from where I invoke the cmake ..
command and where all of my cmake files (apart from CMakeLists.txt
and library modules, such as FindSFML.cmake
) reside.
I don't want it to look there... but in a folder that is called art
, located in build
's parent directory. I want to do this to keep the "build" folder not essential to the project (in the sense that anyone can build the project without relying on stuff that's inside of it).
From what I've seen - looking online, that is - everyone tends to suggest to use the file(COPY ...)
command (or something similar) to copy all of the needed assets/resources inside of another folder similar to my before-mentioned build
folder (I know there must be a technical term for this... build directory, perhaps?), and profit. But is this copying process really necessary? Shouldn't you be able to just specify a different directory from which to load your assets/resources?
Or maybe I've got it all wrong... cmake is just hard to understand sometimes. Thanks in advance and excuse my lack of technical knowledge.
I found a solution using symbolic links and the add_custom_command
function.
Here it is (assuming the layout described above):
set (source "${CMAKE_SOURCE_DIR}/resources")
set (destination "${CMAKE_CURRENT_BINARY_DIR}/resources")
add_custom_command(
TARGET ${PROJECT_NAME} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E create_symlink ${source} ${destination}
DEPENDS ${destination}
COMMENT "symbolic link resources folder from ${source} => ${destination}"
)
I actually got this from a blog... here's the link to the article for good citizenship: http://qrikko.blogspot.it/2016/05/cmake-and-how-to-copy-resources-during.html
Have a nice day.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With