Skip to content

Commit

Permalink
Adding example project and cmake build process
Browse files Browse the repository at this point in the history
  • Loading branch information
Ravenwater committed Jul 8, 2024
1 parent f6e9529 commit 367ace9
Show file tree
Hide file tree
Showing 4 changed files with 100 additions and 0 deletions.
42 changes: 42 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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)
6 changes: 6 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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)

20 changes: 20 additions & 0 deletions src/example/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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})
32 changes: 32 additions & 0 deletions src/example/example.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#include <iostream>
#include <iomanip>
#include <cmath>

#include <universal/number/edecimal/edecimal.hpp>
#include <universal/number/fixpnt/fixpnt.hpp>

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;
}

0 comments on commit 367ace9

Please sign in to comment.