From 2b57981537ca04c3e713771f0ef731e71c38a938 Mon Sep 17 00:00:00 2001 From: Jeff Hutchison Date: Fri, 17 Jul 2020 19:06:17 -0400 Subject: [PATCH 1/4] Enable install via cmake --- .gitignore | 1 + CMakeLists.txt | 54 ++++++++++++++++++++++++++++++++++++ cmake/tinyfsmConfig.cmake.in | 4 +++ 3 files changed, 59 insertions(+) create mode 100644 .gitignore create mode 100644 CMakeLists.txt create mode 100644 cmake/tinyfsmConfig.cmake.in diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..378eac2 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +build diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..cd3d428 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,54 @@ +cmake_minimum_required(VERSION 3.10) + +project("tinyfsm" + VERSION 1.0.1 + DESCRIPTION "A simple C++ finite state machine library." + HOMEPAGE_URL "https://github.com/digint/tinyfsm" +) + +include(GNUInstallDirs) + +add_library(${PROJECT_NAME} INTERFACE) + +target_include_directories(${PROJECT_NAME} + INTERFACE + $ + $ +) + +target_compile_features(${PROJECT_NAME} INTERFACE cxx_std_11) + +install(TARGETS ${PROJECT_NAME} + EXPORT ${PROJECT_NAME}_Targets + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} + RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} +) + +include(CMakePackageConfigHelpers) + +write_basic_package_version_file( + "${PROJECT_NAME}ConfigVersion.cmake" + VERSION ${PROJECT_VERSION} + COMPATIBILITY SameMajorVersion +) + +configure_package_config_file( + "${PROJECT_SOURCE_DIR}/cmake/${PROJECT_NAME}Config.cmake.in" + "${PROJECT_BINARY_DIR}/${PROJECT_NAME}Config.cmake" + INSTALL_DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/${PROJECT_NAME}/cmake +) + +install( + EXPORT ${PROJECT_NAME}_Targets + FILE ${PROJECT_NAME}Targets.cmake + DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/${PROJECT_NAME}/cmake +) + +install( + FILES "${PROJECT_BINARY_DIR}/${PROJECT_NAME}Config.cmake" + "${PROJECT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake" + DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/${PROJECT_NAME}/cmake +) + +install(DIRECTORY ${PROJECT_SOURCE_DIR}/include/ DESTINATION include) \ No newline at end of file diff --git a/cmake/tinyfsmConfig.cmake.in b/cmake/tinyfsmConfig.cmake.in new file mode 100644 index 0000000..ff0fa67 --- /dev/null +++ b/cmake/tinyfsmConfig.cmake.in @@ -0,0 +1,4 @@ +@PACKAGE_INIT@ + +include("${CMAKE_CURRENT_LIST_DIR}/@PROJECT_NAME@Targets.cmake") +check_required_components("@PROJECT_NAME@") \ No newline at end of file From 88f5f02b6ed8705668d2ef6a75b8061efa06957a Mon Sep 17 00:00:00 2001 From: Jeff Hutchison Date: Fri, 17 Jul 2020 19:18:34 -0400 Subject: [PATCH 2/4] Add language to cmake project --- CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index cd3d428..dd18db0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,7 @@ cmake_minimum_required(VERSION 3.10) project("tinyfsm" + LANGUAGES CXX VERSION 1.0.1 DESCRIPTION "A simple C++ finite state machine library." HOMEPAGE_URL "https://github.com/digint/tinyfsm" From 80a6c26d75e5d249c45b8b525ffada0a9d4d668f Mon Sep 17 00:00:00 2001 From: Jeff Hutchison Date: Fri, 17 Jul 2020 19:24:12 -0400 Subject: [PATCH 3/4] Fix problem with cmake 3.10.2 --- CMakeLists.txt | 1 - 1 file changed, 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index dd18db0..44c1c97 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4,7 +4,6 @@ project("tinyfsm" LANGUAGES CXX VERSION 1.0.1 DESCRIPTION "A simple C++ finite state machine library." - HOMEPAGE_URL "https://github.com/digint/tinyfsm" ) include(GNUInstallDirs) From 10d10cc24cfc43e9b3b73b7c0c66b7aade071b9d Mon Sep 17 00:00:00 2001 From: Jeff Hutchison Date: Fri, 17 Jul 2020 19:42:45 -0400 Subject: [PATCH 4/4] Add cmake installation instructions --- README.md | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/README.md b/README.md index c2aa9af..274cc5c 100644 --- a/README.md +++ b/README.md @@ -46,6 +46,22 @@ Installation TinyFSM is a header-only library, no special installation steps are needed. Just point your compiler to the "include" directory. +Alternately, you could install the library using cmake. A typical install procedure is: +```bash +mkdir build +cd build +cmake .. +sudo cmake --build . --target install +``` + +In your project `CMakeLists.txt`, configure this library by including: +```cmake +find_package(tinyfsm) +target_link_libraries(${PROJECT_NAME} tinyfsm) +``` + +Hopefully this works on any OS. It should copy the library to the right os-specific location so you can succesfully `#include `. It will also create the cmake specific files that will allow you to use `find_package(tinyfsm)` in your cmake scripts. + Donate ------