Skip to content

Commit 52112e3

Browse files
authored
Fix #76: Add install config to cmake (#77)
* Add install config to cmake * Fix install * Update README. * Fix readme Co-authored-by: Bowen Fu <missing>
1 parent ac721e3 commit 52112e3

File tree

3 files changed

+78
-6
lines changed

3 files changed

+78
-6
lines changed

CMakeLists.txt

Lines changed: 49 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
cmake_minimum_required(VERSION 3.15...3.19)
2+
23
project(
3-
Matchit
4+
"matchit"
45
VERSION 1.0.0
5-
LANGUAGES CXX)
6+
LANGUAGES CXX
7+
DESCRIPTION
8+
"match(it): A lightweight single-header pattern-matching library for C++17 with macro-free APIs."
9+
HOMEPAGE_URL "https://github.com/BowenFu/matchit.cpp")
610

711
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake")
812

@@ -29,10 +33,17 @@ if (CMAKE_BUILD_TYPE STREQUAL "MSAN")
2933
add_link_options("-L${PROJECT_SOURCE_DIR}/libcxx_msan/lib;-lc++abi")
3034
endif() #CMAKE_BUILD_TYPE STREQUAL "MSAN"
3135

36+
include(GNUInstallDirs)
37+
3238
# Target.
3339
add_library(matchit INTERFACE)
34-
target_include_directories(matchit INTERFACE
35-
${PROJECT_SOURCE_DIR}/include)
40+
41+
target_include_directories(
42+
matchit
43+
INTERFACE $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
44+
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>)
45+
46+
target_compile_features(matchit INTERFACE cxx_std_17)
3647

3748
if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME)
3849
include(Sanitizers)
@@ -42,3 +53,37 @@ if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME)
4253
add_subdirectory(sample)
4354
endif()
4455
endif()
56+
57+
58+
install(
59+
TARGETS matchit
60+
EXPORT matchitTargets
61+
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
62+
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
63+
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
64+
65+
install(DIRECTORY ${PROJECT_SOURCE_DIR}/include/
66+
DESTINATION include)
67+
68+
install(
69+
EXPORT matchitTargets
70+
FILE matchitTargets.cmake
71+
NAMESPACE matchit::
72+
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/matchit)
73+
74+
configure_file(${PROJECT_SOURCE_DIR}/cmake/matchitConfig.cmake.in
75+
matchitConfig.cmake @ONLY)
76+
77+
include(CMakePackageConfigHelpers)
78+
write_basic_package_version_file(
79+
matchitConfigVersion.cmake
80+
VERSION ${PACKAGE_VERSION}
81+
COMPATIBILITY SameMajorVersion)
82+
83+
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/matchitConfig.cmake
84+
${CMAKE_CURRENT_BINARY_DIR}/matchitConfigVersion.cmake
85+
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/matchit)
86+
87+
install(
88+
FILES ${PROJECT_SOURCE_DIR}/LICENSE
89+
DESTINATION ${CMAKE_INSTALL_DOCDIR})

README.md

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,17 @@
3838

3939
### Option 1. Download `matchit.h`
4040

41-
Simply download the header file `matchit.h` and put it in your include directory for dependencies.
41+
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.
4242

4343
That's it.
4444

45-
### Option 2. Manage with cmake
45+
You can download via this bash command
46+
47+
```bash
48+
wget https://raw.githubusercontent.com/BowenFu/matchit.cpp/main/include/matchit.h
49+
```
50+
51+
### Option 2. Manage with cmake FetchContent
4652

4753
Include the code snippet in your CMakeLists.txt:
4854

@@ -66,6 +72,24 @@ message(STATUS "Matchit header are present at ${matchit_SOURCE_DIR}")
6672

6773
And add `${matchit_SOURCE_DIR}/include` to your include path.
6874

75+
### Option 3. Manage with cmake find_package
76+
77+
Clone the repo via
78+
```
79+
git clone --depth 1 https://github.com/BowenFu/matchit.cpp
80+
```
81+
82+
Install the library via
83+
```
84+
cd matchit.cpp
85+
cmake -B ./build
86+
cd build
87+
make install
88+
```
89+
90+
Then use find_package in your CMakeLists.txt.
91+
92+
6993
## Syntax Design
7094

7195
For syntax design details please refer to [REFERENCE](./REFERENCE.md).

cmake/matchitConfig.cmake.in

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
if(NOT TARGET domifair::@PROJECT_NAME@)
2+
include("${CMAKE_CURRENT_LIST_DIR}/@[email protected]")
3+
endif()

0 commit comments

Comments
 (0)