Directory structure of my program
my_project
├── CMakeLists.txt
├── external
│ └── folder
│ └── schema.json
├── src
│ ├── CMakeLists.txt
│ └── main.cpp
└── unit-test
├── CMakeLists.txt
└── test.cpp
I want to define a variable in my_project/CMakeLists.txt
which points to schema.json
my_project/CMakeLists.txt
add_definitions(-DSCHEMA_PATH="${CMAKE_CURRENT_LIST_DIR}/external/folder/schema.json")
To use it in a code as below
my_project/unit-test/test.cpp
std::filesystem::path rootSchema{SCHEMA_PATH};
my_project/src/main.cpp
std::filesystem::path rootSchema{SCHEMA_PATH};
So after build I can directly run the executable and it works, since the json file is available at the path.
cmake -Bbuild -S.
cmake --build build --target all
./build/bin/runTests
How can use the same variable after make install
? Since the schema json file is not present in install directories.