root/
├─ bin/
│ ├─ Release/
│ │ ├─ executable
│ ├─ Debug/
│ │ ├─ executable
├─ Database/
│ ├─ Generated_Databases/
│ │ ├─ XXX
This is how my project looks like (CMakeLists.txt is in /root). I want to access XXX in my project.
When I do "./Database/Generated_Databases/XXX"
on Linux (Qt Creator is the IDE I'm using) it works, but when I do the same on Windows (Visual Studio) it doesnt.
I did std::cout << std::filesystem::current_path() << '\n';
on my windows machine and the output was the current path of the executable and not the /root, which means the working directory on Windows & VS is the executable path. How can I ensure that the working directory will always be /root instead?
Here's how CMakeFiles.txt looks:
cmake_minimum_required(VERSION 3.5)
project(RubiksCubeSolver)
set(SRC "${CMAKE_SOURCE_DIR}/main.cpp"
.....
.....
add_executable(RubiksCubeSolver ${SRC})
# The relative path of the output will be /root *** DOESN'T WORK ***
set(CMAKE_BINARY_DIR ${CMAKE_SOURCE_DIR})
# I realise now that specifying the binary output location is actually irrelevant to the problem (?)
set_target_properties(RubiksCubeSolver PROPERTIES RUNTIME_OUTPUT_DIRECTORY_DEBUG "${CMAKE_BINARY_DIR}/Debug/")
set_target_properties(RubiksCubeSolver PROPERTIES RUNTIME_OUTPUT_DIRECTORY_RELEASE "${CMAKE_BINARY_DIR}/Release/")
# C++20 required for rotl/rotr
set_property(TARGET RubiksCubeSolver PROPERTY CXX_STANDARD 20)
set_property(TARGET RubiksCubeSolver PROPERTY CXX_STANDARD_REQUIRED ON)
# SDL2
# Linux
if(UNIX)
find_package(SDL2 REQUIRED)
include_directories(${SDL2_INCLUDE_DIRS})
target_link_libraries(RubiksCubeSolver ${SDL2_LIBRARIES})
endif()
# Windows
if(WIN32)
# Change to your local SDL2 folder path
set(SDL2_DIR "D:/.................") #its like this because there are issues with SDL2 and windows
find_package(SDL2 REQUIRED)
include_directories(${SDL2_INCLUDE_DIRS})
target_link_libraries(RubiksCubeSolver ${SDL2_LIBRARIES})
endif()