From ab9d785c11f331303b254451d64dac8a1315a0d2 Mon Sep 17 00:00:00 2001 From: "Dr. Colin Hirsch" Date: Thu, 30 Nov 2023 07:16:24 +0100 Subject: [PATCH] Build perf via cmake. --- CMakeLists.txt | 6 ++++++ src/perf/json/CMakeLists.txt | 42 ++++++++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+) create mode 100644 src/perf/json/CMakeLists.txt diff --git a/CMakeLists.txt b/CMakeLists.txt index bbd90702..65e2dcfe 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -51,6 +51,12 @@ if(TAOCPP_JSON_BUILD_EXAMPLES) add_subdirectory(src/example/json) endif() +# performance +option(TAOCPP_JSON_BUILD_PERFORMANCE "Build performance programs" ${TAOCPP_JSON_IS_MAIN_PROJECT}) +if(TAOCPP_JSON_BUILD_PERFORMANCE) + add_subdirectory(src/perf/json) +endif() + option(TAOCPP_JSON_INSTALL "Generate the install target" ${TAOCPP_JSON_IS_MAIN_PROJECT}) if(TAOCPP_JSON_INSTALL) include(CMakePackageConfigHelpers) diff --git a/src/perf/json/CMakeLists.txt b/src/perf/json/CMakeLists.txt new file mode 100644 index 00000000..997a5809 --- /dev/null +++ b/src/perf/json/CMakeLists.txt @@ -0,0 +1,42 @@ +cmake_minimum_required(VERSION 3.8...3.19) + +set(perfsources + benchmark.cpp + parse_file.cpp + pretty_print_file.cpp + print_double.cpp + print_file.cpp + sizes.cpp + syntax_only.cpp +) + +# file(GLOB ...) is used to validate the above list of perf_sources +file(GLOB glob_perf_sources RELATIVE ${CMAKE_CURRENT_LIST_DIR} *.cpp) + +foreach(perfsourcefile ${perfsources}) + if(${perfsourcefile} IN_LIST glob_perf_sources) + list(REMOVE_ITEM glob_perf_sources ${perfsourcefile}) + else() + message(SEND_ERROR "File ${perfsourcefile} is missing from src/perf/json") + endif() + get_filename_component(exename ${perfsourcefile} NAME_WE) + set(exename "tao-json-perf-${exename}") + add_executable(${exename} ${perfsourcefile}) + target_link_libraries(${exename} PRIVATE taocpp::json) + set_target_properties(${exename} PROPERTIES + CXX_STANDARD 11 + CXX_STANDARD_REQUIRED ON + CXX_EXTENSIONS OFF + ) + if(MSVC) + target_compile_options(${exename} PRIVATE /W4 /WX /utf-8) + else() + target_compile_options(${exename} PRIVATE -pedantic -Wall -Wextra -Wshadow -Werror) + endif() +endforeach() + +if(glob_perf_sources) + foreach(ignored_source_file ${glob_perf_sources}) + message(SEND_ERROR "File ${ignored_source_file} in src/perf/json is ignored") + endforeach() +endif()