Alexander Dorokhine | 49410d1 | 2020-03-02 16:19:49 -0800 | [diff] [blame] | 1 | # Copyright 2020 The Android Open Source Project |
| 2 | # |
| 3 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | # you may not use this file except in compliance with the License. |
| 5 | # You may obtain a copy of the License at |
| 6 | # |
| 7 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | # |
| 9 | # Unless required by applicable law or agreed to in writing, software |
| 10 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | # See the License for the specific language governing permissions and |
| 13 | # limitations under the License. |
| 14 | |
| 15 | cmake_minimum_required(VERSION 3.10.2) |
| 16 | |
Cassie Wang | 1db05b5 | 2020-06-26 13:14:18 -0700 | [diff] [blame] | 17 | add_definitions("-DICING_REVERSE_JNI_SEGMENTATION=1") |
Alexander Dorokhine | 49410d1 | 2020-03-02 16:19:49 -0800 | [diff] [blame] | 18 | |
Alexander Dorokhine | 695a85e | 2020-06-03 12:35:10 -0700 | [diff] [blame] | 19 | set( |
| 20 | Protobuf_PREBUILTS_DIR |
| 21 | "${CMAKE_CURRENT_SOURCE_DIR}/../../prebuilts/protobuf") |
Alexander Dorokhine | 49410d1 | 2020-03-02 16:19:49 -0800 | [diff] [blame] | 22 | set(Protobuf_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../protobuf") |
Alexander Dorokhine | 6c89460 | 2020-03-27 15:14:09 -0700 | [diff] [blame] | 23 | set(Protobuf_TARGET_BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}/protobuf-target") |
Alexander Dorokhine | 0647e78 | 2020-06-09 16:11:53 -0700 | [diff] [blame] | 24 | set(Icing_PROTO_GEN_DIR "${CMAKE_CURRENT_BINARY_DIR}/icing-protobuf-gen") |
Alexander Dorokhine | 6c89460 | 2020-03-27 15:14:09 -0700 | [diff] [blame] | 25 | |
Alexander Dorokhine | 695a85e | 2020-06-03 12:35:10 -0700 | [diff] [blame] | 26 | ## Configure libprotobuf ## |
| 27 | # Find the right protoc to compile our proto files |
| 28 | if(${CMAKE_HOST_SYSTEM_NAME} STREQUAL "Darwin") |
| 29 | set(Protobuf_PROTOC_PATH "${Protobuf_PREBUILTS_DIR}/darwin-x86_64/protoc") |
| 30 | elseif(${CMAKE_HOST_SYSTEM_NAME} STREQUAL "Linux") |
| 31 | set(Protobuf_PROTOC_PATH "${Protobuf_PREBUILTS_DIR}/linux-x86_64/protoc") |
| 32 | elseif(${CMAKE_HOST_SYSTEM_NAME} STREQUAL "Windows") |
| 33 | set(Protobuf_PROTOC_PATH "${Protobuf_PREBUILTS_DIR}/windows-x86/protoc.exe") |
| 34 | else() |
| 35 | message( |
| 36 | FATAL_ERROR |
| 37 | "No protoc prebuilt found for host OS ${CMAKE_HOST_SYSTEM_NAME}") |
| 38 | endif() |
| 39 | message(STATUS "Using prebuilt protoc at: ${Protobuf_PROTOC_PATH}") |
Alexander Dorokhine | 49410d1 | 2020-03-02 16:19:49 -0800 | [diff] [blame] | 40 | |
Alexander Dorokhine | 695a85e | 2020-06-03 12:35:10 -0700 | [diff] [blame] | 41 | # Compile libprotobuf |
| 42 | set(protobuf_BUILD_TESTS OFF CACHE BOOL "") |
| 43 | add_subdirectory("${Protobuf_SOURCE_DIR}/cmake" ${Protobuf_TARGET_BINARY_DIR}) |
| 44 | |
| 45 | # Compile libandroidicu |
| 46 | set(ICU_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../icu/libandroidicu") |
| 47 | set(ICU_TARGET_BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}/icu-target") |
| 48 | add_subdirectory(${ICU_SOURCE_DIR} ${ICU_TARGET_BINARY_DIR}) |
Alexander Dorokhine | 49410d1 | 2020-03-02 16:19:49 -0800 | [diff] [blame] | 49 | |
Alexander Dorokhine | 875dc9f | 2020-04-26 21:00:11 -0700 | [diff] [blame] | 50 | # Glob Icing proto sources. Results look like this: icing/proto/document.proto |
Alexander Dorokhine | 49410d1 | 2020-03-02 16:19:49 -0800 | [diff] [blame] | 51 | file( |
| 52 | GLOB_RECURSE |
| 53 | Icing_PROTO_FILES |
Alexander Dorokhine | 0647e78 | 2020-06-09 16:11:53 -0700 | [diff] [blame] | 54 | RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}/proto" |
| 55 | "*.proto") |
Alexander Dorokhine | 49410d1 | 2020-03-02 16:19:49 -0800 | [diff] [blame] | 56 | message(STATUS "Icing_PROTO_FILES=${Icing_PROTO_FILES}") |
| 57 | |
Terry Wang | be92863 | 2020-10-12 03:56:14 -0700 | [diff] [blame] | 58 | |
Alexander Dorokhine | 49410d1 | 2020-03-02 16:19:49 -0800 | [diff] [blame] | 59 | # Run protoc on Icing_PROTO_FILES to generate pb.cc and pb.h files |
Terry Wang | be92863 | 2020-10-12 03:56:14 -0700 | [diff] [blame] | 60 | # The DEPENDS section of add_custom_command could trigger a remake if any proto |
| 61 | # source file has been updated. |
Alexander Dorokhine | 49410d1 | 2020-03-02 16:19:49 -0800 | [diff] [blame] | 62 | file(MAKE_DIRECTORY ${Icing_PROTO_GEN_DIR}) |
| 63 | foreach(FILE ${Icing_PROTO_FILES}) |
| 64 | # Find the name of the proto file without the .proto extension |
| 65 | string(REGEX REPLACE "\.proto$" "" FILE_NOEXT ${FILE}) |
Alexander Dorokhine | 875dc9f | 2020-04-26 21:00:11 -0700 | [diff] [blame] | 66 | list(APPEND Icing_PROTO_SOURCES |
| 67 | "${Icing_PROTO_GEN_DIR}/${FILE_NOEXT}.pb.cc" |
| 68 | "${Icing_PROTO_GEN_DIR}/${FILE_NOEXT}.pb.h") |
| 69 | add_custom_command( |
| 70 | OUTPUT "${Icing_PROTO_GEN_DIR}/${FILE_NOEXT}.pb.cc" |
| 71 | "${Icing_PROTO_GEN_DIR}/${FILE_NOEXT}.pb.h" |
Alexander Dorokhine | 695a85e | 2020-06-03 12:35:10 -0700 | [diff] [blame] | 72 | COMMAND ${Protobuf_PROTOC_PATH} |
Alexander Dorokhine | 0647e78 | 2020-06-09 16:11:53 -0700 | [diff] [blame] | 73 | --proto_path "${CMAKE_CURRENT_SOURCE_DIR}/proto" |
Alexander Dorokhine | 875dc9f | 2020-04-26 21:00:11 -0700 | [diff] [blame] | 74 | --cpp_out ${Icing_PROTO_GEN_DIR} |
| 75 | ${FILE} |
Alexander Dorokhine | 49410d1 | 2020-03-02 16:19:49 -0800 | [diff] [blame] | 76 | WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} |
Terry Wang | be92863 | 2020-10-12 03:56:14 -0700 | [diff] [blame] | 77 | DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/proto/${FILE} |
Alexander Dorokhine | 49410d1 | 2020-03-02 16:19:49 -0800 | [diff] [blame] | 78 | ) |
Alexander Dorokhine | 49410d1 | 2020-03-02 16:19:49 -0800 | [diff] [blame] | 79 | endforeach() |
Alexander Dorokhine | 49410d1 | 2020-03-02 16:19:49 -0800 | [diff] [blame] | 80 | message(STATUS "Icing_PROTO_SOURCES=${Icing_PROTO_SOURCES}") |
| 81 | |
| 82 | # Glob Icing C++ sources |
| 83 | # TODO: When supporting cmake v3.12 or higher, use CONFIGURE_DEPENDS in the glob |
| 84 | # below so that cmake knows when to re-generate the makefiles. |
| 85 | file( |
| 86 | # List files recursively |
| 87 | GLOB_RECURSE |
| 88 | # Store into a variable of this name |
| 89 | Icing_CC_SOURCES |
| 90 | # Return paths that are relative to the project root |
| 91 | RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} |
| 92 | # Glob expressions |
| 93 | icing/*.cc icing/*.h |
| 94 | ) |
Terry Wang | be92863 | 2020-10-12 03:56:14 -0700 | [diff] [blame] | 95 | |
Terry Wang | ffe04ca | 2020-12-23 00:00:05 -0800 | [diff] [blame] | 96 | # TODO(b/170611579): When supporting cmake v3.12 or higher, use CONFIGURE_DEPENDS |
| 97 | # in the glob and remove this section. |
| 98 | include(synced_AOSP_CL_number.txt) |
Terry Wang | be92863 | 2020-10-12 03:56:14 -0700 | [diff] [blame] | 99 | |
Alexander Dorokhine | 49410d1 | 2020-03-02 16:19:49 -0800 | [diff] [blame] | 100 | # Exclude the same types of files as Android.bp. See the comments there. |
Tim Barron | 770e599 | 2020-06-05 16:19:07 -0700 | [diff] [blame] | 101 | list(FILTER Icing_CC_SOURCES EXCLUDE REGEX "^icing/.*[^a-zA-Z0-9]test[^a-zA-Z0-9].*$") |
Alexander Dorokhine | 49410d1 | 2020-03-02 16:19:49 -0800 | [diff] [blame] | 102 | list(FILTER Icing_CC_SOURCES EXCLUDE REGEX "^icing/.*_benchmark\.cc$") |
Tim Barron | 770e599 | 2020-06-05 16:19:07 -0700 | [diff] [blame] | 103 | list(FILTER Icing_CC_SOURCES EXCLUDE REGEX "^icing/helpers/icu/.*$") |
Alexander Dorokhine | 49410d1 | 2020-03-02 16:19:49 -0800 | [diff] [blame] | 104 | list(FILTER Icing_CC_SOURCES EXCLUDE REGEX "^icing/testing/.*$") |
Tim Barron | 770e599 | 2020-06-05 16:19:07 -0700 | [diff] [blame] | 105 | list(FILTER Icing_CC_SOURCES EXCLUDE REGEX "^icing/tokenization/icu/.*$") |
| 106 | list(FILTER Icing_CC_SOURCES EXCLUDE REGEX "^icing/tokenization/simple/.*$") |
Alexander Dorokhine | 49410d1 | 2020-03-02 16:19:49 -0800 | [diff] [blame] | 107 | list(FILTER Icing_CC_SOURCES EXCLUDE REGEX "^icing/tools/.*$") |
Tim Barron | 770e599 | 2020-06-05 16:19:07 -0700 | [diff] [blame] | 108 | list(FILTER Icing_CC_SOURCES EXCLUDE REGEX "^icing/transform/icu/.*$") |
| 109 | list(FILTER Icing_CC_SOURCES EXCLUDE REGEX "^icing/transform/simple/.*$") |
Alexander Dorokhine | 49410d1 | 2020-03-02 16:19:49 -0800 | [diff] [blame] | 110 | message(STATUS "Icing_CC_SOURCES=${Icing_CC_SOURCES}") |
| 111 | |
| 112 | add_library( |
| 113 | # .so name |
| 114 | icing |
| 115 | |
| 116 | # Shared or static |
| 117 | SHARED |
| 118 | |
| 119 | # Provides a relative path to your source file(s). |
| 120 | ${Icing_CC_SOURCES} |
| 121 | ${Icing_PROTO_SOURCES} |
| 122 | ) |
| 123 | target_include_directories(icing PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}) |
| 124 | target_include_directories(icing PRIVATE ${Icing_PROTO_GEN_DIR}) |
| 125 | target_include_directories(icing PRIVATE "${Protobuf_SOURCE_DIR}/src") |
Tim Barron | b47184c | 2020-05-13 22:31:00 +0000 | [diff] [blame] | 126 | target_include_directories(icing PRIVATE "${ICU_SOURCE_DIR}/include") |
| 127 | target_link_libraries(icing protobuf::libprotobuf libandroidicu log) |