diff --git a/.github/workflows/omikuji.yml b/.github/workflows/omikuji.yml new file mode 100644 index 0000000..ee64332 --- /dev/null +++ b/.github/workflows/omikuji.yml @@ -0,0 +1,46 @@ +# This starter workflow is for a CMake project running on a single platform. There is a different starter workflow if you need cross-platform coverage. +# See: https://github.com/actions/starter-workflows/blob/main/ci/cmake-multi-platform.yml +name: omikuji + +on: + push: + branches: [ "main" ] + pull_request: + branches: [ "main" ] + paths: + - "./omikuji/*" + - ".github/workflows/omikuji.yml" + +env: + # Customize the CMake build type here (Release, Debug, RelWithDebInfo, etc.) + BUILD_TYPE: Release + +defaults: + run: + working-directory: ./omikuji + +jobs: + build: + # The CMake configure and build commands are platform agnostic and should work equally well on Windows or Mac. + # You can convert this to a matrix build if you need cross-platform coverage. + # See: https://docs.github.com/en/free-pro-team@latest/actions/learn-github-actions/managing-complex-workflows#using-a-build-matrix + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + + - name: Configure CMake + # Configure CMake in a 'build' subdirectory. `CMAKE_BUILD_TYPE` is only required if you are using a single-configuration generator such as make. + # See https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html?highlight=cmake_build_type + run: cmake -S . -B ./build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} + + - name: Build + # Build your program with the given configuration + run: cmake --build ./build --config ${{env.BUILD_TYPE}} + + - name: Install + run: cmake --install ./build --prefix ./goma + + - name: Test + working-directory: ${{github.workspace}}/omikuji/app + run: bash build.sh && ${{github.workspace}}/omikuji/app/build/main diff --git a/.gitignore b/.gitignore index 08e9f76..4ae2db8 100644 --- a/.gitignore +++ b/.gitignore @@ -32,3 +32,4 @@ *.app **/build +.DS_Store diff --git a/omikuji/CMakeLists.txt b/omikuji/CMakeLists.txt new file mode 100644 index 0000000..e3d1672 --- /dev/null +++ b/omikuji/CMakeLists.txt @@ -0,0 +1,63 @@ +cmake_minimum_required(VERSION 3.20) + +project(Omikuji VERSION 0.1.0) + +option(BUILD_SHARED_LIBS "Build using shared libraries" ON) + +if(APPLE) + set(CMAKE_INSTALL_RPATH "@executable_path/../lib") +elseif(UNIX) + set(CMAKE_INSTALL_RPATH "$ORIGIN/../lib") +endif() + +# libraries +add_library(${PROJECT_NAME}_compiler_flags INTERFACE) +target_compile_features(${PROJECT_NAME}_compiler_flags INTERFACE cxx_std_11) +add_subdirectory(src) +# applications +# add_subdirectory(app) + +# installation + +# setup installer +include(InstallRequiredSystemLibraries) +# set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/License.txt") +set(CPACK_PACKAGE_VERSION_MAJOR "${${PROJECT_NAME}_VERSION_MAJOR}") +set(CPACK_PACKAGE_VERSION_MINOR "${${PROJECT_NAME}_VERSION_MINOR}") +set(CPACK_SOURCE_GENERATOR "TGZ") +include(CPack) + +install(EXPORT ${PROJECT_NAME}Targets + FILE ${PROJECT_NAME}Targets.cmake + NAMESPACE Omikuji:: + DESTINATION lib/cmake/${PROJECT_NAME} +) + +include(CMakePackageConfigHelpers) +# generate the config file that is includes the exports +configure_package_config_file(${CMAKE_CURRENT_SOURCE_DIR}/Config.cmake.in + "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake" + INSTALL_DESTINATION "lib/cmake/${PROJECT_NAME}" + NO_SET_AND_CHECK_MACRO + NO_CHECK_REQUIRED_COMPONENTS_MACRO + ) + +# generate the version file for the config file +write_basic_package_version_file( + "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake" + VERSION "${${PROJECT_NAME}_VERSION_MAJOR}.${${PROJECT_NAME}_VERSION_MINOR}" + COMPATIBILITY AnyNewerVersion +) + +# install the configuration file +install(FILES + ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake + ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake + DESTINATION lib/cmake/${PROJECT_NAME} + ) + +# generate the export targets for the build tree +# needs to be after the install(TARGETS ) command +export(EXPORT ${PROJECT_NAME}Targets + FILE "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Targets.cmake" +) diff --git a/omikuji/Config.cmake.in b/omikuji/Config.cmake.in new file mode 100644 index 0000000..0620d21 --- /dev/null +++ b/omikuji/Config.cmake.in @@ -0,0 +1,3 @@ +@PACKAGE_INIT@ + +include ( "${CMAKE_CURRENT_LIST_DIR}/OmikujiTargets.cmake" ) diff --git a/omikuji/app/CMakeLists.txt b/omikuji/app/CMakeLists.txt new file mode 100644 index 0000000..fda23fc --- /dev/null +++ b/omikuji/app/CMakeLists.txt @@ -0,0 +1,4 @@ +find_package(Omikuji REQUIRED) + +add_executable(main main.cpp) +target_link_libraries(main Omikuji::drawing) diff --git a/omikuji/app/build.sh b/omikuji/app/build.sh new file mode 100644 index 0000000..e94f620 --- /dev/null +++ b/omikuji/app/build.sh @@ -0,0 +1,3 @@ +rm -rf ./build +cmake -S . -B ./build -DCMAKE_PREFIX_PATH=../goma +cmake --build ./build diff --git a/omikuji/app/main.cpp b/omikuji/app/main.cpp new file mode 100644 index 0000000..1024a87 --- /dev/null +++ b/omikuji/app/main.cpp @@ -0,0 +1,7 @@ +#include +#include "drawing.hpp" + +int main(){ + std::cout << draw() << std::endl; + return 0; +} diff --git a/omikuji/build.sh b/omikuji/build.sh new file mode 100644 index 0000000..ab795c8 --- /dev/null +++ b/omikuji/build.sh @@ -0,0 +1,4 @@ +rm -rf build ${PWD}/goma +cmake -S . -B ./build +cmake --build ./build --config=Release +cmake --install ./build --prefix=${PWD}/goma diff --git a/omikuji/src/CMakeLists.txt b/omikuji/src/CMakeLists.txt new file mode 100644 index 0000000..7d77070 --- /dev/null +++ b/omikuji/src/CMakeLists.txt @@ -0,0 +1,18 @@ +add_library(drawing drawing.cpp) + +target_include_directories(drawing + INTERFACE + $ + $ + ) +target_link_libraries(drawing PUBLIC ${PROJECT_NAME}_compiler_flags) + +set_property(TARGET drawing PROPERTY VERSION "0.1.0") +set_property(TARGET drawing PROPERTY SOVERSION "0.1.0") + +set(installable_libs drawing ${PROJECT_NAME}_compiler_flags) +install(TARGETS ${installable_libs} + EXPORT ${PROJECT_NAME}Targets + DESTINATION lib) + +install(FILES drawing.hpp DESTINATION include) diff --git a/omikuji/src/drawing.cpp b/omikuji/src/drawing.cpp new file mode 100644 index 0000000..443961d --- /dev/null +++ b/omikuji/src/drawing.cpp @@ -0,0 +1,13 @@ +#include +#include +#include "drawing.hpp" + +std::string draw(){ + std::random_device seed_gen; + std::mt19937 rng(seed_gen()); + + std::vector slips = {"Very good luck", "Good luck", "Bad luck", "Extremely bad luck"}; + std::uniform_int_distribution<> dist_n(0, slips.size()-1); + int n = dist_n(rng); + return slips[n]; +} diff --git a/omikuji/src/drawing.hpp b/omikuji/src/drawing.hpp new file mode 100644 index 0000000..5924295 --- /dev/null +++ b/omikuji/src/drawing.hpp @@ -0,0 +1,4 @@ +#include +#pragma once + +std::string draw();