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.
 
 
 
 
 
 

180 lines
6.8 KiB

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