diff --git a/CMakeLists.txt b/CMakeLists.txt index cb336f8..f311fe4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,8 +1,12 @@ cmake_minimum_required(VERSION 3.15...3.19) + project( - Matchit + "matchit" VERSION 1.0.0 - LANGUAGES CXX) + LANGUAGES CXX + DESCRIPTION + "match(it): A lightweight single-header pattern-matching library for C++17 with macro-free APIs." + HOMEPAGE_URL "https://github.com/BowenFu/matchit.cpp") list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake") @@ -29,10 +33,17 @@ if (CMAKE_BUILD_TYPE STREQUAL "MSAN") add_link_options("-L${PROJECT_SOURCE_DIR}/libcxx_msan/lib;-lc++abi") endif() #CMAKE_BUILD_TYPE STREQUAL "MSAN" +include(GNUInstallDirs) + # Target. add_library(matchit INTERFACE) -target_include_directories(matchit INTERFACE - ${PROJECT_SOURCE_DIR}/include) + +target_include_directories( + matchit + INTERFACE $ + $) + +target_compile_features(matchit INTERFACE cxx_std_17) if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME) include(Sanitizers) @@ -42,3 +53,37 @@ if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME) add_subdirectory(sample) endif() endif() + + +install( + TARGETS matchit + EXPORT matchitTargets + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} + RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) + +install(DIRECTORY ${PROJECT_SOURCE_DIR}/include/ + DESTINATION include) + +install( + EXPORT matchitTargets + FILE matchitTargets.cmake + NAMESPACE matchit:: + DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/matchit) + +configure_file(${PROJECT_SOURCE_DIR}/cmake/matchitConfig.cmake.in + matchitConfig.cmake @ONLY) + +include(CMakePackageConfigHelpers) +write_basic_package_version_file( + matchitConfigVersion.cmake + VERSION ${PACKAGE_VERSION} + COMPATIBILITY SameMajorVersion) + +install(FILES ${CMAKE_CURRENT_BINARY_DIR}/matchitConfig.cmake + ${CMAKE_CURRENT_BINARY_DIR}/matchitConfigVersion.cmake + DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/matchit) + +install( + FILES ${PROJECT_SOURCE_DIR}/LICENSE + DESTINATION ${CMAKE_INSTALL_DOCDIR}) diff --git a/README.md b/README.md index 7b139ab..29cc124 100644 --- a/README.md +++ b/README.md @@ -38,11 +38,17 @@ ### Option 1. Download `matchit.h` -Simply download the header file `matchit.h` and put it in your include directory for dependencies. +Simply download the header file [`matchit.h`](https://raw.githubusercontent.com/BowenFu/matchit.cpp/main/include/matchit.h) and put it in your include directory for dependencies. That's it. -### Option 2. Manage with cmake +You can download via this bash command + +```bash +wget https://raw.githubusercontent.com/BowenFu/matchit.cpp/main/include/matchit.h +``` + +### Option 2. Manage with cmake FetchContent Include the code snippet in your CMakeLists.txt: @@ -66,6 +72,24 @@ message(STATUS "Matchit header are present at ${matchit_SOURCE_DIR}") And add `${matchit_SOURCE_DIR}/include` to your include path. +### Option 3. Manage with cmake find_package + +Clone the repo via +``` +git clone --depth 1 https://github.com/BowenFu/matchit.cpp +``` + +Install the library via +``` +cd matchit.cpp +cmake -B ./build +cd build +make install +``` + +Then use find_package in your CMakeLists.txt. + + ## Syntax Design For syntax design details please refer to [REFERENCE](./REFERENCE.md). diff --git a/cmake/matchitConfig.cmake.in b/cmake/matchitConfig.cmake.in new file mode 100644 index 0000000..31996d1 --- /dev/null +++ b/cmake/matchitConfig.cmake.in @@ -0,0 +1,3 @@ +if(NOT TARGET domifair::@PROJECT_NAME@) + include("${CMAKE_CURRENT_LIST_DIR}/@PROJECT_NAME@Targets.cmake") +endif()