Align on a single CMake style.

We currently write a mix of "if (FOO)" and "if(FOO)". While the former looks
more like a usual language, CMake believes everything, even "if" and "else", is
just a really really funny function call (a "command").

We should pick something for consistency. Upstream CMake writes "if(FOO)", so
go with that one.

Change-Id: I67e0eb650a52670110b417312a362c9f161c8721
Reviewed-on: https://boringssl-review.googlesource.com/30807
Reviewed-by: Adam Langley <agl@google.com>
This commit is contained in:
David Benjamin 2018-08-10 10:30:55 -05:00 committed by Adam Langley
parent ddedf6d455
commit e6fd125d31
11 changed files with 61 additions and 61 deletions

View File

@ -1,4 +1,4 @@
cmake_minimum_required (VERSION 2.8.11) cmake_minimum_required(VERSION 2.8.11)
# Report AppleClang separately from Clang. Their version numbers are different. # Report AppleClang separately from Clang. Their version numbers are different.
# https://cmake.org/cmake/help/v3.0/policy/CMP0025.html # https://cmake.org/cmake/help/v3.0/policy/CMP0025.html
@ -7,7 +7,7 @@ if(POLICY CMP0025)
endif() endif()
# Defer enabling C and CXX languages. # Defer enabling C and CXX languages.
project (BoringSSL NONE) project(BoringSSL NONE)
if(WIN32) if(WIN32)
# On Windows, prefer cl over gcc if both are available. By default most of # On Windows, prefer cl over gcc if both are available. By default most of
@ -34,14 +34,14 @@ else()
find_program(GO_EXECUTABLE go) find_program(GO_EXECUTABLE go)
endif() endif()
if (NOT GO_EXECUTABLE) if(NOT GO_EXECUTABLE)
message(FATAL_ERROR "Could not find Go") message(FATAL_ERROR "Could not find Go")
endif() endif()
if (USE_CUSTOM_LIBCXX) if(USE_CUSTOM_LIBCXX)
set(BORINGSSL_ALLOW_CXX_RUNTIME 1) set(BORINGSSL_ALLOW_CXX_RUNTIME 1)
endif() endif()
if (BORINGSSL_ALLOW_CXX_RUNTIME) if(BORINGSSL_ALLOW_CXX_RUNTIME)
add_definitions(-DBORINGSSL_ALLOW_CXX_RUNTIME) add_definitions(-DBORINGSSL_ALLOW_CXX_RUNTIME)
endif() endif()
@ -189,7 +189,7 @@ if((CMAKE_COMPILER_IS_GNUCXX AND CMAKE_C_COMPILER_VERSION VERSION_GREATER "4.7.9
endif() endif()
if(CMAKE_COMPILER_IS_GNUCXX) if(CMAKE_COMPILER_IS_GNUCXX)
if ((CMAKE_C_COMPILER_VERSION VERSION_GREATER "4.8.99") OR CLANG) if((CMAKE_C_COMPILER_VERSION VERSION_GREATER "4.8.99") OR CLANG)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c11") set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c11")
else() else()
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c99") set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c99")
@ -222,19 +222,19 @@ endif()
add_definitions(-DBORINGSSL_IMPLEMENTATION) add_definitions(-DBORINGSSL_IMPLEMENTATION)
if (BUILD_SHARED_LIBS) if(BUILD_SHARED_LIBS)
add_definitions(-DBORINGSSL_SHARED_LIBRARY) add_definitions(-DBORINGSSL_SHARED_LIBRARY)
# Enable position-independent code globally. This is needed because # Enable position-independent code globally. This is needed because
# some library targets are OBJECT libraries. # some library targets are OBJECT libraries.
set(CMAKE_POSITION_INDEPENDENT_CODE TRUE) set(CMAKE_POSITION_INDEPENDENT_CODE TRUE)
endif() endif()
if (MSAN) if(MSAN)
if(NOT CLANG) if(NOT CLANG)
message(FATAL_ERROR "Cannot enable MSAN unless using Clang") message(FATAL_ERROR "Cannot enable MSAN unless using Clang")
endif() endif()
if (ASAN) if(ASAN)
message(FATAL_ERROR "ASAN and MSAN are mutually exclusive") message(FATAL_ERROR "ASAN and MSAN are mutually exclusive")
endif() endif()
@ -243,7 +243,7 @@ if (MSAN)
set(OPENSSL_NO_ASM "1") set(OPENSSL_NO_ASM "1")
endif() endif()
if (ASAN) if(ASAN)
if(NOT CLANG) if(NOT CLANG)
message(FATAL_ERROR "Cannot enable ASAN unless using Clang") message(FATAL_ERROR "Cannot enable ASAN unless using Clang")
endif() endif()
@ -281,7 +281,7 @@ if(TSAN)
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fsanitize=thread") set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fsanitize=thread")
endif() endif()
if (GCOV) if(GCOV)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fprofile-arcs -ftest-coverage") set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fprofile-arcs -ftest-coverage")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fprofile-arcs -ftest-coverage") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fprofile-arcs -ftest-coverage")
endif() endif()
@ -307,65 +307,65 @@ endif()
# the source files rather than the build. This does not work for our assembly # the source files rather than the build. This does not work for our assembly
# files, so we fix CMAKE_SYSTEM_PROCESSOR and only support single-architecture # files, so we fix CMAKE_SYSTEM_PROCESSOR and only support single-architecture
# builds. # builds.
if (NOT OPENSSL_NO_ASM AND CMAKE_OSX_ARCHITECTURES) if(NOT OPENSSL_NO_ASM AND CMAKE_OSX_ARCHITECTURES)
list(LENGTH CMAKE_OSX_ARCHITECTURES NUM_ARCHES) list(LENGTH CMAKE_OSX_ARCHITECTURES NUM_ARCHES)
if (NOT ${NUM_ARCHES} EQUAL 1) if(NOT ${NUM_ARCHES} EQUAL 1)
message(FATAL_ERROR "Universal binaries not supported.") message(FATAL_ERROR "Universal binaries not supported.")
endif() endif()
list(GET CMAKE_OSX_ARCHITECTURES 0 CMAKE_SYSTEM_PROCESSOR) list(GET CMAKE_OSX_ARCHITECTURES 0 CMAKE_SYSTEM_PROCESSOR)
endif() endif()
if (OPENSSL_NO_ASM) if(OPENSSL_NO_ASM)
add_definitions(-DOPENSSL_NO_ASM) add_definitions(-DOPENSSL_NO_ASM)
set(ARCH "generic") set(ARCH "generic")
elseif (${CMAKE_SYSTEM_PROCESSOR} STREQUAL "x86_64") elseif(${CMAKE_SYSTEM_PROCESSOR} STREQUAL "x86_64")
set(ARCH "x86_64") set(ARCH "x86_64")
elseif (${CMAKE_SYSTEM_PROCESSOR} STREQUAL "amd64") elseif(${CMAKE_SYSTEM_PROCESSOR} STREQUAL "amd64")
set(ARCH "x86_64") set(ARCH "x86_64")
elseif (${CMAKE_SYSTEM_PROCESSOR} STREQUAL "AMD64") elseif(${CMAKE_SYSTEM_PROCESSOR} STREQUAL "AMD64")
# cmake reports AMD64 on Windows, but we might be building for 32-bit. # cmake reports AMD64 on Windows, but we might be building for 32-bit.
if (CMAKE_CL_64) if(CMAKE_CL_64)
set(ARCH "x86_64") set(ARCH "x86_64")
else() else()
set(ARCH "x86") set(ARCH "x86")
endif() endif()
elseif (${CMAKE_SYSTEM_PROCESSOR} STREQUAL "x86") elseif(${CMAKE_SYSTEM_PROCESSOR} STREQUAL "x86")
set(ARCH "x86") set(ARCH "x86")
elseif (${CMAKE_SYSTEM_PROCESSOR} STREQUAL "i386") elseif(${CMAKE_SYSTEM_PROCESSOR} STREQUAL "i386")
set(ARCH "x86") set(ARCH "x86")
elseif (${CMAKE_SYSTEM_PROCESSOR} STREQUAL "i686") elseif(${CMAKE_SYSTEM_PROCESSOR} STREQUAL "i686")
set(ARCH "x86") set(ARCH "x86")
elseif (${CMAKE_SYSTEM_PROCESSOR} STREQUAL "aarch64") elseif(${CMAKE_SYSTEM_PROCESSOR} STREQUAL "aarch64")
set(ARCH "aarch64") set(ARCH "aarch64")
elseif (${CMAKE_SYSTEM_PROCESSOR} STREQUAL "arm64") elseif(${CMAKE_SYSTEM_PROCESSOR} STREQUAL "arm64")
set(ARCH "aarch64") set(ARCH "aarch64")
elseif (${CMAKE_SYSTEM_PROCESSOR} MATCHES "^arm*") elseif(${CMAKE_SYSTEM_PROCESSOR} MATCHES "^arm*")
set(ARCH "arm") set(ARCH "arm")
elseif (${CMAKE_SYSTEM_PROCESSOR} STREQUAL "mips") elseif(${CMAKE_SYSTEM_PROCESSOR} STREQUAL "mips")
# Just to avoid the unknown processor error. # Just to avoid the unknown processor error.
set(ARCH "generic") set(ARCH "generic")
elseif (${CMAKE_SYSTEM_PROCESSOR} STREQUAL "ppc64le") elseif(${CMAKE_SYSTEM_PROCESSOR} STREQUAL "ppc64le")
set(ARCH "ppc64le") set(ARCH "ppc64le")
else() else()
message(FATAL_ERROR "Unknown processor:" ${CMAKE_SYSTEM_PROCESSOR}) message(FATAL_ERROR "Unknown processor:" ${CMAKE_SYSTEM_PROCESSOR})
endif() endif()
if (ANDROID AND NOT ANDROID_NDK_REVISION AND ${ARCH} STREQUAL "arm") if(ANDROID AND NOT ANDROID_NDK_REVISION AND ${ARCH} STREQUAL "arm")
# The third-party Android-NDK CMake files somehow fail to set the -march flag # The third-party Android-NDK CMake files somehow fail to set the -march flag
# for assembly files. Without this flag, the compiler believes that it's # for assembly files. Without this flag, the compiler believes that it's
# building for ARMv5. # building for ARMv5.
set(CMAKE_ASM_FLAGS "-march=${CMAKE_SYSTEM_PROCESSOR} ${CMAKE_ASM_FLAGS}") set(CMAKE_ASM_FLAGS "-march=${CMAKE_SYSTEM_PROCESSOR} ${CMAKE_ASM_FLAGS}")
endif() endif()
if (${ARCH} STREQUAL "x86" AND APPLE AND ${CMAKE_VERSION} VERSION_LESS "3.0") if(${ARCH} STREQUAL "x86" AND APPLE AND ${CMAKE_VERSION} VERSION_LESS "3.0")
# With CMake 2.8.x, ${CMAKE_SYSTEM_PROCESSOR} evalutes to i386 on OS X, # With CMake 2.8.x, ${CMAKE_SYSTEM_PROCESSOR} evalutes to i386 on OS X,
# but clang defaults to 64-bit builds on OS X unless otherwise told. # but clang defaults to 64-bit builds on OS X unless otherwise told.
# Set ARCH to x86_64 so clang and CMake agree. This is fixed in CMake 3. # Set ARCH to x86_64 so clang and CMake agree. This is fixed in CMake 3.
set(ARCH "x86_64") set(ARCH "x86_64")
endif() endif()
if (USE_CUSTOM_LIBCXX) if(USE_CUSTOM_LIBCXX)
if (NOT CLANG) if(NOT CLANG)
message(FATAL_ERROR "USE_CUSTOM_LIBCXX only supported with Clang") message(FATAL_ERROR "USE_CUSTOM_LIBCXX only supported with Clang")
endif() endif()
@ -390,7 +390,7 @@ if (USE_CUSTOM_LIBCXX)
list(REMOVE_ITEM LIBCXXABI_SOURCES "trunk/src/cxa_noexception.cpp") list(REMOVE_ITEM LIBCXXABI_SOURCES "trunk/src/cxa_noexception.cpp")
# libc++ also defines new and delete. # libc++ also defines new and delete.
list(REMOVE_ITEM LIBCXXABI_SOURCES "trunk/src/stdlib_new_delete.cpp") list(REMOVE_ITEM LIBCXXABI_SOURCES "trunk/src/stdlib_new_delete.cpp")
if (TSAN) if(TSAN)
# ThreadSanitizer tries to intercept these symbols. Skip them to avoid # ThreadSanitizer tries to intercept these symbols. Skip them to avoid
# symbol conflicts. # symbol conflicts.
list(REMOVE_ITEM LIBCXXABI_SOURCES "trunk/src/cxa_guard.cpp") list(REMOVE_ITEM LIBCXXABI_SOURCES "trunk/src/cxa_guard.cpp")
@ -404,7 +404,7 @@ if (USE_CUSTOM_LIBCXX)
set_target_properties(libcxxabi PROPERTIES COMPILE_FLAGS "-Wno-missing-prototypes -Wno-implicit-fallthrough") set_target_properties(libcxxabi PROPERTIES COMPILE_FLAGS "-Wno-missing-prototypes -Wno-implicit-fallthrough")
add_library(libcxx ${LIBCXX_SOURCES}) add_library(libcxx ${LIBCXX_SOURCES})
if (ASAN OR MSAN OR TSAN) if(ASAN OR MSAN OR TSAN)
# Sanitizers try to intercept new and delete. # Sanitizers try to intercept new and delete.
target_compile_definitions( target_compile_definitions(
libcxx PRIVATE libcxx PRIVATE
@ -459,7 +459,7 @@ if(FUZZ)
add_subdirectory(fuzz) add_subdirectory(fuzz)
endif() endif()
if (NOT ${CMAKE_VERSION} VERSION_LESS "3.2") if(NOT ${CMAKE_VERSION} VERSION_LESS "3.2")
# USES_TERMINAL is only available in CMake 3.2 or later. # USES_TERMINAL is only available in CMake 3.2 or later.
set(MAYBE_USES_TERMINAL USES_TERMINAL) set(MAYBE_USES_TERMINAL USES_TERMINAL)
endif() endif()

View File

@ -2,27 +2,27 @@ include_directories(../include)
if(NOT OPENSSL_NO_ASM) if(NOT OPENSSL_NO_ASM)
if(UNIX) if(UNIX)
if (${ARCH} STREQUAL "aarch64") if(${ARCH} STREQUAL "aarch64")
# The "armx" Perl scripts look for "64" in the style argument # The "armx" Perl scripts look for "64" in the style argument
# in order to decide whether to generate 32- or 64-bit asm. # in order to decide whether to generate 32- or 64-bit asm.
if (APPLE) if(APPLE)
set(PERLASM_STYLE ios64) set(PERLASM_STYLE ios64)
else() else()
set(PERLASM_STYLE linux64) set(PERLASM_STYLE linux64)
endif() endif()
elseif (${ARCH} STREQUAL "arm") elseif(${ARCH} STREQUAL "arm")
if (APPLE) if(APPLE)
set(PERLASM_STYLE ios32) set(PERLASM_STYLE ios32)
else() else()
set(PERLASM_STYLE linux32) set(PERLASM_STYLE linux32)
endif() endif()
elseif (${ARCH} STREQUAL "ppc64le") elseif(${ARCH} STREQUAL "ppc64le")
set(PERLASM_STYLE linux64le) set(PERLASM_STYLE linux64le)
else() else()
if (${ARCH} STREQUAL "x86") if(${ARCH} STREQUAL "x86")
set(PERLASM_FLAGS "-fPIC -DOPENSSL_IA32_SSE2") set(PERLASM_FLAGS "-fPIC -DOPENSSL_IA32_SSE2")
endif() endif()
if (APPLE) if(APPLE)
set(PERLASM_STYLE macosx) set(PERLASM_STYLE macosx)
else() else()
set(PERLASM_STYLE elf) set(PERLASM_STYLE elf)
@ -38,8 +38,8 @@ if(NOT OPENSSL_NO_ASM)
endif() endif()
# CMake does not add -isysroot and -arch flags to assembly. # CMake does not add -isysroot and -arch flags to assembly.
if (APPLE) if(APPLE)
if (CMAKE_OSX_SYSROOT) if(CMAKE_OSX_SYSROOT)
set(CMAKE_ASM_FLAGS "${CMAKE_ASM_FLAGS} -isysroot \"${CMAKE_OSX_SYSROOT}\"") set(CMAKE_ASM_FLAGS "${CMAKE_ASM_FLAGS} -isysroot \"${CMAKE_OSX_SYSROOT}\"")
endif() endif()
foreach(arch ${CMAKE_OSX_ARCHITECTURES}) foreach(arch ${CMAKE_OSX_ARCHITECTURES})
@ -47,7 +47,7 @@ if(NOT OPENSSL_NO_ASM)
endforeach() endforeach()
endif() endif()
else() else()
if (${ARCH} STREQUAL "x86_64") if(${ARCH} STREQUAL "x86_64")
set(PERLASM_STYLE nasm) set(PERLASM_STYLE nasm)
else() else()
set(PERLASM_STYLE win32n) set(PERLASM_STYLE win32n)
@ -281,7 +281,7 @@ add_executable(
) )
target_link_libraries(crypto_test crypto boringssl_gtest) target_link_libraries(crypto_test crypto boringssl_gtest)
if (WIN32) if(WIN32)
target_link_libraries(crypto_test ws2_32) target_link_libraries(crypto_test ws2_32)
endif() endif()
add_dependencies(all_tests crypto_test) add_dependencies(all_tests crypto_test)

View File

@ -1,6 +1,6 @@
include_directories(../../include) include_directories(../../include)
if (${ARCH} STREQUAL "arm") if(${ARCH} STREQUAL "arm")
set( set(
CHACHA_ARCH_SOURCES CHACHA_ARCH_SOURCES
@ -8,7 +8,7 @@ if (${ARCH} STREQUAL "arm")
) )
endif() endif()
if (${ARCH} STREQUAL "aarch64") if(${ARCH} STREQUAL "aarch64")
set( set(
CHACHA_ARCH_SOURCES CHACHA_ARCH_SOURCES
@ -16,7 +16,7 @@ if (${ARCH} STREQUAL "aarch64")
) )
endif() endif()
if (${ARCH} STREQUAL "x86") if(${ARCH} STREQUAL "x86")
set( set(
CHACHA_ARCH_SOURCES CHACHA_ARCH_SOURCES
@ -24,7 +24,7 @@ if (${ARCH} STREQUAL "x86")
) )
endif() endif()
if (${ARCH} STREQUAL "x86_64") if(${ARCH} STREQUAL "x86_64")
set( set(
CHACHA_ARCH_SOURCES CHACHA_ARCH_SOURCES

View File

@ -1,6 +1,6 @@
include_directories(../../include) include_directories(../../include)
if (${ARCH} STREQUAL "x86_64") if(${ARCH} STREQUAL "x86_64")
set( set(
CIPHER_ARCH_SOURCES CIPHER_ARCH_SOURCES

View File

@ -1,6 +1,6 @@
include_directories(../../include) include_directories(../../include)
if (${ARCH} STREQUAL "arm") if(${ARCH} STREQUAL "arm")
set( set(
CURVE25519_ARCH_SOURCES CURVE25519_ARCH_SOURCES

View File

@ -1,6 +1,6 @@
include_directories(../../include) include_directories(../../include)
if (${ARCH} STREQUAL "x86_64") if(${ARCH} STREQUAL "x86_64")
set( set(
BCM_ASM_SOURCES BCM_ASM_SOURCES
@ -22,7 +22,7 @@ if (${ARCH} STREQUAL "x86_64")
) )
endif() endif()
if (${ARCH} STREQUAL "x86") if(${ARCH} STREQUAL "x86")
set( set(
BCM_ASM_SOURCES BCM_ASM_SOURCES
@ -40,7 +40,7 @@ if (${ARCH} STREQUAL "x86")
) )
endif() endif()
if (${ARCH} STREQUAL "arm") if(${ARCH} STREQUAL "arm")
set( set(
BCM_ASM_SOURCES BCM_ASM_SOURCES
@ -56,7 +56,7 @@ if (${ARCH} STREQUAL "arm")
) )
endif() endif()
if (${ARCH} STREQUAL "aarch64") if(${ARCH} STREQUAL "aarch64")
set( set(
BCM_ASM_SOURCES BCM_ASM_SOURCES
@ -69,7 +69,7 @@ if (${ARCH} STREQUAL "aarch64")
) )
endif() endif()
if (${ARCH} STREQUAL "ppc64le") if(${ARCH} STREQUAL "ppc64le")
set( set(
BCM_ASM_SOURCES BCM_ASM_SOURCES

View File

@ -1,6 +1,6 @@
include_directories(../../include) include_directories(../../include)
if (${ARCH} STREQUAL "arm") if(${ARCH} STREQUAL "arm")
set( set(
POLY1305_ARCH_SOURCES POLY1305_ARCH_SOURCES

View File

@ -49,7 +49,7 @@ add_executable(
) )
target_link_libraries(decrepit_test crypto decrepit boringssl_gtest) target_link_libraries(decrepit_test crypto decrepit boringssl_gtest)
if (WIN32) if(WIN32)
target_link_libraries(decrepit_test ws2_32) target_link_libraries(decrepit_test ws2_32)
endif() endif()
add_dependencies(all_tests decrepit_test) add_dependencies(all_tests decrepit_test)

View File

@ -1,6 +1,6 @@
include_directories(../include) include_directories(../include)
if (FIPS) if(FIPS)
add_executable( add_executable(
cavp cavp

View File

@ -54,7 +54,7 @@ add_executable(
) )
target_link_libraries(ssl_test ssl crypto boringssl_gtest) target_link_libraries(ssl_test ssl crypto boringssl_gtest)
if (WIN32) if(WIN32)
target_link_libraries(ssl_test ws2_32) target_link_libraries(ssl_test ws2_32)
endif() endif()
add_dependencies(all_tests ssl_test) add_dependencies(all_tests ssl_test)

View File

@ -20,11 +20,11 @@ add_executable(
transport_common.cc transport_common.cc
) )
if (APPLE OR WIN32 OR ANDROID) if(APPLE OR WIN32 OR ANDROID)
target_link_libraries(bssl ssl crypto) target_link_libraries(bssl ssl crypto)
else() else()
find_library(FOUND_LIBRT rt) find_library(FOUND_LIBRT rt)
if (FOUND_LIBRT) if(FOUND_LIBRT)
target_link_libraries(bssl ssl crypto -lrt) target_link_libraries(bssl ssl crypto -lrt)
else() else()
target_link_libraries(bssl ssl crypto) target_link_libraries(bssl ssl crypto)