# reading files from sourceDir rather than sourceDir/build/project.app/Contents/MacOS/

**URL:** https://discourse.vtk.org/t/reading-files-from-sourcedir-rather-than-sourcedir-build-project-app-contents-macos/14829
**Category:** Support
**Created:** [November 6, 2024, 9:04am UTC](https://discourse.vtk.org/t/reading-files-from-sourcedir-rather-than-sourcedir-build-project-app-contents-macos/14829 "2024-11-06T09:04:55Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![RoyMultiC](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/r/d9b06d/32.png) [@RoyMultiC](https://discourse.vtk.org/u/RoyMultiC)
#### Post date: [November 6, 2024, 9:04am UTC](https://discourse.vtk.org/t/reading-files-from-sourcedir-rather-than-sourcedir-build-project-app-contents-macos/14829/1 "2024-11-06T09:04:55Z")

</div>

Hi everyone,

I’m currently working on the example from [[https://examples.vtk.org/site/Cxx/IO/ReadSTL/](https://examples.vtk.org/site/Cxx/IO/ReadSTL/)]. I noticed that the STL files are only successfully read when I place them in the directory: /source/cmake-build-debug/VTK\_importSTL.app/Contents/MacOS/.

I would like to read the files directly from the /source directory instead.  
I have already add `include_directories( ${CMAKE_CURRENT_SOURCE_DIR} )` in CMakeLists.txt and add `$ContentRoot$` to the Working Directory but neither of these works.  
Could this be solved by changing my CMake configuration?

Here is my CmakeLists.txt

```auto
cmake_minimum_required( VERSION 3.29 )
project( VTK_importSTL )
find_package( VTK COMPONENTS
              CommonColor
              CommonCore
              IOGeometry
              InteractionStyle
              RenderingContextOpenGL2
              RenderingCore
              RenderingFreeType
              RenderingGL2PSOpenGL2
              RenderingOpenGL2
)
if(NOT VTK_FOUND)
    message( FATAL_ERROR "VTK components: Unable to find the VTK build folder." )
endif()

# Prevent a "command line is too long" failure in Windows.
set( CMAKE_NINJA_FORCE_RESPONSE_FILE "ON" CACHE BOOL "Force Ninja to use response files." )
add_executable( VTK_importSTL MACOSX_BUNDLE main.cpp )
target_link_libraries( VTK_importSTL PRIVATE ${VTK_LIBRARIES} )

include_directories( ${CMAKE_CURRENT_SOURCE_DIR} )

# vtk_module_autoinit is needed
vtk_module_autoinit(
        TARGETS VTK_importSTL
        MODULES ${VTK_LIBRARIES}
)

```

I would greatly appreciate any guidance, thanks in advance

---

<div class="post-metadata">

### Author: ![codeling](https://discourse.vtk.org/user_avatar/discourse.vtk.org/codeling/32/3792_2.png) [@codeling](https://discourse.vtk.org/u/codeling)
#### Post date: [November 6, 2024, 2:08pm UTC](https://discourse.vtk.org/t/reading-files-from-sourcedir-rather-than-sourcedir-build-project-app-contents-macos/14829/2 "2024-11-06T14:08:14Z")

</div>

If I understood correctly, you want to read .stl files **at runtime** from a specific folder?

`include_directories` has nothing to do with where files are searched for at runtime, it only affects where the compiler searches for include files during **compile time**.

You either need to specify an absolute path to the .stl (something like `/source/test.stl`), or specify a path relative to the _current working directory_; the working directory in your case seems to be `/source/cmake-build-debug/VTK_importSTL.app/Contents/MacOS/`, so a relative path to a file `test.stl` in `/source` would be `../../../../test.stl`.

Alternatively, you could _change the working directory_ for your application; there are however many ways to run your program (via IDE, via shell, etc…), and this influences how you specify the working directory, so you’d have to tell us how you are actually running the application. I suspect you are running it directly via XCode?

You could set the working folder manually [as described here](https://stackoverflow.com/questions/13225500/how-to-change-the-working-directory-to-the-location-of-the-program) - probably a bit outdated, but it should give an idea where to look.

You should also be able to [set the XCode working directory via CMake](https://stackoverflow.com/questions/70265676/how-to-set-xcode-debugger-working-directory-with-cmake).

---

<div class="post-metadata">

### Author: ![RoyMultiC](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/r/d9b06d/32.png) [@RoyMultiC](https://discourse.vtk.org/u/RoyMultiC)
#### Post date: [November 6, 2024, 4:50pm UTC](https://discourse.vtk.org/t/reading-files-from-sourcedir-rather-than-sourcedir-build-project-app-contents-macos/14829/3 "2024-11-06T16:50:45Z")

</div>

> I have already added `include_directories(${CMAKE_CURRENT_SOURCE_DIR})` in CMakeLists.txt and included `$ContentRoot$` in the Working Directory, but neither of these worked.

Okie Dokie, I just tested adding `$ContentRoot$`(namely sourceFileDir) to the _Working Directory_ in my CLion 2024.2.2 on a **Windows** system. It worked pretty well for reading the files from the other directory.

I can speculate that this is an annoying bug due to some configuration or setting conflicts between CLion 2024.2.2 and macOS. I’ll report it to JetBrains.  
In any case, thank you for your help. Next time, I won’t suspect it’s an issue with my CMake, at least.

---

<div class="post-metadata">

### Author: ![codeling](https://discourse.vtk.org/user_avatar/discourse.vtk.org/codeling/32/3792_2.png) [@codeling](https://discourse.vtk.org/u/codeling)
#### Post date: [November 7, 2024, 6:59am UTC](https://discourse.vtk.org/t/reading-files-from-sourcedir-rather-than-sourcedir-build-project-app-contents-macos/14829/4 "2024-11-07T06:59:13Z")

</div>

> [@RoyMultiC](#):
>
> add `$ContentRoot$` to the Working Directory

Oh I had missed that one in the original post! How did you set the working directory, via IDE or via CMake? The CLion part definitely clears things up for me as well.

> In any case, thank you for your help. Next time, I won’t suspect it’s an issue with my CMake, at least.

Not sure if my answer was actually helping or more confusing 😉 - There _are_ ways to set the working directory via CMake, but they are IDE-specific; not sure if there is one for CLion!
