forked from agauniyal/rang
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Import code in maddouri:pr.better_cmake PR, prepare for minor release…
… with cmake
- Loading branch information
Showing
3 changed files
with
91 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,60 @@ | ||
cmake_minimum_required (VERSION 2.8) | ||
cmake_minimum_required (VERSION 2.8.12) | ||
|
||
project (rang) | ||
|
||
include_directories(include) | ||
install(FILES ${PROJECT_SOURCE_DIR}/include/rang.hpp DESTINATION include) | ||
add_library(${PROJECT_NAME} INTERFACE) | ||
target_include_directories(${PROJECT_NAME} INTERFACE | ||
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>" | ||
"$<INSTALL_INTERFACE:include>" # <prefix>/include | ||
) | ||
|
||
install( | ||
FILES "include/rang.hpp" | ||
DESTINATION "include" | ||
) | ||
|
||
# Usage in CMake projects: | ||
# | ||
# set(CMAKE_CXX_STANDARD 11) | ||
# set(CMAKE_CXX_STANDARD_REQUIRED ON) | ||
# set(CMAKE_CXX_EXTENSIONS OFF) | ||
# | ||
# set(rang_DIR "path/to/rangConfig.cmake/dir" CACHE PATH "Directory containing rangConfig.cmake") | ||
# find_package(rang REQUIRED CONFIG [NO_DEFAULT_PATH]) | ||
# | ||
# add_executable(some_app some_app_source.cpp) | ||
# target_link_libraries(some_app rang) | ||
install(TARGETS ${PROJECT_NAME} EXPORT ${PROJECT_NAME}Targets) | ||
|
||
include(CMakePackageConfigHelpers) | ||
set(CONFIG_PACKAGE_BUILD_LOCATION "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}") | ||
set(CONFIG_PACKAGE_INSTALL_LOCATION "lib/cmake/${PROJECT_NAME}") | ||
write_basic_package_version_file ( | ||
"${CONFIG_PACKAGE_BUILD_LOCATION}/${PROJECT_NAME}ConfigVersion.cmake" | ||
VERSION 3.1.0 | ||
COMPATIBILITY AnyNewerVersion | ||
) | ||
export( | ||
EXPORT ${PROJECT_NAME}Targets | ||
FILE "${CONFIG_PACKAGE_BUILD_LOCATION}/${PROJECT_NAME}Targets.cmake" | ||
#NAMESPACE ${PROJECT_NAME}:: | ||
) | ||
configure_file( | ||
"cmake/Config.cmake.in" | ||
"${CONFIG_PACKAGE_BUILD_LOCATION}/${PROJECT_NAME}Config.cmake" | ||
@ONLY | ||
) | ||
install( | ||
EXPORT "${PROJECT_NAME}Targets" | ||
FILE "${PROJECT_NAME}Targets.cmake" | ||
#NAMESPACE ${PROJECT_NAME}:: | ||
DESTINATION "${CONFIG_PACKAGE_INSTALL_LOCATION}" | ||
) | ||
install( | ||
FILES | ||
"${CONFIG_PACKAGE_BUILD_LOCATION}/${PROJECT_NAME}Config.cmake" | ||
"${CONFIG_PACKAGE_BUILD_LOCATION}/${PROJECT_NAME}ConfigVersion.cmake" | ||
DESTINATION "${CONFIG_PACKAGE_INSTALL_LOCATION}" | ||
) | ||
|
||
add_subdirectory(test) |
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
include("${CMAKE_CURRENT_LIST_DIR}/@[email protected]") |
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 |
---|---|---|
@@ -0,0 +1,32 @@ | ||
cmake_minimum_required(VERSION 2.8.12) | ||
|
||
project(rang-test) | ||
|
||
set(CMAKE_CXX_STANDARD 11 ) | ||
set(CMAKE_CXX_STANDARD_REQUIRED ON ) | ||
set(CMAKE_CXX_EXTENSIONS OFF) | ||
|
||
function(rang_add_test file_name) | ||
add_executable("${file_name}" "${file_name}.cpp") | ||
target_link_libraries("${file_name}" rang) | ||
endfunction() | ||
|
||
# simple tests ################################################################# | ||
|
||
rang_add_test(colorTest) | ||
rang_add_test(envTermMissing) | ||
|
||
# test that uses doctest ####################################################### | ||
|
||
set(doctest_DIR "" CACHE PATH "Directory containing doctestConfig.cmake") | ||
find_package(doctest) | ||
|
||
if (${doctest_FOUND} EQUAL 1) | ||
add_executable(all_rang_tests "test.cpp") | ||
target_link_libraries(all_rang_tests rang doctest::doctest) | ||
|
||
enable_testing() | ||
|
||
# cd build_dir && ctest --test-command all_tests | ||
add_test(NAME all_tests COMMAND "$<TARGET_FILE:all_rang_tests>") | ||
endif() |