CMakeLists.txt 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. option(SLIC3R_ENC_CHECK "Verify encoding of source files" 1)
  2. if (IS_CROSS_COMPILE)
  3. # Force disable due to cross compilation. This fact is already printed on cli for users
  4. set(SLIC3R_ENC_CHECK OFF CACHE BOOL "" FORCE)
  5. endif ()
  6. if (SLIC3R_ENC_CHECK)
  7. add_executable(encoding-check encoding-check.cpp)
  8. # A global no-op target which depends on all encodings checks,
  9. # and on which in turn all checked targets depend.
  10. # This is done to make encoding checks the first thing to be
  11. # performed before actually compiling any sources of the checked targets
  12. # to make the check fail as early as possible.
  13. add_custom_target(global-encoding-check
  14. ALL
  15. DEPENDS encoding-check
  16. )
  17. endif()
  18. # Function that adds source file encoding check to a target
  19. # using the above encoding-check binary
  20. function(encoding_check TARGET)
  21. if (SLIC3R_ENC_CHECK)
  22. # Obtain target source files
  23. get_target_property(T_SOURCES ${TARGET} SOURCES)
  24. # Define top-level encoding check target for this ${TARGET}
  25. add_custom_target(encoding-check-${TARGET}
  26. DEPENDS encoding-check ${T_SOURCES}
  27. COMMENT "Checking source files encodings for target ${TARGET}"
  28. )
  29. # Add checking of each source file as a subcommand of encoding-check-${TARGET}
  30. foreach(file ${T_SOURCES})
  31. add_custom_command(TARGET encoding-check-${TARGET}
  32. COMMAND $<TARGET_FILE:encoding-check> ${TARGET} ${file}
  33. WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
  34. )
  35. endforeach()
  36. # This adds dependency on encoding-check-${TARGET} to ${TARET}
  37. # via the global-encoding-check
  38. add_dependencies(global-encoding-check encoding-check-${TARGET})
  39. add_dependencies(${TARGET} global-encoding-check)
  40. endif()
  41. endfunction()