1# Copyright 2015 The RE2 Authors. All Rights Reserved. 2# Use of this source code is governed by a BSD-style 3# license that can be found in the LICENSE file. 4 5# Old enough to support Ubuntu Trusty. 6cmake_minimum_required(VERSION 2.8.12) 7 8if(POLICY CMP0048) 9 cmake_policy(SET CMP0048 NEW) 10endif() 11 12project(RE2 CXX) 13include(CTest) 14 15option(BUILD_SHARED_LIBS "build shared libraries" OFF) 16option(USEPCRE "use PCRE in tests and benchmarks" OFF) 17 18# CMake seems to have no way to enable/disable testing per subproject, 19# so we provide an option similar to BUILD_TESTING, but just for RE2. 20option(RE2_BUILD_TESTING "enable testing for RE2" ON) 21 22set(EXTRA_TARGET_LINK_LIBRARIES) 23 24if(CMAKE_CXX_COMPILER_ID MATCHES "MSVC") 25 if(MSVC_VERSION LESS 1900) 26 message(FATAL_ERROR "you need Visual Studio 2015 or later") 27 endif() 28 if(BUILD_SHARED_LIBS) 29 # See http://www.kitware.com/blog/home/post/939 for details. 30 cmake_minimum_required(VERSION 3.4) 31 set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON) 32 endif() 33 # CMake defaults to /W3, but some users like /W4 (or /Wall) and /WX, 34 # so we disable various warnings that aren't particularly helpful. 35 add_compile_options(/wd4100 /wd4201 /wd4456 /wd4457 /wd4702 /wd4815) 36 # Without a byte order mark (BOM), Visual Studio assumes that the source 37 # file is encoded using the current user code page, so we specify UTF-8. 38 add_compile_options(/utf-8) 39elseif(CYGWIN OR MINGW) 40 # See https://stackoverflow.com/questions/38139631 for details. 41 add_compile_options(-std=gnu++11) 42elseif(CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang") 43 add_compile_options(-std=c++11) 44endif() 45 46if(WIN32) 47 add_definitions(-DUNICODE -D_UNICODE -DSTRICT -DNOMINMAX) 48 add_definitions(-D_CRT_SECURE_NO_WARNINGS -D_SCL_SECURE_NO_WARNINGS) 49elseif(UNIX) 50 add_compile_options(-pthread) 51 list(APPEND EXTRA_TARGET_LINK_LIBRARIES -pthread) 52endif() 53 54if(USEPCRE) 55 add_definitions(-DUSEPCRE) 56 list(APPEND EXTRA_TARGET_LINK_LIBRARIES pcre) 57endif() 58 59include_directories(${CMAKE_CURRENT_SOURCE_DIR}) 60 61set(RE2_SOURCES 62 re2/bitstate.cc 63 re2/compile.cc 64 re2/dfa.cc 65 re2/filtered_re2.cc 66 re2/mimics_pcre.cc 67 re2/nfa.cc 68 re2/onepass.cc 69 re2/parse.cc 70 re2/perl_groups.cc 71 re2/prefilter.cc 72 re2/prefilter_tree.cc 73 re2/prog.cc 74 re2/re2.cc 75 re2/regexp.cc 76 re2/set.cc 77 re2/simplify.cc 78 re2/stringpiece.cc 79 re2/tostring.cc 80 re2/unicode_casefold.cc 81 re2/unicode_groups.cc 82 util/rune.cc 83 util/strutil.cc 84 ) 85 86add_library(re2 ${RE2_SOURCES}) 87 88if(RE2_BUILD_TESTING) 89 set(TESTING_SOURCES 90 re2/testing/backtrack.cc 91 re2/testing/dump.cc 92 re2/testing/exhaustive_tester.cc 93 re2/testing/null_walker.cc 94 re2/testing/regexp_generator.cc 95 re2/testing/string_generator.cc 96 re2/testing/tester.cc 97 util/pcre.cc 98 ) 99 100 add_library(testing STATIC ${TESTING_SOURCES}) 101 102 set(TEST_TARGETS 103 charclass_test 104 compile_test 105 filtered_re2_test 106 mimics_pcre_test 107 parse_test 108 possible_match_test 109 re2_test 110 re2_arg_test 111 regexp_test 112 required_prefix_test 113 search_test 114 set_test 115 simplify_test 116 string_generator_test 117 118 dfa_test 119 exhaustive1_test 120 exhaustive2_test 121 exhaustive3_test 122 exhaustive_test 123 random_test 124 ) 125 126 set(BENCHMARK_TARGETS 127 regexp_benchmark 128 ) 129 130 foreach(target ${TEST_TARGETS}) 131 add_executable(${target} re2/testing/${target}.cc util/test.cc) 132 target_link_libraries(${target} testing re2 ${EXTRA_TARGET_LINK_LIBRARIES}) 133 add_test(NAME ${target} COMMAND ${target}) 134 endforeach(target) 135 136 foreach(target ${BENCHMARK_TARGETS}) 137 add_executable(${target} re2/testing/${target}.cc util/benchmark.cc) 138 target_link_libraries(${target} testing re2 ${EXTRA_TARGET_LINK_LIBRARIES}) 139 endforeach(target) 140endif() 141 142set(RE2_HEADERS 143 re2/filtered_re2.h 144 re2/re2.h 145 re2/set.h 146 re2/stringpiece.h 147 ) 148 149install(FILES ${RE2_HEADERS} DESTINATION include/re2) 150install(TARGETS re2 ARCHIVE DESTINATION lib LIBRARY DESTINATION lib RUNTIME DESTINATION bin) 151