Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmake: update and add install targets #87

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 33 additions & 35 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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
$<$<CXX_COMPILER_ID:MSVC>:/W4 /WX>
$<$<NOT:$<CXX_COMPILER_ID:MSVC>>:-Wall -Werror>
)
target_include_directories(tinyformat INTERFACE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
$<INSTALL_INTERFACE:include>
)

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
)
1 change: 1 addition & 0 deletions tinyformatConfig.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
include("${CMAKE_CURRENT_LIST_DIR}/tinyformatTargets.cmake")