4

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.

1 Answer 1

4

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.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.