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.
 
 
 
 
 
 

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