EthUtils.cmake 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. #
  2. # renames the file if it is different from its destination
  3. include(CMakeParseArguments)
  4. #
  5. macro(replace_if_different SOURCE DST)
  6. set(extra_macro_args ${ARGN})
  7. set(options CREATE)
  8. set(one_value_args)
  9. set(multi_value_args)
  10. cmake_parse_arguments(REPLACE_IF_DIFFERENT "${options}" "${one_value_args}" "${multi_value_args}" "${extra_macro_args}")
  11. if (REPLACE_IF_DIFFERENT_CREATE AND (NOT (EXISTS "${DST}")))
  12. file(WRITE "${DST}" "")
  13. endif()
  14. execute_process(COMMAND ${CMAKE_COMMAND} -E compare_files "${SOURCE}" "${DST}" RESULT_VARIABLE DIFFERENT OUTPUT_QUIET ERROR_QUIET)
  15. if (DIFFERENT)
  16. execute_process(COMMAND ${CMAKE_COMMAND} -E rename "${SOURCE}" "${DST}")
  17. else()
  18. execute_process(COMMAND ${CMAKE_COMMAND} -E remove "${SOURCE}")
  19. endif()
  20. endmacro()
  21. macro(eth_add_test NAME)
  22. # parse arguments here
  23. set(commands)
  24. set(current_command "")
  25. foreach (arg ${ARGN})
  26. if (arg STREQUAL "ARGS")
  27. if (current_command)
  28. list(APPEND commands ${current_command})
  29. endif()
  30. set(current_command "")
  31. else ()
  32. set(current_command "${current_command} ${arg}")
  33. endif()
  34. endforeach(arg)
  35. list(APPEND commands ${current_command})
  36. message(STATUS "test: ${NAME} | ${commands}")
  37. # create tests
  38. set(index 0)
  39. list(LENGTH commands count)
  40. while (index LESS count)
  41. list(GET commands ${index} test_arguments)
  42. set(run_test "--run_test=${NAME}")
  43. add_test(NAME "${NAME}.${index}" COMMAND testeth ${run_test} ${test_arguments})
  44. math(EXPR index "${index} + 1")
  45. endwhile(index LESS count)
  46. # add target to run them
  47. add_custom_target("test.${NAME}"
  48. DEPENDS testeth
  49. WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
  50. COMMAND ${CMAKE_COMMAND} -DETH_TEST_NAME="${NAME}" -DCTEST_COMMAND="${CTEST_COMMAND}" -P "${ETH_SCRIPTS_DIR}/runtest.cmake"
  51. )
  52. endmacro()
  53. # Creates C resources file from files
  54. function(eth_add_resources RESOURCE_FILE OUT_FILE ETH_RES_DIR)
  55. include("${RESOURCE_FILE}")
  56. set(OUTPUT "${ETH_RESOURCE_LOCATION}/${ETH_RESOURCE_NAME}.hpp")
  57. #message(FATAL_ERROR "res:! ${ETH_RESOURCE_LOCATION}")
  58. include_directories("${ETH_RESOURCE_LOCATION}")
  59. set(${OUT_FILE} "${OUTPUT}" PARENT_SCOPE)
  60. set(filenames "${RESOURCE_FILE}")
  61. list(APPEND filenames "${ETH_SCRIPTS_DIR}/resources.cmake")
  62. foreach(resource ${ETH_RESOURCES})
  63. list(APPEND filenames "${${resource}}")
  64. endforeach(resource)
  65. add_custom_command(OUTPUT ${OUTPUT}
  66. COMMAND ${CMAKE_COMMAND} -DETH_RES_FILE="${RESOURCE_FILE}" -DETH_RES_DIR="${ETH_RES_DIR}" -P "${ETH_SCRIPTS_DIR}/resources.cmake"
  67. DEPENDS ${filenames}
  68. )
  69. endfunction()
  70. macro(eth_default_option O DEF)
  71. if (DEFINED ${O})
  72. if (${${O}})
  73. set(${O} ON)
  74. else ()
  75. set(${O} OFF)
  76. endif()
  77. else ()
  78. set(${O} ${DEF})
  79. endif()
  80. endmacro()
  81. # In Windows split repositories build we need to be checking whether or not
  82. # Debug/Release or both versions were built for the config phase to run smoothly
  83. macro(eth_check_library_link L)
  84. if (${${L}_LIBRARY} AND ${${L}_LIBRARY} EQUAL "${L}_LIBRARY-NOTFOUND")
  85. unset(${${L}_LIBRARY})
  86. endif()
  87. if (${${L}_LIBRARY_DEBUG} AND ${${L}_LIBRARY_DEBUG} EQUAL "${L}_LIBRARY_DEBUG-NOTFOUND")
  88. unset(${${L}_LIBRARY_DEBUG})
  89. endif()
  90. if (${${L}_LIBRARY} AND ${${L}_LIBRARY_DEBUG})
  91. set(${L}_LIBRARIES optimized ${${L}_LIBRARY} debug ${${L}_LIBRARY_DEBUG})
  92. elseif (${${L}_LIBRARY})
  93. set(${L}_LIBRARIES ${${L}_LIBRARY})
  94. elseif (${${L}_LIBRARY_DEBUG})
  95. set(${L}_LIBRARIES ${${L}_LIBRARY_DEBUG})
  96. endif()
  97. endmacro()