CMake - Set working directory for visual studio? Topic is solved

Problems building or running the engine, queries about how to use features etc.
Post Reply
123iamking
Gremlin
Posts: 152
Joined: Sat Aug 12, 2017 4:16 pm
x 4

CMake - Set working directory for visual studio?

Post by 123iamking »

I see in the project Sample_Tutorial01_Initialization (Ogre 2.1 Sample, Visual Studio) has working directory is ../bin/$(Configuration).
How do you do that? I have tried (source)

Code: Select all

set_target_properties(${PROJECT_BIN} PROPERTIES 
    VS_DEBUGGER_WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/$(Configuration)")
But it's not working!
I have read the file "..\Samples\2.0\Tutorials\Tutorial01_Initialization\CMakeLists.txt", but I don't find any clue.
Please help :?
hyyou
Gremlin
Posts: 173
Joined: Wed Feb 03, 2016 2:24 am
x 17
Contact:

Re: CMake - Set working directory for visual studio?

Post by hyyou »

What do you mean by "not working"?
cmake execute fail / can't compile / can't link / crash ?
Is there any error log of something?
Did you follow this tutorial http://www.ogre3d.org/forums/viewtopic.php?f=25&t=92874 ?

In my installing process, I don't have a kind of problem that need me to investigate CMakeLists.txt.
I have zero knowledge about CMake script, but I can make it run.
123iamking
Gremlin
Posts: 152
Joined: Sat Aug 12, 2017 4:16 pm
x 4

Re: CMake - Set working directory for visual studio?

Post by 123iamking »

hyyou wrote:What do you mean by "not working"?
cmake execute fail / can't compile / can't link / crash ?
Is there any error log of something?
Did you follow this tutorial http://www.ogre3d.org/forums/viewtopic.php?f=25&t=92874 ?

In my installing process, I don't have a kind of problem that need me to investigate CMakeLists.txt.
I have zero knowledge about CMake script, but I can make it run.
Sorry for being vague :P by "not working" I mean the cmake script still run ok, but it doesn't set working directory (a setting in Visual studio C++ Debug Configuration) to the value: "${CMAKE_CURRENT_BINARY_DIR}/$(Configuration)".
I just want to set that value with CMake, but I don't know how. And I see that the sample project of Ogre 2.1 can set that value, so I just want to copy it - but I don't know where. Please help.
IndieGuy11
Halfling
Posts: 50
Joined: Fri May 19, 2017 8:09 pm
x 2

Re: CMake - Set working directory for visual studio?

Post by IndieGuy11 »

Look into VS_DEBUGGER_WORKING_DIRECTORY, i think this is what your after. I am not sure though because I never seen a need to code this in as its not really normal to build your cmake solutions from scratch enough times where it becomes annoying to manually set it.
hyyou
Gremlin
Posts: 173
Joined: Wed Feb 03, 2016 2:24 am
x 17
Contact:

Re: CMake - Set working directory for visual studio?

Post by hyyou »

I guess OP want to automate some of the tedious project set-up process, right?
To workaround without the script (because I lack knowledge how to script it), I use Visual Studio's property sheet (.prop).
For me, .prop is easier to code than cmake script, e.g. here is how to set the working directory :-

Code: Select all

  <PropertyGroup>
    <LocalDebuggerCommand>SomePath\$(Configuration)\$(ProjectName).exe</LocalDebuggerCommand>
    <LocalDebuggerWorkingDirectory>SomePath\$(Configuration)</LocalDebuggerWorkingDirectory> 
....
Another great thing is that Property sheet can be also inside another property sheet.
(reference: https://stackoverflow.com/questions/167 ... rty-sheets)

This solution is Visual-specific though and it is hard to refactor (notepad++ find/replace is a workaround), and it is very far from what you asked. :oops:
123iamking
Gremlin
Posts: 152
Joined: Sat Aug 12, 2017 4:16 pm
x 4

Re: CMake - Set working directory for visual studio?

Post by 123iamking »

I think I finally found it. Ogre uses CMake template method to set working directory.
In the file
E:\Source\ogre\CMake\Utils\OgreConfigTargets.cmake
There is this code:

Code: Select all

# create vcproj.user file for Visual Studio to set debug working directory
function(ogre_create_vcproj_userfile TARGETNAME)
  if (MSVC AND NOT WINDOWS_STORE AND NOT WINDOWS_PHONE)
    configure_file(
	  ${OGRE_TEMPLATES_DIR}/VisualStudioUserFile.vcproj.user.in
	  ${CMAKE_CURRENT_BINARY_DIR}/${TARGETNAME}.vcproj.user
	  @ONLY
	)
    configure_file(
	  ${OGRE_TEMPLATES_DIR}/VisualStudioUserFile.vcxproj.user.in
	  ${CMAKE_CURRENT_BINARY_DIR}/${TARGETNAME}.vcxproj.user
	  @ONLY
	)
  endif ()
endfunction(ogre_create_vcproj_userfile)
And the template files are:
"E:\Source\ogre\CMake\Templates\VisualStudioUserFile.vcproj.user.in"
"E:\Source\ogre\CMake\Templates\VisualStudioUserFile.vcxproj.user.in"

No wonder why I didn't find this, I barked up at the wrong tree
Post Reply