AutoInclude.cmake 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. # Filename: AutoInclude.cmake
  2. # Description: This file backports the CMAKE_INCLUDE_CURRENT_DIR_IN_INTERFACE
  3. # introduced in CMake 2.8.11 to previous versions of cmake, and enables the
  4. # behavior by default.
  5. #
  6. # Emulate CMake 2.8.11's CMAKE_INCLUDE_CURRENT_DIR_IN_INTERFACE behavior if
  7. # this version doesn't define CMAKE_INCLUDE_CURRENT_DIR_IN_INTERFACE.
  8. # CFSworks's version of CMake (2.8.12) doesn't have
  9. # CMAKE_INCLUDE_CURRENT_DIR_IN_INTERFACE even though it should be supported,
  10. # hence test if it's defined (as either ON or OFF) before trying to use it.
  11. if("${CMAKE_INCLUDE_CURRENT_DIR_IN_INTERFACE}" STREQUAL "")
  12. # Replace some built-in functions in order to extend their functionality.
  13. function(add_library target)
  14. _add_library(${target} ${ARGN})
  15. set_target_properties("${target}" PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${CMAKE_CURRENT_SOURCE_DIR};${CMAKE_CURRENT_BINARY_DIR}")
  16. endfunction()
  17. function(add_executable target)
  18. _add_executable(${target} ${ARGN})
  19. set_target_properties("${target}" PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${CMAKE_CURRENT_SOURCE_DIR};${CMAKE_CURRENT_BINARY_DIR}")
  20. endfunction()
  21. function(target_link_libraries target)
  22. set(interface_dirs)
  23. get_target_property(target_interface_dirs "${target}" INTERFACE_INCLUDE_DIRECTORIES)
  24. foreach(lib ${ARGN})
  25. get_target_property(lib_interface_dirs "${lib}" INTERFACE_INCLUDE_DIRECTORIES)
  26. if(lib_interface_dirs)
  27. list(APPEND interface_dirs ${lib_interface_dirs})
  28. endif()
  29. endforeach()
  30. if(interface_dirs)
  31. list(REMOVE_DUPLICATES interface_dirs)
  32. #NB. target_include_directories is new in 2.8.8.
  33. #target_include_directories("${target}" ${interface_dirs})
  34. include_directories(${interface_dirs})
  35. # Update this target's interface inc dirs.
  36. set_target_properties("${target}" PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${target_interface_dirs};${interface_dirs}")
  37. endif()
  38. # Call to the built-in function we are overriding.
  39. _target_link_libraries(${target} ${ARGN})
  40. endfunction()
  41. else()
  42. # 2.8.11 supports this natively.
  43. set(CMAKE_INCLUDE_CURRENT_DIR_IN_INTERFACE ON)
  44. endif()
  45. set(CMAKE_INCLUDE_CURRENT_DIR ON)