Skip to content

Commit

Permalink
Switch to cxx_std_11 as per best current practice.
Browse files Browse the repository at this point in the history
It requires a version of CMake newer than what Ubuntu Xenial has,
but I should really have bumped up to Ubuntu Bionic a year ago...

Fixes google#370.

Change-Id: I1af221e03d80da2df547c63c7ed60016a892885e
Reviewed-on: https://code-review.googlesource.com/c/re2/+/60092
Reviewed-by: Perry Lorier <[email protected]>
Reviewed-by: Paul Wankadia <[email protected]>
  • Loading branch information
junyer committed Apr 11, 2022
1 parent f093268 commit f5c782e
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,14 @@
# Use of this source code is governed by a BSD-style
# license that can be found in the LICENSE file.

# Old enough to support Ubuntu Xenial.
cmake_minimum_required(VERSION 3.5.1)
# Old enough to support Ubuntu Bionic.
cmake_minimum_required(VERSION 3.10.2)

project(RE2 CXX)
include(CMakePackageConfigHelpers)
include(CTest)
include(GNUInstallDirs)

# Unlike GCC and upstream Clang, AppleClang still defaults to `-std=c++98`
# for some reason. Set CMAKE_CXX_STANDARD if we seem to need to set it. :/
if(APPLE AND NOT CMAKE_CXX_FLAGS MATCHES "-std=" AND NOT CMAKE_CXX_STANDARD)
set(CMAKE_CXX_STANDARD 11)
endif()

option(BUILD_SHARED_LIBS "build shared libraries" OFF)
option(USEPCRE "use PCRE in tests and benchmarks" OFF)

Expand Down Expand Up @@ -84,6 +78,7 @@ set(RE2_SOURCES
)

add_library(re2 ${RE2_SOURCES})
target_compile_features(re2 PUBLIC cxx_std_11)
target_include_directories(re2 PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>)
set_target_properties(re2 PROPERTIES SOVERSION ${SONAME} VERSION ${SONAME}.0.0)
add_library(re2::re2 ALIAS re2)
Expand All @@ -105,6 +100,7 @@ if(RE2_BUILD_TESTING)
)

add_library(testing STATIC ${TESTING_SOURCES})
target_compile_features(testing PUBLIC cxx_std_11)
target_link_libraries(testing PUBLIC re2)

set(TEST_TARGETS
Expand Down Expand Up @@ -137,12 +133,14 @@ if(RE2_BUILD_TESTING)

foreach(target ${TEST_TARGETS})
add_executable(${target} re2/testing/${target}.cc util/test.cc)
target_compile_features(${target} PUBLIC cxx_std_11)
target_link_libraries(${target} testing ${EXTRA_TARGET_LINK_LIBRARIES})
add_test(NAME ${target} COMMAND ${target})
endforeach()

foreach(target ${BENCHMARK_TARGETS})
add_executable(${target} re2/testing/${target}.cc util/benchmark.cc)
target_compile_features(${target} PUBLIC cxx_std_11)
target_link_libraries(${target} testing ${EXTRA_TARGET_LINK_LIBRARIES})
endforeach()
endif()
Expand Down

0 comments on commit f5c782e

Please sign in to comment.