mirror of
https://github.com/boostorg/parser.git
synced 2026-01-19 04:22:13 +00:00
Fix deficiencies in the CMake build:
- Clone minimal Boost dependencies so that the minimal Boost.Test header is available. - Add boostdep-generated CMake code to the top of the top-level CMakeLists.txt. Fixes #127.
This commit is contained in:
@@ -1,4 +1,36 @@
|
||||
cmake_minimum_required(VERSION 3.5)
|
||||
# Copyright (C) 2024 T. Zachary Laine
|
||||
# Distributed under the Boost Software License, Version 1.0.
|
||||
# https://www.boost.org/LICENSE_1_0.txt
|
||||
|
||||
if(NOT CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
|
||||
|
||||
# Generated by `boostdep --cmake parser`
|
||||
|
||||
cmake_minimum_required(VERSION 3.8...3.20)
|
||||
|
||||
project(boost_parser VERSION "${BOOST_SUPERPROJECT_VERSION}" LANGUAGES CXX)
|
||||
|
||||
add_library(boost_parser INTERFACE)
|
||||
add_library(Boost::parser ALIAS boost_parser)
|
||||
|
||||
target_include_directories(boost_parser INTERFACE include)
|
||||
|
||||
target_link_libraries(boost_parser
|
||||
INTERFACE
|
||||
Boost::assert
|
||||
Boost::hana
|
||||
Boost::type_index
|
||||
)
|
||||
|
||||
if(BUILD_TESTING AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/test/CMakeLists.txt")
|
||||
|
||||
add_subdirectory(test)
|
||||
|
||||
endif()
|
||||
|
||||
else()
|
||||
|
||||
cmake_minimum_required(VERSION 3.8...3.20)
|
||||
project(parse)
|
||||
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
|
||||
|
||||
@@ -9,17 +41,19 @@ set(CXX_STD 17 CACHE STRING "Set to 14, 17, etc., to enable C++14, C++17, etc.")
|
||||
message("-- Using -std=c++${CXX_STD}")
|
||||
|
||||
if (CMAKE_CXX_COMPILER_ID STREQUAL Clang)
|
||||
add_definitions(-g -Wall)
|
||||
add_definitions(-Wall)
|
||||
elseif (CMAKE_CXX_COMPILER_ID STREQUAL GNU)
|
||||
add_definitions(-g -Wall)
|
||||
add_definitions(-Wall)
|
||||
elseif (CMAKE_CXX_COMPILER_ID STREQUAL MSVC)
|
||||
add_definitions(/W3)
|
||||
endif ()
|
||||
|
||||
|
||||
##################################################
|
||||
# Build config
|
||||
##################################################
|
||||
set(BUILD_WITH_HANA false CACHE BOOL "Build with BOOST_PARSER_USE_HANA_TUPLE defined.")
|
||||
set(BUILD_WITH_HANA false CACHE BOOL
|
||||
"Build with optional Hana support (and BOOST_PARSER_USE_HANA_TUPLE defined).")
|
||||
if (BUILD_WITH_HANA)
|
||||
add_definitions(-DBOOST_PARSER_USE_HANA_TUPLE)
|
||||
endif()
|
||||
@@ -54,8 +88,11 @@ if (Boost_FOUND)
|
||||
target_include_directories(parser INTERFACE ${Boost_INCLUDE_DIRS})
|
||||
endif()
|
||||
|
||||
|
||||
##################################################
|
||||
# Subdirectories
|
||||
##################################################
|
||||
add_subdirectory(test)
|
||||
add_subdirectory(example)
|
||||
|
||||
endif()
|
||||
|
||||
@@ -1,9 +1,58 @@
|
||||
# Copyright Louis Dionne 2016
|
||||
# Copyright Zach Laine 2016
|
||||
# Copyright Zach Laine 2024
|
||||
# Distributed under the Boost Software License, Version 1.0.
|
||||
# (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt)
|
||||
|
||||
###############################################################################
|
||||
# Boost
|
||||
###############################################################################
|
||||
find_package(Boost)
|
||||
set(Boost_USE_STATIC_LIBS ON)
|
||||
|
||||
if (NOT BOOST_BRANCH)
|
||||
set(BOOST_BRANCH master)
|
||||
endif()
|
||||
|
||||
add_custom_target(boost_clone_superproject
|
||||
DEPENDS
|
||||
${CMAKE_BINARY_DIR}/boost_root
|
||||
COMMENT
|
||||
"Cloning Boost superproject."
|
||||
VERBATIM)
|
||||
|
||||
add_custom_command(
|
||||
OUTPUT ${CMAKE_BINARY_DIR}/boost_root
|
||||
COMMAND git clone --depth 100 -b ${BOOST_BRANCH}
|
||||
https://github.com/boostorg/boost.git boost_root
|
||||
WORKING_DIRECTORY ${CMAKE_BINARY_DIR})
|
||||
|
||||
add_custom_target(boost_clone_deps
|
||||
DEPENDS
|
||||
${CMAKE_BINARY_DIR}/boost_root/libs/headers/include
|
||||
COMMENT
|
||||
"Cloning Boost dependencies."
|
||||
VERBATIM)
|
||||
add_dependencies(boost_clone_deps boost_clone_superproject)
|
||||
|
||||
if (MSVC)
|
||||
set(bootstrap_cmd ./bootstrap.bat)
|
||||
else()
|
||||
set(bootstrap_cmd ./bootstrap.sh)
|
||||
endif()
|
||||
|
||||
add_custom_command(
|
||||
OUTPUT ${CMAKE_BINARY_DIR}/boost_root/libs/headers/include
|
||||
COMMAND git submodule init libs/assert
|
||||
COMMAND git submodule init libs/config
|
||||
COMMAND git submodule init libs/core
|
||||
COMMAND git submodule init libs/hana
|
||||
COMMAND git submodule init tools/build
|
||||
COMMAND git submodule init libs/headers
|
||||
COMMAND git submodule init tools/boost_install
|
||||
COMMAND git submodule update --jobs 3 --depth 100
|
||||
COMMAND ${bootstrap_cmd}
|
||||
COMMAND ./b2 headers
|
||||
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/boost_root)
|
||||
|
||||
add_library(boost INTERFACE)
|
||||
add_dependencies(boost boost_clone_deps)
|
||||
target_include_directories(boost INTERFACE ${CMAKE_BINARY_DIR}/boost_root)
|
||||
|
||||
@@ -11,29 +11,31 @@ enable_testing()
|
||||
|
||||
add_custom_target(run_examples COMMAND ${CMAKE_CTEST_COMMAND} -VV -C ${CMAKE_CFG_INTDIR})
|
||||
|
||||
macro(add_sample name)
|
||||
macro(add_example name)
|
||||
add_executable(${name} ${name}.cpp)
|
||||
target_link_libraries(${name} parser)
|
||||
target_link_libraries(${name} parser ${ARGN})
|
||||
set_property(TARGET ${name} PROPERTY CXX_STANDARD ${CXX_STD})
|
||||
add_test(${name} ${CMAKE_CURRENT_BINARY_DIR}/${name})
|
||||
endmacro()
|
||||
|
||||
add_sample(hello)
|
||||
add_sample(trivial)
|
||||
add_sample(trivial_skipper)
|
||||
add_sample(semantic_actions)
|
||||
add_sample(rule_intro)
|
||||
add_sample(struct_rule)
|
||||
add_sample(parsing_into_a_struct)
|
||||
add_sample(parsing_into_a_class)
|
||||
add_sample(roman_numerals)
|
||||
add_sample(user_error_handler)
|
||||
|
||||
if (Boost_FOUND)
|
||||
if (NOT BUILD_WITHOUT_HANA)
|
||||
add_sample(self_filling_symbol_table)
|
||||
add_sample(json)
|
||||
endif()
|
||||
|
||||
add_sample(callback_json)
|
||||
set(libs)
|
||||
if (BUILD_WITH_HANA)
|
||||
set(libs boost)
|
||||
endif()
|
||||
|
||||
add_example(hello ${libs})
|
||||
add_example(trivial ${libs})
|
||||
add_example(trivial_skipper ${libs})
|
||||
add_example(semantic_actions ${libs})
|
||||
add_example(rule_intro ${libs})
|
||||
add_example(struct_rule ${libs})
|
||||
add_example(parsing_into_a_struct ${libs})
|
||||
add_example(parsing_into_a_class ${libs})
|
||||
add_example(user_error_handler ${libs})
|
||||
|
||||
if (BUILD_WITH_HANA)
|
||||
add_example(roman_numerals boost)
|
||||
add_example(self_filling_symbol_table boost)
|
||||
add_example(json boost)
|
||||
add_example(callback_json boost)
|
||||
endif()
|
||||
|
||||
@@ -11,7 +11,7 @@ add_custom_target(check COMMAND ${CMAKE_CTEST_COMMAND} --output-on-failure -j4 -
|
||||
##################################################
|
||||
add_executable(parser_ parser.cpp)
|
||||
set_property(TARGET parser_ PROPERTY CXX_STANDARD ${CXX_STD})
|
||||
target_link_libraries(parser_ parser ${link_flags})
|
||||
target_link_libraries(parser_ parser boost ${link_flags})
|
||||
if (MSVC)
|
||||
target_compile_options(parser_ PRIVATE /source-charset:utf-8 /bigobj)
|
||||
endif ()
|
||||
@@ -19,7 +19,7 @@ add_test(NAME parser_ COMMAND parser_)
|
||||
|
||||
add_executable(parser_api parser_api.cpp)
|
||||
set_property(TARGET parser_api PROPERTY CXX_STANDARD ${CXX_STD})
|
||||
target_link_libraries(parser_api parser ${link_flags})
|
||||
target_link_libraries(parser_api parser boost ${link_flags})
|
||||
if (MSVC)
|
||||
target_compile_options(parser_api PRIVATE /source-charset:utf-8 /bigobj)
|
||||
endif ()
|
||||
@@ -35,12 +35,12 @@ add_executable(
|
||||
compile_all_t.cpp
|
||||
)
|
||||
set_property(TARGET compile_tests PROPERTY CXX_STANDARD ${CXX_STD})
|
||||
target_link_libraries(compile_tests parser)
|
||||
target_link_libraries(compile_tests parser boost)
|
||||
|
||||
macro(add_test_executable name)
|
||||
add_executable(${name} ${name}.cpp)
|
||||
set_property(TARGET ${name} PROPERTY CXX_STANDARD ${CXX_STD})
|
||||
target_link_libraries(${name} parser ${link_flags})
|
||||
target_link_libraries(${name} parser boost ${link_flags})
|
||||
if (MSVC)
|
||||
target_compile_options(${name} PRIVATE /source-charset:utf-8 /bigobj)
|
||||
endif ()
|
||||
|
||||
Reference in New Issue
Block a user