Skip to content

Commit

Permalink
Merge pull request #9 from terasakisatoshi/terasaki/omikuji
Browse files Browse the repository at this point in the history
Terasaki/omikuji
  • Loading branch information
terasakisatoshi authored May 26, 2024
2 parents d1f55b1 + fc6e543 commit 3d8a283
Show file tree
Hide file tree
Showing 11 changed files with 166 additions and 0 deletions.
46 changes: 46 additions & 0 deletions .github/workflows/omikuji.yml
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,4 @@
*.app

**/build
.DS_Store
63 changes: 63 additions & 0 deletions omikuji/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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"
)
3 changes: 3 additions & 0 deletions omikuji/Config.cmake.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
@PACKAGE_INIT@

include ( "${CMAKE_CURRENT_LIST_DIR}/OmikujiTargets.cmake" )
4 changes: 4 additions & 0 deletions omikuji/app/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
find_package(Omikuji REQUIRED)

add_executable(main main.cpp)
target_link_libraries(main Omikuji::drawing)
3 changes: 3 additions & 0 deletions omikuji/app/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
rm -rf ./build
cmake -S . -B ./build -DCMAKE_PREFIX_PATH=../goma
cmake --build ./build
7 changes: 7 additions & 0 deletions omikuji/app/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#include<iostream>
#include "drawing.hpp"

int main(){
std::cout << draw() << std::endl;
return 0;
}
4 changes: 4 additions & 0 deletions omikuji/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
rm -rf build ${PWD}/goma
cmake -S . -B ./build
cmake --build ./build --config=Release
cmake --install ./build --prefix=${PWD}/goma
18 changes: 18 additions & 0 deletions omikuji/src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
add_library(drawing drawing.cpp)

target_include_directories(drawing
INTERFACE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
$<INSTALL_INTERFACE:include>
)
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)
13 changes: 13 additions & 0 deletions omikuji/src/drawing.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#include<string>
#include<random>
#include "drawing.hpp"

std::string draw(){
std::random_device seed_gen;
std::mt19937 rng(seed_gen());

std::vector<std::string> 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];
}
4 changes: 4 additions & 0 deletions omikuji/src/drawing.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#include<string>
#pragma once

std::string draw();

0 comments on commit 3d8a283

Please sign in to comment.