diff --git a/CMakeLists.txt b/CMakeLists.txt index b1f27d7..b29af69 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -18,6 +18,7 @@ endif() # ---- Dependencies ---- +include(FetchContent) FetchContent_Declare( fast_float GIT_REPOSITORY https://github.com/red0124/fast_float.git @@ -25,6 +26,7 @@ FetchContent_Declare( GIT_SHALLOW TRUE) FetchContent_MakeAvailable(fast_float) +set(fast_float_source_dir "${FETCHCONTENT_BASE_DIR}/fast_float-src") # ---- Declare library ---- @@ -36,7 +38,7 @@ target_include_directories( ${ssp_warning_guard} INTERFACE "$" - fast_float + "$" ) target_compile_features(ssp INTERFACE cxx_std_17) @@ -47,3 +49,49 @@ target_link_libraries( "$<$,$,9.0>>:c++fs>" "$<$,$,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() diff --git a/README.md b/README.md index 41968cb..f27e771 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ Function traits taken from [qt-creator](https://code.woboq.org/qt5/qt-creator/sr # 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: -``` +```shell $ cat students.csv James Bailey,65,2.5 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: -``` +```shell $ ./a.out James Bailey 65 2.5 Brian S. Wolfe 40 1.9 @@ -59,6 +59,18 @@ Bill (Heath) Gates 65 3.3 * Conversions can be chained if invalid * 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 ## Conversions @@ -375,3 +387,39 @@ std::string s; std::cin >> s; int num = c.convert(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') +```