mirror of
https://github.com/firebase/firebase-ios-sdk
synced 2026-11-11 22:55:59 +05:45
* Rewrite cc_test to take named arguments Cut down on build file verbosity by having cc_test take SOURCES and DEPENDS. The separate invocation of target_link_libraries is no longer necessary. * Add a cc_library rule to parallel cc_test This cuts down on build file verbosity. * Automatically add OBJC_FLAGS to cc_libraries if applicable * Exclude platform-specific libraries from 'all' This is makes it possible to declare this kind of library unconditionally. Usage within a test or as a dependency will actually trigger building. * Restore secure_random_test.cc; clean-up comments
92 lines
2.2 KiB
CMake
92 lines
2.2 KiB
CMake
# Copyright 2017 Google
|
|
#
|
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
# you may not use this file except in compliance with the License.
|
|
# You may obtain a copy of the License at
|
|
#
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
#
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
# See the License for the specific language governing permissions and
|
|
# limitations under the License.
|
|
|
|
include(CMakeParseArguments)
|
|
|
|
# cc_library(
|
|
# target
|
|
# SOURCES sources...
|
|
# DEPENDS libraries...
|
|
# )
|
|
#
|
|
# Defines a new library target with the given target name, sources, and dependencies.
|
|
function(cc_library name)
|
|
set(flag EXCLUDE_FROM_ALL)
|
|
set(multi DEPENDS SOURCES)
|
|
cmake_parse_arguments(ccl "${flag}" "" "${multi}" ${ARGN})
|
|
|
|
add_library(
|
|
${name}
|
|
${ccl_SOURCES}
|
|
)
|
|
add_objc_flags(${name} ccl)
|
|
target_link_libraries(
|
|
${name}
|
|
PUBLIC
|
|
${ccl_DEPENDS}
|
|
)
|
|
|
|
if(ccl_EXCLUDE_FROM_ALL)
|
|
set_property(
|
|
TARGET ${name}
|
|
PROPERTY EXCLUDE_FROM_ALL ON
|
|
)
|
|
endif()
|
|
|
|
endfunction()
|
|
|
|
# cc_test(
|
|
# target
|
|
# SOURCES sources...
|
|
# DEPENDS libraries...
|
|
# )
|
|
#
|
|
# Defines a new test executable target with the given target name, sources, and
|
|
# dependencies. Implicitly adds DEPENDS on GTest::GTest and GTest::Main.
|
|
function(cc_test name)
|
|
set(multi DEPENDS SOURCES)
|
|
cmake_parse_arguments(cct "" "" "${multi}" ${ARGN})
|
|
|
|
list(APPEND cct_DEPENDS GTest::GTest GTest::Main)
|
|
|
|
add_executable(${name} ${cct_SOURCES})
|
|
add_objc_flags(${name} cct)
|
|
add_test(${name} ${name})
|
|
|
|
target_link_libraries(${name} ${cct_DEPENDS})
|
|
endfunction()
|
|
|
|
# add_objc_flags(target sources...)
|
|
#
|
|
# Adds OBJC_FLAGS to the compile options of the given target if any of the
|
|
# sources have filenames that indicate they are are Objective-C.
|
|
function(add_objc_flags target)
|
|
set(_has_objc OFF)
|
|
|
|
foreach(source ${ARGN})
|
|
get_filename_component(ext ${source} EXT)
|
|
if((ext STREQUAL ".m") OR (ext STREQUAL ".mm"))
|
|
set(_has_objc ON)
|
|
endif()
|
|
endforeach()
|
|
|
|
if(_has_objc)
|
|
target_compile_options(
|
|
${target}
|
|
PRIVATE
|
|
${OBJC_FLAGS}
|
|
)
|
|
endif()
|
|
endfunction()
|