From 367ace996e1b2cd0fe40cf457ff31980c7c619ff Mon Sep 17 00:00:00 2001 From: Ravenwater Date: Mon, 8 Jul 2024 08:25:11 -0400 Subject: [PATCH] Adding example project and cmake build process --- CMakeLists.txt | 42 ++++++++++++++++++++++++++++++++++++++ src/CMakeLists.txt | 6 ++++++ src/example/CMakeLists.txt | 20 ++++++++++++++++++ src/example/example.cpp | 32 +++++++++++++++++++++++++++++ 4 files changed, 100 insertions(+) create mode 100644 CMakeLists.txt create mode 100644 src/CMakeLists.txt create mode 100644 src/example/CMakeLists.txt create mode 100644 src/example/example.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..08faebd --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,42 @@ +cmake_minimum_required(VERSION 3) + +project(starter + DESCRIPTION "a starter repo for building Universal applications" + VERSION "0.0.1" + LANGUAGES C CXX ASM + HOMEPAGE_URL "https://github.com/stillwater-sc/universal") + +set(CMAKE_CXX_STANDARD 20) +set(CMAKE_CXX_STANDARD_REQUIRED ON) + +find_package(Boost) +if(Boost_FOUND) + message(STATUS "Boost_INCLUDE_DIR" ${Boost_INCLUDE_DIR}) + include_directories(${Boost_INCLUDE_DIR}) +endif(Boost_FOUND) + +set(STARTER_ROOT_DIR ${PROJECT_SOURCE_DIR}) +set(STARTER_INSTALL_INCLUDE_DIR ${PROJECT_SOURCE_DIR}/include) +set(STARTER_INSTALL_LIB_DIR ${PROJECT_SOURCE_DIR}/lib) +set(STARTER_INSTALL_BIN_DIR ${PROJECT_SOURCE_DIR}/bin) + +add_definitions(-D UNIVERSAL_ENABLE_TEST=OFF) + +# include file for common includes +include_directories(${STARTER_INSTALL_INCLUDE_DIR}) + +enable_testing() +#include(CTest) + +# Universal is a C++ header-only library, so we do not need to build anything +# if you do add this line, you will get all the Universal regression tests, +# playground, education, applications, and command line utilities. +# You can only add this build subdirectory to ONE and only ONE project +# within the starter workspace. Multiple includes will yield multiple definitions +# of build, install, and uninstall targets. +#add_subdirectory(${STARTER_ROOT_DIR}/ext/stillwater-sc/universal build_universal) + +# MTL4 is a C++ header-only library, so we do not need to build anything +#add_subdirectory(${STARTER_ROOT_DIR}/ext/stillwater-sc/mtl4 build_mtl4) + +add_subdirectory(src) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt new file mode 100644 index 0000000..3d7f497 --- /dev/null +++ b/src/CMakeLists.txt @@ -0,0 +1,6 @@ +cmake_minimum_required(VERSION 3.22) +project(starter_examples) + +# simple starter skeleton for projects that use the Universal Number System library +add_subdirectory(apps/example) + diff --git a/src/example/CMakeLists.txt b/src/example/CMakeLists.txt new file mode 100644 index 0000000..b514364 --- /dev/null +++ b/src/example/CMakeLists.txt @@ -0,0 +1,20 @@ +cmake_minimum_required(VERSION 3.22) +set(app_name example) +project(${app_name} CXX) + +# Universal is a C++ header-only library, so we do not need to build anything +include_directories(${STARTER_ROOT_DIR}/ext/stillwater-sc/universal/include) + +# source files that make up the command +set(SOURCE_FILES + example.cpp +) + +add_executable(${app_name} ${SOURCE_FILES}) +set(folder "Applications/Example") +set_target_properties(${app_name} PROPERTIES FOLDER ${folder}) + +# add libraries if you need them +#target_link_libraries(example required-library1 required-library2) +install(TARGETS ${app_name} DESTINATION ${STARTER_INSTALL_BIN_DIR}) +#install(FILES my-consolidated-include.hpp DESTINATION ${STARTER_INSTALL_INCLUDE_DIR}) diff --git a/src/example/example.cpp b/src/example/example.cpp new file mode 100644 index 0000000..d23268a --- /dev/null +++ b/src/example/example.cpp @@ -0,0 +1,32 @@ +#include +#include +#include + +#include +#include + +int main(int argc, char* argv) +try { + edecimal d, e, f; + + e = 1.0f; + f = 0xFFFF'FFFF'FFFF'FFFFull; + d = e + f; + + std::cout << d << std::endl; + + return EXIT_SUCCESS; + +} +catch (const char* msg) { + std::cerr << msg << std::endl; + return EXIT_FAILURE; +} +catch (const sw::universal::arithmetic_exception& err) { + std::cerr << "Unprocessed universal arithmetic exception: " << err.what() << std::endl; + return EXIT_FAILURE; +} +catch (...) { + std::cerr << "Caught unknown exception" << std::endl; + return EXIT_FAILURE; +}