How to setup cmake to copy Resources to build folder when change a file ( or files)

Currently, I use cocos2dx v3.17.2 and Visual studio 2017/2019.

As you can see this code below

if(LINUX OR WINDOWS)
set(APP_RES_DIR "$<TARGET_FILE_DIR:${APP_NAME}>/Resources")
cocos_copy_target_res(${APP_NAME} COPY_TO ${APP_RES_DIR} FOLDERS ${GAME_RES_FOLDER})
endif()

→ If there is any change in source code ( not Resouces folder ) → all files in the Resouces folder will copy to the build folder. It’s quite a waste of my time because in the Resources folder I have a lot of files ( images, audios, fonts .etc…)

→ Now, I just want to copy the Resources folder to build a folder when the Resouces folder has changed files! Can someone help me rewrite this cmake ?

There is a solution that would save you a lot of time here. Instead of copying the resources, it just creates a symbolic link to the resources folder, so it’s instant.

1 Like

I follow this solution above, but I have an error as below :sleepy:

1>EXEC : CMake error : failed to create symbolic link ‘D:/apps/b2/bin/TestApp/Debug/Resources’: operation not permitted
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Microsoft\VC\v160\Microsoft.CppCommon.targets(143,5): error MSB3073: The command “setlocal
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Microsoft\VC\v160\Microsoft.CppCommon.targets(143,5): error MSB3073: “C:\Program Files\CMake\bin\cmake.exe” -E create_symlink D:/apps/Resources D:/apps/b2/bin/TestApp/Debug/Resources
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Microsoft\VC\v160\Microsoft.CppCommon.targets(143,5): error MSB3073: if %errorlevel% neq 0 goto :cmEnd
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Microsoft\VC\v160\Microsoft.CppCommon.targets(143,5): error MSB3073: :cmEnd
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Microsoft\VC\v160\Microsoft.CppCommon.targets(143,5): error MSB3073: endlocal & call :cmErrorLevel %errorlevel% & goto :cmDone
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Microsoft\VC\v160\Microsoft.CppCommon.targets(143,5): error MSB3073: :cmErrorLevel
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Microsoft\VC\v160\Microsoft.CppCommon.targets(143,5): error MSB3073: exit /b %1
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Microsoft\VC\v160\Microsoft.CppCommon.targets(143,5): error MSB3073: :cmDone
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Microsoft\VC\v160\Microsoft.CppCommon.targets(143,5): error MSB3073: if %errorlevel% neq 0 goto :VCEnd
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Microsoft\VC\v160\Microsoft.CppCommon.targets(143,5): error MSB3073: :VCEnd” exited with code 1.

If the Resource folder already exists in the build output folder, you’ll have issues. Did you do a clean build first? Check the D:/apps/b2/bin/TestApp/Debug/ path and make sure there is no Resources folder already in there, and if there is, delete it.

I can’t think of any other reason for that error at the moment.

1 Like

I solved this problem by running the Visual Studio as Administrator permissions

You shouldn’t need to run VS in admin mode, and it’s probably not a good idea to do so. If you have to do that it may mean that the permissions on the build output folder are probably not correct.

1 Like

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.