cmake.patch 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. diff --git a/CMakeLists.txt b/CMakeLists.txt
  2. index 9898f42..788d371 100644
  3. --- a/CMakeLists.txt
  4. +++ b/CMakeLists.txt
  5. @@ -43,41 +43,52 @@ option(ZYDIS_FUZZ_AFL_FAST
  6. option(ZYDIS_LIBFUZZER
  7. "Enables LLVM libfuzzer mode and reduces prints in ZydisFuzzIn"
  8. OFF)
  9. -set(ZYDIS_ZYCORE_PATH
  10. - "${CMAKE_CURRENT_LIST_DIR}/dependencies/zycore"
  11. - CACHE
  12. - PATH
  13. - "The path to look for Zycore")
  14. # =============================================================================================== #
  15. -# Dependencies #
  16. +# Exported functions #
  17. # =============================================================================================== #
  18. -# Try to initialize the Zycore submodule using Git
  19. -if (NOT EXISTS "${ZYDIS_ZYCORE_PATH}/CMakeLists.txt" AND
  20. - "${ZYDIS_ZYCORE_PATH}" STREQUAL "${CMAKE_CURRENT_LIST_DIR}/dependencies/zycore")
  21. - find_package(Git QUIET)
  22. - if(GIT_FOUND AND EXISTS "${PROJECT_SOURCE_DIR}/.git")
  23. - execute_process(
  24. - COMMAND ${GIT_EXECUTABLE} submodule update --init --recursive
  25. - WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
  26. - )
  27. - endif()
  28. +function (zyan_set_common_flags target)
  29. +if (NOT MSVC)
  30. + target_compile_options("${target}" PRIVATE "-std=c99")
  31. endif ()
  32. -if (NOT EXISTS "${ZYDIS_ZYCORE_PATH}/CMakeLists.txt")
  33. - message(
  34. - FATAL_ERROR
  35. - "Can't find zycore submodule. Please make sure to clone the repo recursively.\n"
  36. - "You can fix this by running\n"
  37. - " git submodule update --init\n"
  38. - "or by cloning using\n"
  39. - " git clone --recursive <url>\n"
  40. - "Alternatively, you can manually clone zycore to some path and set ZYDIS_ZYCORE_PATH."
  41. - )
  42. +if (ZYAN_DEV_MODE)
  43. + # If in developer mode, be pedantic.
  44. + if (MSVC)
  45. + target_compile_options("${target}" PUBLIC "/WX" "/W4")
  46. + else ()
  47. + target_compile_options("${target}" PUBLIC "-Wall" "-pedantic" "-Wextra" "-Werror")
  48. + endif ()
  49. +endif ()
  50. +endfunction ()
  51. +
  52. +function (zyan_set_source_group target)
  53. +if (ZYAN_DEV_MODE)
  54. + if (((CMAKE_MAJOR_VERSION GREATER 3) OR (CMAKE_MAJOR_VERSION EQUAL 3)) AND
  55. + ((CMAKE_MINOR_VERSION GREATER 8) OR (CMAKE_MINOR_VERSION EQUAL 8)))
  56. + # Mirror directory structure in project files
  57. + get_property("TARGET_SOURCE_FILES" TARGET "${target}" PROPERTY SOURCES)
  58. + source_group(TREE "${CMAKE_CURRENT_LIST_DIR}" FILES ${TARGET_SOURCE_FILES})
  59. + endif ()
  60. endif ()
  61. +endfunction ()
  62. +
  63. +function (zyan_maybe_enable_wpo target)
  64. +if (ZYAN_WHOLE_PROGRAM_OPTIMIZATION AND MSVC)
  65. + set_target_properties("${target}" PROPERTIES COMPILE_FLAGS "/GL")
  66. + set_target_properties("${target}" PROPERTIES LINK_FLAGS_RELEASE "/LTCG")
  67. +endif ()
  68. +endfunction ()
  69. +
  70. +function (zyan_maybe_enable_wpo_for_lib target)
  71. +if (ZYAN_WHOLE_PROGRAM_OPTIMIZATION AND MSVC)
  72. + set_target_properties("${target}" PROPERTIES COMPILE_FLAGS "/GL")
  73. + set_target_properties("${target}" PROPERTIES LINK_FLAGS_RELEASE "/LTCG")
  74. + set_target_properties("${target}" PROPERTIES STATIC_LIBRARY_FLAGS_RELEASE "/LTCG")
  75. +endif ()
  76. +endfunction ()
  77. -add_subdirectory(${ZYDIS_ZYCORE_PATH} "zycore" EXCLUDE_FROM_ALL)
  78. # =============================================================================================== #
  79. # Library configuration #