CMakeLists.txt 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. cmake_minimum_required(VERSION 3.5)
  2. ################### Variables. ####################
  3. # Change if you want modify path or other values. #
  4. ###################################################
  5. set(PROJECT_NAME BeefFuzz)
  6. # Output Variables
  7. set(OUTPUT_DEBUG Debug/bin)
  8. set(OUTPUT_RELEASE Release/bin)
  9. ############## CMake Project ################
  10. # The main options of project #
  11. #############################################
  12. project(${PROJECT_NAME} CXX C)
  13. set (CMAKE_CXX_STANDARD 14)
  14. add_definitions(-D_GLIBCXX_USE_CXX11_ABI=1)
  15. #set(CMAKE_POSITION_INDEPENDENT_CODE ON)
  16. # Define Release by default.
  17. if(NOT CMAKE_BUILD_TYPE)
  18. set(CMAKE_BUILD_TYPE "Debug")
  19. message(STATUS "Build type not specified: Use Debug by default.")
  20. endif(NOT CMAKE_BUILD_TYPE)
  21. # Definition of Macros
  22. add_definitions(
  23. -DIDEHELPER_EXPORTS
  24. -DBFSYSLIB_DYNAMIC
  25. -DUNICODE
  26. -D_UNICODE
  27. -DBF_NO_FBX
  28. -DFT2_BUILD_LIBRARY
  29. -DBFSYSLIB_DYNAMIC
  30. )
  31. if (${APPLE})
  32. include_directories(
  33. .
  34. ../
  35. ../BeefySysLib/
  36. ../BeefySysLib/third_party
  37. ../BeefySysLib/third_party/freetype/include
  38. ../IDEHelper
  39. ../BeefySysLib/platform/osx
  40. )
  41. else()
  42. include_directories(
  43. .
  44. ../
  45. ../BeefySysLib/
  46. ../BeefySysLib/third_party
  47. ../BeefySysLib/third_party/freetype/include
  48. ../IDEHelper
  49. ../BeefySysLib/platform/linux
  50. )
  51. endif()
  52. ############## Artefacts Output #################
  53. # Defines outputs , depending Debug or Release. #
  54. #################################################
  55. if(CMAKE_BUILD_TYPE STREQUAL "Debug")
  56. add_definitions(
  57. -D_DEBUG
  58. )
  59. set(EXECUTABLE_OUTPUT_PATH "${CMAKE_BINARY_DIR}/${OUTPUT_DEBUG}")
  60. else()
  61. set(EXECUTABLE_OUTPUT_PATH "${CMAKE_BINARY_DIR}/${OUTPUT_RELEASE}")
  62. endif()
  63. ################### Dependencies ##################
  64. # Add Dependencies to project. #
  65. ###################################################
  66. option(BUILD_DEPENDS
  67. "Build other CMake project."
  68. ON
  69. )
  70. # Dependencies : disable BUILD_DEPENDS to link with lib already build.
  71. if(BUILD_DEPENDS)
  72. else()
  73. endif()
  74. ################# Flags ################
  75. # Defines Flags for Windows and Linux. #
  76. ########################################
  77. if(MSVC)
  78. set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /W3 /MD /MDd /Od /EHsc")
  79. set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /W3 /GL /Od /Oi /Gy /EHsc")
  80. else()
  81. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17 -Wno-multichar -Wno-invalid-offsetof -fno-omit-frame-pointer -fsanitize=fuzzer")
  82. if (BF_ENABLE_ASAN)
  83. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address")
  84. endif()
  85. endif()
  86. ################ Files ################
  87. # -- Add files to project. -- #
  88. #######################################
  89. file(GLOB SRC_FILES
  90. BeefFuzz.cpp
  91. FuzzApp.cpp
  92. )
  93. # Add executable to build.
  94. add_executable(${PROJECT_NAME}
  95. ${SRC_FILES}
  96. )
  97. find_package(LLVM 13 CONFIG COMPONENTS)
  98. if (LLVM_FOUND)
  99. message(STATUS "Found LLVM ${LLVM_PACKAGE_VERSION}")
  100. message(STATUS "Using LLVMConfig.cmake in: ${LLVM_DIR}")
  101. include_directories(${LLVM_INCLUDE_DIRS})
  102. add_definitions(${LLVM_DEFINITIONS})
  103. set(TARGET_LIBS_OS "-lLLVM-13")
  104. else()
  105. include_directories(
  106. ../extern/llvm-project_13_0_1/llvm/include
  107. ../extern/llvm-project_13_0_1/llvm/lib/Target
  108. )
  109. if(CMAKE_BUILD_TYPE STREQUAL "Debug")
  110. include_directories(
  111. ../extern/llvm_linux_13_0_1/include
  112. ../extern/llvm_linux_13_0_1/lib/Target/X86
  113. )
  114. set(LLVM_LIB "${CMAKE_CURRENT_SOURCE_DIR}/../extern/llvm_linux_13_0_1/lib")
  115. else()
  116. include_directories(
  117. ../extern/llvm_linux_rel_13_0_1/include
  118. ../extern/llvm_linux_rel_13_0_1/lib/Target/X86
  119. )
  120. set(LLVM_LIB "${CMAKE_CURRENT_SOURCE_DIR}/../extern/llvm_linux_rel_13_0_1/lib")
  121. endif()
  122. execute_process(
  123. COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/../extern/llvm_linux_13_0_1/bin/llvm-config --system-libs --link-static
  124. OUTPUT_VARIABLE LLVM_SYSTEM_LIBS
  125. OUTPUT_STRIP_TRAILING_WHITESPACE
  126. RESULT_VARIABLE EXEC_RESULT
  127. )
  128. if (EXEC_RESULT AND NOT EXEC_RESULT EQUAL 0)
  129. if (EXEC_RESULT MATCHES "^[0-9]+$")
  130. message(FATAL_ERROR "llvm-config exited with code ${EXEC_RESULT}.")
  131. else()
  132. message(FATAL_ERROR "llvm-config couldn't be executed: ${EXEC_RESULT}")
  133. endif()
  134. endif()
  135. message(STATUS "Found LLVM 13.0.1 (local build)")
  136. endif()
  137. if (${APPLE})
  138. set(TARGET_LIBS_OS "")
  139. else()
  140. #set(TARGET_LIBS_OS "curses")
  141. #set(TARGET_LIBS_OS "-Xlinker --no-demangle -v")
  142. set(TARGET_LIBS_OS "${LLVM_SYSTEM_LIBS}")
  143. endif()
  144. # Link with other dependencies.
  145. if(MSVC)
  146. target_link_libraries(${PROJECT_NAME} BeefySysLib IDEHelper kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib)
  147. else()
  148. target_link_libraries(${PROJECT_NAME} BeefySysLib
  149. IDEHelper
  150. ${TARGET_LIBS_OS}
  151. )
  152. endif()