You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

190 regels
7.1 KiB

  1. cmake_minimum_required (VERSION 2.8.10)
  2. # Defer enabling C and CXX languages.
  3. project (BoringSSL NONE)
  4. if(WIN32)
  5. # On Windows, prefer cl over gcc if both are available. By default most of
  6. # the CMake generators prefer gcc, even on Windows.
  7. set(CMAKE_GENERATOR_CC cl)
  8. endif()
  9. enable_language(C)
  10. enable_language(CXX)
  11. if(ANDROID)
  12. # Android-NDK CMake files reconfigure the path and so Go and Perl won't be
  13. # found. However, ninja will still find them in $PATH if we just name them.
  14. set(PERL_EXECUTABLE "perl")
  15. set(GO_EXECUTABLE "go")
  16. else()
  17. find_package(Perl REQUIRED)
  18. find_program(GO_EXECUTABLE go)
  19. endif()
  20. if (NOT GO_EXECUTABLE)
  21. message(FATAL_ERROR "Could not find Go")
  22. endif()
  23. if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
  24. set(C_CXX_FLAGS "-Wall -Werror -Wformat=2 -Wsign-compare -Wmissing-field-initializers -ggdb -fvisibility=hidden")
  25. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${C_CXX_FLAGS}")
  26. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x ${C_CXX_FLAGS}")
  27. elseif(MSVC)
  28. set(MSVC_DISABLED_WARNINGS_LIST
  29. "C4100" # 'exarg' : unreferenced formal parameter
  30. "C4127" # conditional expression is constant
  31. "C4200" # nonstandard extension used : zero-sized array in
  32. # struct/union.
  33. "C4242" # 'function' : conversion from 'int' to 'uint8_t',
  34. # possible loss of data
  35. "C4244" # 'function' : conversion from 'int' to 'uint8_t',
  36. # possible loss of data
  37. "C4245" # 'initializing' : conversion from 'long' to
  38. # 'unsigned long', signed/unsigned mismatch
  39. "C4267" # conversion from 'size_t' to 'int', possible loss of data
  40. "C4371" # layout of class may have changed from a previous version of the
  41. # compiler due to better packing of member '...'
  42. "C4388" # signed/unsigned mismatch
  43. "C4296" # '>=' : expression is always true
  44. "C4350" # behavior change: 'std::_Wrap_alloc...'
  45. "C4365" # '=' : conversion from 'size_t' to 'int',
  46. # signed/unsigned mismatch
  47. "C4389" # '!=' : signed/unsigned mismatch
  48. "C4510" # 'argument' : default constructor could not be generated
  49. "C4512" # 'argument' : assignment operator could not be generated
  50. "C4514" # 'function': unreferenced inline function has been removed
  51. "C4548" # expression before comma has no effect; expected expression with
  52. # side-effect" caused by FD_* macros.
  53. "C4610" # struct 'argument' can never be instantiated - user defined
  54. # constructor required.
  55. "C4625" # copy constructor could not be generated because a base class
  56. # copy constructor is inaccessible or deleted
  57. "C4626" # assignment operator could not be generated because a base class
  58. # assignment operator is inaccessible or deleted
  59. "C4706" # assignment within conditional expression
  60. "C4710" # 'function': function not inlined
  61. "C4711" # function 'function' selected for inline expansion
  62. "C4800" # 'int' : forcing value to bool 'true' or 'false'
  63. # (performance warning)
  64. "C4820" # 'bytes' bytes padding added after construct 'member_name'
  65. "C4996" # 'read': The POSIX name for this item is deprecated. Instead,
  66. # use the ISO C++ conformant name: _read.
  67. )
  68. string(REPLACE "C" " -wd" MSVC_DISABLED_WARNINGS_STR
  69. ${MSVC_DISABLED_WARNINGS_LIST})
  70. set(CMAKE_C_FLAGS "-Wall -WX ${MSVC_DISABLED_WARNINGS_STR}")
  71. set(CMAKE_CXX_FLAGS "-Wall -WX ${MSVC_DISABLED_WARNINGS_STR}")
  72. add_definitions(-D_HAS_EXCEPTIONS=0)
  73. add_definitions(-DWIN32_LEAN_AND_MEAN)
  74. add_definitions(-DNOMINMAX)
  75. endif()
  76. if((CMAKE_COMPILER_IS_GNUCXX AND CMAKE_C_COMPILER_VERSION VERSION_GREATER "4.7.99") OR
  77. CMAKE_CXX_COMPILER_ID MATCHES "Clang")
  78. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wshadow")
  79. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wshadow")
  80. endif()
  81. if((CMAKE_COMPILER_IS_GNUCXX AND CMAKE_C_COMPILER_VERSION VERSION_GREATER "4.8.99") OR
  82. CMAKE_CXX_COMPILER_ID MATCHES "Clang")
  83. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c11 -D_XOPEN_SOURCE=700")
  84. endif()
  85. if(FUZZ)
  86. if(!CMAKE_CXX_COMPILER_ID MATCHES "Clang")
  87. message("You need to build with Clang for fuzzing to work")
  88. endif()
  89. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=address -fsanitize-coverage=edge,indirect-calls")
  90. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address -fsanitize-coverage=edge,indirect-calls")
  91. set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_C_FLAGS} -fsanitize=address")
  92. link_directories(.)
  93. endif()
  94. add_definitions(-DBORINGSSL_IMPLEMENTATION)
  95. if (BUILD_SHARED_LIBS)
  96. add_definitions(-DBORINGSSL_SHARED_LIBRARY)
  97. # Enable position-independent code globally. This is needed because
  98. # some library targets are OBJECT libraries.
  99. set(CMAKE_POSITION_INDEPENDENT_CODE TRUE)
  100. endif()
  101. if (${CMAKE_SYSTEM_PROCESSOR} STREQUAL "x86_64")
  102. set(ARCH "x86_64")
  103. elseif (${CMAKE_SYSTEM_PROCESSOR} STREQUAL "amd64")
  104. set(ARCH "x86_64")
  105. elseif (${CMAKE_SYSTEM_PROCESSOR} STREQUAL "AMD64")
  106. # cmake reports AMD64 on Windows, but we might be building for 32-bit.
  107. if (CMAKE_CL_64)
  108. set(ARCH "x86_64")
  109. else()
  110. set(ARCH "x86")
  111. endif()
  112. elseif (${CMAKE_SYSTEM_PROCESSOR} STREQUAL "x86")
  113. set(ARCH "x86")
  114. elseif (${CMAKE_SYSTEM_PROCESSOR} STREQUAL "i386")
  115. set(ARCH "x86")
  116. elseif (${CMAKE_SYSTEM_PROCESSOR} STREQUAL "i686")
  117. set(ARCH "x86")
  118. elseif (${CMAKE_SYSTEM_PROCESSOR} STREQUAL "arm")
  119. set(ARCH "arm")
  120. elseif (${CMAKE_SYSTEM_PROCESSOR} STREQUAL "armv6")
  121. set(ARCH "arm")
  122. elseif (${CMAKE_SYSTEM_PROCESSOR} STREQUAL "armv7-a")
  123. set(ARCH "arm")
  124. elseif (${CMAKE_SYSTEM_PROCESSOR} STREQUAL "aarch64")
  125. set(ARCH "aarch64")
  126. else()
  127. message(FATAL_ERROR "Unknown processor:" ${CMAKE_SYSTEM_PROCESSOR})
  128. endif()
  129. if (ANDROID AND ${ARCH} STREQUAL "arm")
  130. # The Android-NDK CMake files somehow fail to set the -march flag for
  131. # assembly files. Without this flag, the compiler believes that it's
  132. # building for ARMv5.
  133. set(CMAKE_ASM_FLAGS "${CMAKE_ASM_FLAGS} -march=${CMAKE_SYSTEM_PROCESSOR}")
  134. endif()
  135. if (${ARCH} STREQUAL "x86" AND APPLE)
  136. # With CMake 2.8.x, ${CMAKE_SYSTEM_PROCESSOR} evalutes to i386 on OS X,
  137. # but clang defaults to 64-bit builds on OS X unless otherwise told.
  138. # Set ARCH to x86_64 so clang and CMake agree. This is fixed in CMake 3.
  139. set(ARCH "x86_64")
  140. endif()
  141. if (OPENSSL_NO_ASM)
  142. add_definitions(-DOPENSSL_NO_ASM)
  143. set(ARCH "generic")
  144. endif()
  145. # Declare a dummy target to build all unit tests. Test targets should inject
  146. # themselves as dependencies next to the target definition.
  147. add_custom_target(all_tests)
  148. add_subdirectory(crypto)
  149. add_subdirectory(ssl)
  150. add_subdirectory(ssl/test)
  151. add_subdirectory(tool)
  152. add_subdirectory(decrepit)
  153. if(FUZZ)
  154. add_subdirectory(fuzz)
  155. endif()
  156. if (NOT ${CMAKE_VERSION} VERSION_LESS "3.2")
  157. # USES_TERMINAL is only available in CMake 3.2 or later.
  158. set(MAYBE_USES_TERMINAL USES_TERMINAL)
  159. endif()
  160. add_custom_target(
  161. run_tests
  162. COMMAND ${GO_EXECUTABLE} run util/all_tests.go -build-dir
  163. ${CMAKE_BINARY_DIR}
  164. COMMAND cd ssl/test/runner
  165. COMMAND ${GO_EXECUTABLE} test -shim-path $<TARGET_FILE:bssl_shim>
  166. WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
  167. DEPENDS all_tests bssl_shim
  168. ${MAYBE_USES_TERMINAL})