cmake/Modules/DefineRelativeFilePaths.cmake
raw| 1 | # Source: https://stackoverflow.com/questions/237542/getting-base-name-of-the-source-file-at-compile-time |
| 2 | |
| 3 | function (cmake_define_relative_file_paths SOURCES) |
| 4 | foreach (SOURCE IN LISTS SOURCES) |
| 5 | file ( |
| 6 | RELATIVE_PATH RELATIVE_SOURCE_PATH |
| 7 | ${PROJECT_SOURCE_DIR} ${SOURCE} |
| 8 | ) |
| 9 | |
| 10 | set_source_files_properties ( |
| 11 | ${SOURCE} PROPERTIES |
| 12 | COMPILE_DEFINITIONS FILENAME="${RELATIVE_SOURCE_PATH}" |
| 13 | ) |
| 14 | endforeach () |
| 15 | endfunction () |