From 4805669b01d6a5f7fd61d6451f192950e4e36b9b Mon Sep 17 00:00:00 2001 From: Connor Baker Date: Tue, 23 Jan 2024 05:03:40 +0000 Subject: [PATCH] cmake: update and add install targets Co-Authored-By: Someone Serge --- CMakeLists.txt | 68 ++++++++++++++++++++---------------------- tinyformatConfig.cmake | 1 + 2 files changed, 34 insertions(+), 35 deletions(-) create mode 100644 tinyformatConfig.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index 7715dd0..8f17830 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,44 +1,42 @@ # CMake build for tests. # # See also the Makefile, which is currently more fully featured on unix. - - -# Set cmake builtin variables before calling project(), otherwise the -# cmake-provided defaults will get in first! -set(CMAKE_BUILD_TYPE "Release" CACHE STRING - "Choose the type of build, options are: None(CMAKE_CXX_FLAGS or CMAKE_C_FLAGS used) Debug Release RelWithDebInfo MinSizeRel." +cmake_minimum_required(VERSION 3.14) +project(tinyformat LANGUAGES CXX) + +# Define the target library +add_library(tinyformat INTERFACE) +target_compile_features(tinyformat INTERFACE cxx_std_11) +target_compile_options(tinyformat INTERFACE + $<$:/W4 /WX> + $<$>:-Wall -Werror> +) +target_include_directories(tinyformat INTERFACE + $ + $ ) -set(CXX_STD "c++11" CACHE STRING "Version of C++ standard in use") - -# This project is infrastructure. Warnings from common warning levels should -# be errors on all compilers, unless explicitly silenced. -if(NOT WIN32) - set(CMAKE_CXX_FLAGS "-Wall -Werror -std=${CXX_STD}" CACHE STRING "Flags used by the compiler during all build types.") -endif() - -project(tinyformat) -cmake_minimum_required(VERSION 2.8) -set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin) +# Setup for testing +include(CTest) +if(BUILD_TESTING) + add_executable(tinyformat_test tinyformat_test.cpp) + target_link_libraries(tinyformat_test PRIVATE tinyformat) + add_test(NAME tinyformat_test COMMAND tinyformat_test) -if(WIN32) - # Treat warnings as errors. Would set this above, but need the default - # flags too, and `project()` behaves is differently on different systems. - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W3 /WX") -endif() + add_executable(tinyformat_speed_test tinyformat_speed_test.cpp) + target_link_libraries(tinyformat_speed_test PRIVATE tinyformat) -# Dummy translation unit to test for missing `inline`s -include_directories(${CMAKE_SOURCE_DIR}) -file(WRITE ${CMAKE_BINARY_DIR}/_empty.cpp "#include \"tinyformat.h\"") -add_executable(tinyformat_test tinyformat_test.cpp ${CMAKE_BINARY_DIR}/_empty.cpp) -enable_testing() -if(CMAKE_CONFIGURATION_TYPES) - set(ctest_config_opt -C ${CMAKE_BUILD_TYPE}) + foreach(impl printf iostreams tinyformat boost) + add_test(NAME tinyformat_speed_test_${impl} COMMAND tinyformat_speed_test ${impl}) + endforeach() endif() -add_test(NAME test COMMAND tinyformat_test) -add_custom_target(testall COMMAND ${CMAKE_CTEST_COMMAND} -V ${ctest_config_opt} DEPENDS tinyformat_test) -option(COMPILE_SPEED_TEST FALSE) -if (COMPILE_SPEED_TEST) - add_executable(tinyformat_speed_test tinyformat_speed_test.cpp) -endif () +# Setup for installation +install(TARGETS tinyformat EXPORT tinyformatTargets) +install(FILES tinyformat.h DESTINATION include) +install(FILES tinyformatConfig.cmake DESTINATION lib/cmake/tinyformat) +install( + EXPORT tinyformatTargets + FILE tinyformatTargets.cmake + DESTINATION lib/cmake/tinyformat +) diff --git a/tinyformatConfig.cmake b/tinyformatConfig.cmake new file mode 100644 index 0000000..877f0e9 --- /dev/null +++ b/tinyformatConfig.cmake @@ -0,0 +1 @@ +include("${CMAKE_CURRENT_LIST_DIR}/tinyformatTargets.cmake")