Skip to content

Commit

Permalink
Replace __FILE__ with __FILENAME__ relative project path
Browse files Browse the repository at this point in the history
  • Loading branch information
philipnbbc committed Jan 13, 2023
1 parent b16ad59 commit 6aecc6f
Show file tree
Hide file tree
Showing 12 changed files with 48 additions and 6 deletions.
3 changes: 3 additions & 0 deletions apps/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,7 @@ target_link_libraries(bmxtimecode PRIVATE
bmx
)

include("${PROJECT_SOURCE_DIR}/cmake/source_filename.cmake")
set_source_filename(bmxtimecode "${CMAKE_CURRENT_LIST_DIR}" "bmx")

install(TARGETS bmxtimecode DESTINATION bin)
3 changes: 3 additions & 0 deletions apps/bmxparse/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,7 @@ target_link_libraries(bmxparse PRIVATE
bmx
)

include("${PROJECT_SOURCE_DIR}/cmake/source_filename.cmake")
set_source_filename(bmxparse "${CMAKE_CURRENT_LIST_DIR}" "bmx")

install(TARGETS bmxparse DESTINATION bin)
3 changes: 3 additions & 0 deletions apps/bmxtranswrap/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,7 @@ target_link_libraries(bmxtranswrap PRIVATE
bmx_app_writers
)

include("${PROJECT_SOURCE_DIR}/cmake/source_filename.cmake")
set_source_filename(bmxtranswrap "${CMAKE_CURRENT_LIST_DIR}" "bmx")

install(TARGETS bmxtranswrap DESTINATION bin)
3 changes: 3 additions & 0 deletions apps/mxf2raw/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,7 @@ target_link_libraries(mxf2raw PRIVATE
bmx
)

include("${PROJECT_SOURCE_DIR}/cmake/source_filename.cmake")
set_source_filename(mxf2raw "${CMAKE_CURRENT_LIST_DIR}" "bmx")

install(TARGETS mxf2raw DESTINATION bin)
3 changes: 3 additions & 0 deletions apps/raw2bmx/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,7 @@ target_link_libraries(raw2bmx PRIVATE
bmx_app_writers
)

include("${PROJECT_SOURCE_DIR}/cmake/source_filename.cmake")
set_source_filename(raw2bmx "${CMAKE_CURRENT_LIST_DIR}" "bmx")

install(TARGETS raw2bmx DESTINATION bin)
3 changes: 3 additions & 0 deletions apps/writers/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,6 @@ target_compile_definitions(bmx_app_writers PRIVATE
target_link_libraries(bmx_app_writers PUBLIC
bmx
)

include("${PROJECT_SOURCE_DIR}/cmake/source_filename.cmake")
set_source_filename(bmx_app_writers "${CMAKE_CURRENT_LIST_DIR}" "bmx")
12 changes: 12 additions & 0 deletions cmake/source_filename.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Adds the __FILENAME__=filename compile definition.
# Based on https://stackoverflow.com/a/27990434, but changed to define __FILENAME__ to be a relative project path
function(set_source_filename target sources_base_dir project_dirname)
get_target_property(source_files "${target}" SOURCES)
foreach(source_file ${source_files})
file(RELATIVE_PATH rel_path ${PROJECT_SOURCE_DIR} "${sources_base_dir}/${source_file}")
file(TO_NATIVE_PATH "${project_dirname}/${rel_path}" filename)
set_property(
SOURCE "${source_file}" APPEND
PROPERTY COMPILE_DEFINITIONS "__FILENAME__=\"${filename}\"")
endforeach()
endfunction()
10 changes: 5 additions & 5 deletions include/bmx/BMXException.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,11 @@
#include <exception>


#define BMX_EXCEPTION(err) \
do { \
bmx::log_error_nl err; \
bmx::log_error(" near %s:%d\n", __FILE__, __LINE__); \
throw BMXException err; \
#define BMX_EXCEPTION(err) \
do { \
bmx::log_error_nl err; \
bmx::log_error(" near %s:%d\n", __FILENAME__, __LINE__); \
throw BMXException err; \
} while (0)

#define BMX_CHECK(cond) \
Expand Down
3 changes: 3 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,9 @@ set_target_properties(bmx PROPERTIES
SOVERSION ${PROJECT_VERSION_MAJOR}
)

include("${PROJECT_SOURCE_DIR}/cmake/source_filename.cmake")
set_source_filename(bmx "${CMAKE_CURRENT_LIST_DIR}" "bmx")

install(TARGETS bmx
ARCHIVE DESTINATION lib
LIBRARY DESTINATION lib
Expand Down
2 changes: 1 addition & 1 deletion src/mxf_reader/MXFFileReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ static const char *RESULT_STRINGS[] =

#define THROW_RESULT(result) \
do { \
log_warn("Open error '%s' near %s:%d\n", #result, __FILE__, __LINE__); \
log_warn("Open error '%s' near %s:%d\n", #result, __FILENAME__, __LINE__); \
throw result; \
} while (0)

Expand Down
5 changes: 5 additions & 0 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,15 @@ add_executable(create_test_essence
create_test_essence.cpp
)

include("${PROJECT_SOURCE_DIR}/cmake/source_filename.cmake")
set_source_filename(create_test_essence "${CMAKE_CURRENT_LIST_DIR}" "bmx")

add_executable(file_truncate
file_truncate.cpp
)

set_source_filename(file_truncate "${CMAKE_CURRENT_LIST_DIR}" "bmx")

add_subdirectory(ard_zdf_hdf)
add_subdirectory(as02)
add_subdirectory(as10)
Expand Down
4 changes: 4 additions & 0 deletions tools/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,9 @@ foreach(tool_source ${tool_sources})
add_executable(${tool_target}
${tool_source}
)

include("${PROJECT_SOURCE_DIR}/cmake/source_filename.cmake")
set_source_filename(${tool_target} "${CMAKE_CURRENT_LIST_DIR}" "bmx")

install(TARGETS ${tool_target} DESTINATION bin)
endforeach()

0 comments on commit 6aecc6f

Please sign in to comment.