Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
To make it simpler and easier to understand. Some of the changes are: * Comments are removed because they look redundant and just explain explicit things. * CMake commands are grouped in section, first goes "target" section, then "tests", and "install" is at the very end. * "make run" command has been removed because termcolo may be used by another projects as a subproject, and we don't want to propagate such broadly named command to the main project.
- Loading branch information
1 parent
60c0fa1
commit bcfbae5
Showing
2 changed files
with
43 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,64 +1,58 @@ | ||
cmake_minimum_required(VERSION 3.0) | ||
project(termcolor) | ||
|
||
# define target to install and link tests against | ||
add_library(${PROJECT_NAME} INTERFACE) | ||
target_include_directories(${PROJECT_NAME} | ||
INTERFACE $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>) | ||
# | ||
# target | ||
# | ||
|
||
# ALIAS same as in configure file | ||
# the ALIAS can be used to create examples which use the same syntax as a client | ||
# application, which uses `find_package(libdivide CONFIG)` | ||
# create the alias libdivide::libdivide | ||
add_library(${PROJECT_NAME} INTERFACE) | ||
add_library(${PROJECT_NAME}::${PROJECT_NAME} ALIAS ${PROJECT_NAME}) | ||
|
||
option(ENABLE_TESTING "enable testing with CTEST" ON) | ||
if(ENABLE_TESTING) | ||
enable_testing() | ||
target_include_directories(${PROJECT_NAME} INTERFACE | ||
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include> | ||
$<INSTALL_INTERFACE:include>) | ||
|
||
# | ||
# tests | ||
# | ||
|
||
option(TERMCOLOR_TESTS "Build termcolor tests." OFF) | ||
|
||
if(TERMCOLOR_TESTS) | ||
add_executable(test_${PROJECT_NAME} test/test.cpp) | ||
# add compiler flags for test target only for GCC and Clang | ||
target_compile_options(test_${PROJECT_NAME} INTERFACE | ||
$<BUILD_INTERFACE: | ||
$<$<OR:$<CXX_COMPILER_ID:GNU>,$<CXX_COMPILER_ID:Clang>>: | ||
-Werror -Wall -pedantic>> | ||
) | ||
|
||
add_test(test_${PROJECT_NAME} test_${PROJECT_NAME}) | ||
target_link_libraries(test_${PROJECT_NAME} PRIVATE ${PROJECT_NAME}::${PROJECT_NAME}) | ||
add_custom_target(run COMMAND test_${PROJECT_NAME}) | ||
-Werror -Wall -pedantic>>) | ||
target_link_libraries( | ||
test_${PROJECT_NAME} PRIVATE ${PROJECT_NAME}::${PROJECT_NAME}) | ||
endif() | ||
|
||
# create install target | ||
install( | ||
TARGETS ${PROJECT_NAME} | ||
EXPORT ${PROJECT_NAME}-targets | ||
INCLUDES DESTINATION include # set include path for installed library target | ||
) | ||
install( | ||
FILES include/termcolor/termcolor.hpp | ||
DESTINATION include/termcolor | ||
) | ||
# | ||
# install | ||
# | ||
|
||
# Include module for fuctions | ||
# - 'write_basic_package_version_file' | ||
# - 'configure_package_config_file' | ||
include(CMakePackageConfigHelpers) | ||
|
||
# generate and install termcolor-config.cmake file | ||
# Configure '<PROJECT-NAME>-config.cmake' | ||
configure_package_config_file( | ||
"cmake/config.cmake.in" | ||
"${CMAKE_CURRENT_BINARY_DIR}/generated/termcolor-config.cmake" | ||
INSTALL_DESTINATION "lib/cmake/termcolor" | ||
) | ||
# install config file | ||
cmake/config.cmake.in | ||
${CMAKE_CURRENT_BINARY_DIR}/generated/${PROJECT_NAME}-config.cmake | ||
INSTALL_DESTINATION lib/cmake/${PROJECT_NAME}) | ||
|
||
install( | ||
FILES "${CMAKE_CURRENT_BINARY_DIR}/generated/termcolor-config.cmake" | ||
DESTINATION "lib/cmake/termcolor" | ||
) | ||
# install targets file | ||
FILES ${CMAKE_CURRENT_BINARY_DIR}/generated/${PROJECT_NAME}-config.cmake | ||
DESTINATION lib/cmake/${PROJECT_NAME}) | ||
|
||
install( | ||
EXPORT "${PROJECT_NAME}-targets" | ||
NAMESPACE "${PROJECT_NAME}::" | ||
DESTINATION "lib/cmake/termcolor" | ||
) | ||
DIRECTORY include/ | ||
DESTINATION include) | ||
|
||
install( | ||
TARGETS ${PROJECT_NAME} | ||
EXPORT ${PROJECT_NAME}-targets | ||
INCLUDES DESTINATION include) | ||
|
||
install( | ||
EXPORT ${PROJECT_NAME}-targets | ||
NAMESPACE ${PROJECT_NAME}:: | ||
DESTINATION lib/cmake/${PROJECT_NAME}) |