Merge pull request #8 from red0124/feature/cmake_update

Feature/cmake update
This commit is contained in:
red0124 2021-02-07 16:17:38 +01:00 committed by GitHub
commit 22f8d5f139
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 99 additions and 3 deletions

View File

@ -18,6 +18,7 @@ endif()
# ---- Dependencies ---- # ---- Dependencies ----
include(FetchContent)
FetchContent_Declare( FetchContent_Declare(
fast_float fast_float
GIT_REPOSITORY https://github.com/red0124/fast_float.git GIT_REPOSITORY https://github.com/red0124/fast_float.git
@ -25,6 +26,7 @@ FetchContent_Declare(
GIT_SHALLOW TRUE) GIT_SHALLOW TRUE)
FetchContent_MakeAvailable(fast_float) FetchContent_MakeAvailable(fast_float)
set(fast_float_source_dir "${FETCHCONTENT_BASE_DIR}/fast_float-src")
# ---- Declare library ---- # ---- Declare library ----
@ -36,7 +38,7 @@ target_include_directories(
${ssp_warning_guard} ${ssp_warning_guard}
INTERFACE INTERFACE
"$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>" "$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>"
fast_float "$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/fast_float>"
) )
target_compile_features(ssp INTERFACE cxx_std_17) target_compile_features(ssp INTERFACE cxx_std_17)
@ -47,3 +49,49 @@ target_link_libraries(
"$<$<AND:$<CXX_COMPILER_ID:AppleClang,Clang>,$<VERSION_LESS:$<CXX_COMPILER_VERSION>,9.0>>:c++fs>" "$<$<AND:$<CXX_COMPILER_ID:AppleClang,Clang>,$<VERSION_LESS:$<CXX_COMPILER_VERSION>,9.0>>:c++fs>"
"$<$<AND:$<CXX_COMPILER_ID:GNU>,$<VERSION_LESS:$<CXX_COMPILER_VERSION>,9.1>>:stdc++fs>" "$<$<AND:$<CXX_COMPILER_ID:GNU>,$<VERSION_LESS:$<CXX_COMPILER_VERSION>,9.1>>:stdc++fs>"
) )
# ---- Install ----
include(CMakePackageConfigHelpers)
include(GNUInstallDirs)
set(ssp_directory "ssp-${PROJECT_VERSION}")
set(ssp_include_directory "${CMAKE_INSTALL_INCLUDEDIR}")
install(
DIRECTORY "${PROJECT_SOURCE_DIR}/include/" "${fast_float_source_dir}/include/"
DESTINATION "${ssp_include_directory}"
COMPONENT ssp_Development
)
install(
TARGETS ssp
EXPORT sspTargets
INCLUDES DESTINATION "${ssp_include_directory}"
)
write_basic_package_version_file(
ssp-config-version.cmake
COMPATIBILITY SameMajorVersion
ARCH_INDEPENDENT
)
set(ssp_install_cmakedir "${CMAKE_INSTALL_LIBDIR}/cmake/${ssp_directory}")
install(
FILES "${PROJECT_BINARY_DIR}/ssp-config-version.cmake"
DESTINATION "${ssp_install_cmakedir}"
COMPONENT ssp_Development
)
install(
EXPORT sspTargets
FILE ssp-config.cmake
NAMESPACE ssp::
DESTINATION "${ssp_install_cmakedir}"
COMPONENT ssp_Development
)
if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
include(CPack)
endif()

View File

@ -8,7 +8,7 @@ Function traits taken from [qt-creator](https://code.woboq.org/qt5/qt-creator/sr
# Example # Example
Lets say we have a csv file containing students in a given format (NAME,AGE,GRADE) and we want to parse and print all the valid values: Lets say we have a csv file containing students in a given format (NAME,AGE,GRADE) and we want to parse and print all the valid values:
``` ```shell
$ cat students.csv $ cat students.csv
James Bailey,65,2.5 James Bailey,65,2.5
Brian S. Wolfe,40,1.9 Brian S. Wolfe,40,1.9
@ -38,7 +38,7 @@ int main() {
} }
``` ```
And if we compile and execute the program we get the following output: And if we compile and execute the program we get the following output:
``` ```shell
$ ./a.out $ ./a.out
James Bailey 65 2.5 James Bailey 65 2.5
Brian S. Wolfe 40 1.9 Brian S. Wolfe 40 1.9
@ -59,6 +59,18 @@ Bill (Heath) Gates 65 3.3
* Conversions can be chained if invalid * Conversions can be chained if invalid
* Fast * Fast
# Installation
```shell
$ git clone https://github.com/red0124/ssp
$ cd ssp
$ cmake --configure .
$ sudo make install
```
*Note, this will also install the fast_float library*
The library supports [CMake](#Cmake) and [meson](#Meson) build systems
# Usage # Usage
## Conversions ## Conversions
@ -375,3 +387,39 @@ std::string s;
std::cin >> s; std::cin >> s;
int num = c.convert<int>(s.c_str()); int num = c.convert<int>(s.c_str());
``` ```
# Using as a project dependency
## CMake
If the repository is cloned within the CMake project, it can be added in the following way:
```cmake
add_subdirectory(ssp)
```
Alternatively, it can be fetched from the repository:
```cmake
include(FetchContent)
FetchContent_Declare(
ssp
GIT_REPOSITORY https://github.com/red0124/ssp.git
GIT_TAG origin/master
GIT_SHALLOW TRUE)
FetchContent_MakeAvailable(ssp)
```
Either way, after you prepare the target, you just have to invoke it in your project:
```cmake
target_link_libraries(project PUBLIC ssp)
```
## Meson
Create an *ssp.wrap* file in your *subprojects* directory with the following content:
```wrap
[wrap-git]
url = https://github.com/red0124/ssp
revision = origin/master
```
Then simply fetch the dependency and it is ready to be used:
```meson
ssp_sub = subproject('ssp')
ssp_dep = ssp_sub.get_variable('ssp_dep')
```