github.com/cockroachdb/cockroach@v20.2.0-alpha.1+incompatible/c-deps/libroach/CMakeLists.txt (about)

     1  # Copyright 2017 The Cockroach Authors.
     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
    12  # implied. See the License for the specific language governing
    13  # permissions and limitations under the License.
    14  
    15  # NB: Despite CMake's portability, this build configuration makes no attempt to
    16  # support non-GCC-like compilers.
    17  
    18  # The CXX_STANDARD property was introduced in version 3.1
    19  # 3.3 fixes https://cmake.org/cmake/help/v3.3/policy/CMP0060.html
    20  cmake_minimum_required(VERSION 3.3 FATAL_ERROR)
    21  
    22  project(roachlib)
    23  
    24  if(CMAKE_SYSTEM_NAME MATCHES "Linux")
    25    add_definitions(-DOS_LINUX)
    26  endif()
    27  
    28  add_library(roach
    29    batch.cc
    30    cache.cc
    31    chunked_buffer.cc
    32    comparator.cc
    33    db.cc
    34    encoding.cc
    35    engine.cc
    36    eventlistener.cc
    37    file_registry.cc
    38    getter.cc
    39    godefs.cc
    40    incremental_iterator.cc
    41    row_counter.cc
    42    iterator.cc
    43    ldb.cc
    44    merge.cc
    45    mvcc.cc
    46    options.cc
    47    snapshot.cc
    48    sst_dump.cc
    49    stack_trace.cc
    50    table_props.cc
    51    utils.cc
    52    protos/kv/kvserver/concurrency/lock/locking.pb.cc
    53    protos/roachpb/api.pb.cc
    54    protos/roachpb/data.pb.cc
    55    protos/roachpb/errors.pb.cc
    56    protos/roachpb/internal.pb.cc
    57    protos/roachpb/metadata.pb.cc
    58    protos/storage/enginepb/mvcc.pb.cc
    59    protos/storage/enginepb/mvcc3.pb.cc
    60    protos/storage/enginepb/file_registry.pb.cc
    61    protos/storage/enginepb/rocksdb.pb.cc
    62    protos/util/hlc/legacy_timestamp.pb.cc
    63    protos/util/hlc/timestamp.pb.cc
    64    protos/util/log/log.pb.cc
    65    protos/util/tracing/recorded_span.pb.cc
    66    protos/util/unresolved_addr.pb.cc
    67    rocksdbutils/env_encryption.cc
    68  )
    69  target_include_directories(roach
    70    PUBLIC  ./include
    71    PRIVATE ../protobuf/src
    72    PRIVATE ../rocksdb/include
    73    PRIVATE protos
    74  )
    75  
    76  add_library(roachccl
    77    ccl/crypto_utils.cc
    78    ccl/ctr_stream.cc
    79    ccl/db.cc
    80    ccl/key_manager.cc
    81    protosccl/ccl/baseccl/encryption_options.pb.cc
    82    protosccl/ccl/storageccl/engineccl/enginepbccl/key_registry.pb.cc
    83    protosccl/ccl/storageccl/engineccl/enginepbccl/stats.pb.cc
    84  )
    85  target_include_directories(roachccl
    86    PUBLIC ./ccl/include
    87    PRIVATE .. # CryptoPP headers are directly in the directory. Include .. to be able to include <cryptopp/....h>
    88    PRIVATE ../protobuf/src
    89    PRIVATE ../rocksdb/include
    90    PRIVATE protos
    91    PRIVATE protosccl
    92  )
    93  target_link_libraries(roachccl roach)
    94  
    95  set_target_properties(roach roachccl PROPERTIES
    96    CXX_STANDARD 11
    97    CXX_STANDARD_REQUIRED YES
    98    CXX_EXTENSIONS NO
    99    COMPILE_OPTIONS "-Werror;-Wall;-Wno-sign-compare;-Wno-array-bounds"
   100  )
   101  
   102  enable_testing()
   103  
   104  # List of tests to build and run. Tests in `ccl/` are linked against roachccl, all others
   105  # are linked against roach only.
   106  set(tests
   107    chunked_buffer_test.cc
   108    db_test.cc
   109    comparator_test.cc
   110    encoding_test.cc
   111    file_registry_test.cc
   112    merge_test.cc
   113    ccl/crypto_utils_test.cc
   114    ccl/db_test.cc
   115    ccl/encrypted_env_test.cc
   116    ccl/key_manager_test.cc
   117  )
   118  
   119  # "test" doesn't depend on the actual tests. Let's add a "check" target
   120  # that depends on all test executables and runs "ctest".
   121  add_custom_target(check COMMAND ${CMAKE_CTEST_COMMAND} -V)
   122  
   123  # Add googletest and get around a weird cmake issue:
   124  # https://gitlab.kitware.com/cmake/cmake/issues/16920
   125  set(THREADS_PTHREAD_ARG "2" CACHE STRING "Forcibly set by CMakeLists.txt." FORCE)
   126  add_subdirectory(../googletest/googletest
   127                   ${CMAKE_BINARY_DIR}/googletest
   128                   EXCLUDE_FROM_ALL)
   129  
   130  # TODO(benesch): make this required when CMake 3.9 is widely deployed.
   131  include(GoogleTest OPTIONAL)
   132  
   133  # Iterate over all test sources.
   134  foreach(tsrc ${tests})
   135    # Build target name from filename (eg: ccl_db_test.cc for ccl/db_test.cc).
   136    get_filename_component(filename ${tsrc} NAME_WE)
   137    get_filename_component(dirname ${tsrc} DIRECTORY)
   138    if("${dirname}" STREQUAL "" )
   139      set(tname ${filename})
   140    else()
   141      set(tname ${dirname}_${filename})
   142    endif()
   143  
   144    if(${tsrc} MATCHES "^ccl/")
   145      # Link `ccl/` tests against roachccl and CryptoPP.
   146  		# Use ccl/testutils.
   147      add_executable(${tname} ${tsrc} testutils.cc ccl/testutils.cc)
   148      target_link_libraries(${tname}
   149        roachccl
   150        ${CRYPTOPP_LIB}
   151      )
   152      target_include_directories(${tname}
   153        PRIVATE .. # CryptoPP headers are directly in the directory. Include .. to be able to include <cryptopp/....h>
   154        PRIVATE protosccl
   155      )
   156    else()
   157  		# Use testutils.
   158      add_executable(${tname} ${tsrc} testutils.cc)
   159    endif()
   160  
   161  	# Set includes/libraries/properties.
   162    target_include_directories(${tname}
   163      PRIVATE ../googletest/googletest/include
   164      PRIVATE ../protobuf/src
   165      PRIVATE ../rocksdb/include
   166      PRIVATE protos
   167    )
   168  
   169    # Add all other libraries.
   170    target_link_libraries(${tname}
   171      roach
   172      gtest_main
   173      pthread
   174      ${ROCKSDB_LIB}
   175      ${PROTOBUF_LIB}
   176      ${JEMALLOC_LIB}
   177      ${SNAPPY_LIB}
   178    )
   179  
   180    if(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
   181      target_link_libraries(${tname} rt)
   182    endif()
   183  
   184    set_target_properties(${tname} PROPERTIES
   185      CXX_STANDARD 11
   186      CXX_STANDARD_REQUIRED YES
   187      CXX_EXTENSIONS NO
   188      COMPILE_OPTIONS "-Werror;-Wall;-Wno-sign-compare;-Wno-array-bounds"
   189    )
   190  
   191    # Add the executable to the set of tests run by the "check" target.
   192    if(COMMAND gtest_discover_tests)
   193      # gtest_discover_tests, introduced in CMake 3.10, teaches CTest about the
   194      # actual test cases within the test binary.
   195      gtest_discover_tests(${tname})
   196    else()
   197      # In earlier versions, just tell CTest to treat the test binary as a black
   198      # box that returns an exit code.
   199      add_test(${tname} ${tname})
   200    endif()
   201    add_dependencies(check ${tname})
   202  endforeach(tsrc)