Improve CMakeLists to allow disabling example and lint builds, also fix a warning on CMake version 3.24 and above.

This commit is contained in:
Pierre Talbot 2022-11-08 22:18:54 +01:00
parent a212606a90
commit 41132d1776
2 changed files with 18 additions and 7 deletions

View File

@ -1,6 +1,12 @@
cmake_minimum_required(VERSION 3.14)
project(cpp-peglib)
# Avoid warning about DOWNLOAD_EXTRACT_TIMESTAMP in CMake 3.24:
# Fix found at https://github.com/ethereum/solidity/pull/13429
if (CMAKE_VERSION VERSION_GREATER_EQUAL "3.24.0")
cmake_policy(SET CMP0135 NEW)
endif()
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_EXTENSIONS OFF)
@ -11,18 +17,17 @@ else()
endif()
option(PEGLIB_BUILD_TESTS "Build cpp-peglib tests" ON)
option(PEGLIB_BUILD_LINT "Build cpp-peglib lint" ON)
option(PEGLIB_BUILD_EXAMPLE "Build cpp-peglib examples" ON)
set(THREADS_PREFER_PTHREAD_FLAG ON)
find_package(Threads)
if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
set(add_link_deps Threads::Threads)
if(${PEGLIB_BUILD_LINT})
add_subdirectory(lint)
endif()
add_subdirectory(lint)
if(${PEGLIB_BUILD_EXAMPLE})
add_subdirectory(example)
# add_subdirectory(cymbol)
endif()
if (${PEGLIB_BUILD_TESTS})
add_subdirectory(test)

View File

@ -1,6 +1,12 @@
cmake_minimum_required(VERSION 3.14)
project(test)
# Avoid warning about DOWNLOAD_EXTRACT_TIMESTAMP in CMake 3.24:
# Fix found at https://github.com/ethereum/solidity/pull/13429
if (CMAKE_VERSION VERSION_GREATER_EQUAL "3.24.0")
cmake_policy(SET CMP0135 NEW)
endif()
include(FetchContent)
FetchContent_Declare(
googletest