Skip to content

Commit

Permalink
Transformed into a separately compiled library/removed support for he…
Browse files Browse the repository at this point in the history
…ader-only usage/inclusion.

Added CMake integration/project files.
Removed redundant/no longer relevant function attributes.
Cleanedup/replaced ifdef inclusion guards with simple pragma once.
Fixed compilation errors introduced in the previous commits on this branch.
Various other cleanups and stylistic changes.
  • Loading branch information
psiha committed Jan 12, 2024
1 parent 0427844 commit 82aba42
Show file tree
Hide file tree
Showing 67 changed files with 675 additions and 1,279 deletions.
116 changes: 61 additions & 55 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,7 @@ cmake_minimum_required( VERSION 3.27.0 )
project( vm )

###################
##### Target ######
###################

set(CMAKE_CXX_STANDARD 23)

# TODO: Use psiha/build cmake utils?

file( GLOB_RECURSE vm_sources "${PROJECT_SOURCE_DIR}/include/*" )
add_library( vm STATIC ${vm_sources} )
target_include_directories( vm PUBLIC "${PROJECT_SOURCE_DIR}/include/" )
target_compile_features( vm PRIVATE cxx_std_23 )

###################
###### Deps #######
## Deps
###################

# Download CPM.cmake
Expand All @@ -27,57 +14,76 @@ file(
${CMAKE_CURRENT_BINARY_DIR}/cmake/CPM.cmake
EXPECTED_HASH SHA256=cc155ce02e7945e7b8967ddfaff0b050e958a723ef7aad3766d368940cb15494
)
set(CPM_SOURCE_CACHE "${CMAKE_CURRENT_BINARY_DIR}/deps") # Using this ensures shallow clones
include(${CMAKE_CURRENT_BINARY_DIR}/cmake/CPM.cmake)
set( CPM_SOURCE_CACHE "${CMAKE_CURRENT_BINARY_DIR}/deps" ) # Using this ensures shallow clones
include( ${CMAKE_CURRENT_BINARY_DIR}/cmake/CPM.cmake )


# Add packages

CPMAddPackage("gh:boostorg/static_assert#boost-1.84.0") # Boost::core dependency
CPMAddPackage("gh:boostorg/throw_exception#boost-1.84.0") # Boost::core dependency
CPMAddPackage("gh:boostorg/config#boost-1.84.0") # Boost::core dependency
CPMAddPackage("gh:boostorg/io#boost-1.84.0") # Boost::utility dependency
CPMAddPackage("gh:boostorg/type_traits#boost-1.84.0") # Boost::utility dependency
CPMAddPackage("gh:boostorg/predef#boost-1.84.0") # Boost::winapi dependency
CPMAddPackage("gh:boostorg/assert#boost-1.84.0")
CPMAddPackage("gh:boostorg/core#boost-1.84.0")
CPMAddPackage("gh:boostorg/preprocessor#boost-1.84.0")
CPMAddPackage("gh:boostorg/winapi#boost-1.84.0")
CPMAddPackage("gh:boostorg/utility#boost-1.84.0")

CPMAddPackage("gh:psiha/config_ex#master")
CPMAddPackage("gh:psiha/std_fix#master")
CPMAddPackage("gh:psiha/err#master")
CPMAddPackage("gh:psiha/build#master")

CPMAddPackage("gh:google/[email protected]")

# Link & include

target_link_libraries( vm PRIVATE
Boost::core
Boost::assert
Boost::preprocessor
Boost::winapi
Boost::utility
set( boost_ver boost-1.84.0 )
CPMAddPackage( "gh:boostorg/static_assert#${boost_ver}" ) # Boost::core dependency
CPMAddPackage( "gh:boostorg/throw_exception#${boost_ver}" ) # Boost::core dependency
CPMAddPackage( "gh:boostorg/config#${boost_ver}" ) # Boost::core dependency
CPMAddPackage( "gh:boostorg/io#${boost_ver}" ) # Boost::utility dependency
CPMAddPackage( "gh:boostorg/type_traits#${boost_ver}" ) # Boost::utility dependency
CPMAddPackage( "gh:boostorg/predef#${boost_ver}" ) # Boost::winapi dependency
CPMAddPackage( "gh:boostorg/assert#${boost_ver}" )
CPMAddPackage( "gh:boostorg/core#${boost_ver}" )
CPMAddPackage( "gh:boostorg/preprocessor#${boost_ver}" )
CPMAddPackage( "gh:boostorg/winapi#${boost_ver}" )
CPMAddPackage( "gh:boostorg/utility#${boost_ver}" )

CPMAddPackage( "gh:psiha/config_ex#master" )
CPMAddPackage( "gh:psiha/std_fix#master" )
CPMAddPackage( "gh:psiha/err#master" )
CPMAddPackage( "gh:psiha/build#master" )

CPMAddPackage( "gh:google/[email protected]" )


include( ${build_SOURCE_DIR}/build_options.cmake )

PSI_add_compile_options( Debug ${PSI_compiler_runtime_sanity_checks} )
PSI_add_link_options ( Debug ${PSI_linker_runtime_sanity_checks} )

set( CMAKE_INTERPROCEDURAL_OPTIMIZATION_RELEASE true )
PSI_add_link_options ( Release ${PSI_linker_LTO} )
PSI_add_compile_options( Release ${PSI_compiler_LTO} ${PSI_compiler_optimize_for_size} ${PSI_compiler_disable_thread_safe_init} ${PSI_compiler_fastmath} ${PSI_compiler_debug_symbols} )

if ( WIN32 )
add_compile_definitions( WIN32_LEAN_AND_MEAN NOMINMAX NOCOMM )
endif()

###################
## Target(s)
###################

include( vm.cmake )

target_link_libraries( psi_vm PRIVATE
Boost::core
Boost::assert
Boost::preprocessor
Boost::winapi
Boost::utility
)

target_include_directories( vm PRIVATE
"${assert_SOURCE_DIR}/include"
"${core_SOURCE_DIR}/include"
"${preprocessor_SOURCE_DIR}/include"
"${winapi_SOURCE_DIR}/include"
"${utility_SOURCE_DIR}/include"
"${config_ex_SOURCE_DIR}/include"
"${std_fix_SOURCE_DIR}/include"
"${err_SOURCE_DIR}/include"
"${build_SOURCE_DIR}/include"
target_include_directories( psi_vm PRIVATE
"${assert_SOURCE_DIR}/include"
"${core_SOURCE_DIR}/include"
"${preprocessor_SOURCE_DIR}/include"
"${winapi_SOURCE_DIR}/include"
"${utility_SOURCE_DIR}/include"
"${config_ex_SOURCE_DIR}/include"
"${std_fix_SOURCE_DIR}/include"
"${err_SOURCE_DIR}/include"
"${build_SOURCE_DIR}/include"
)

###################
##### Testing #####
## Testing
###################

enable_testing()

add_subdirectory("${PROJECT_SOURCE_DIR}/test")
add_subdirectory( "${PROJECT_SOURCE_DIR}/test" )
15 changes: 0 additions & 15 deletions CMakeSettings.json

This file was deleted.

3 changes: 2 additions & 1 deletion include/psi/vm/align.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ namespace align_detail
#ifdef __clang__
[[ using gnu: const, always_inline ]] constexpr auto is_aligned( auto const value, auto const alignment ) noexcept { return __builtin_is_aligned( value, alignment ); }
#else
[[ using gnu: const, always_inline ]] constexpr auto is_aligned( auto const value, auto const alignment ) noexcept { return value % alignment == 0; }
[[ using gnu: const, always_inline ]] constexpr auto is_aligned( auto const value, auto const alignment ) noexcept { return value % alignment == 0; }
[[ using gnu: const, always_inline ]] constexpr auto is_aligned( auto * const ptr , auto const alignment ) noexcept { return is_aligned( reinterpret_cast<std::uintptr_t>( ptr ), alignment ); }
#endif
[[ using gnu: const, always_inline ]] constexpr auto align_down( auto const value, auto const alignment ) noexcept
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
#include <sys/mman.h>
#endif // OS

#include "../span.hpp"
#include <psi/vm/span.hpp>

#include <cstddef>
#include <cstdint>
Expand Down Expand Up @@ -55,7 +55,7 @@ inline std::uint32_t constexpr reserve_granularity{ 64 * 1024 };

#else // POSIX

enum class allocation_type
enum class allocation_type : int
{
reserve = PROT_NONE,
commit = PROT_READ | PROT_WRITE
Expand Down
47 changes: 0 additions & 47 deletions include/psi/vm/amalgamated_lib.cpp

This file was deleted.

28 changes: 0 additions & 28 deletions include/psi/vm/detail/impl_inline.hpp

This file was deleted.

43 changes: 21 additions & 22 deletions include/psi/vm/detail/impl_selection.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,40 +14,40 @@
///
////////////////////////////////////////////////////////////////////////////////
//------------------------------------------------------------------------------
#ifndef impl_selection_hpp__05AF14B5_B23B_4CB8_A253_FD2D07B37ECF
#define impl_selection_hpp__05AF14B5_B23B_4CB8_A253_FD2D07B37ECF
#pragma once
//------------------------------------------------------------------------------
#include <boost/config.hpp>
#include <boost/preprocessor/cat.hpp>

#include <boost/preprocessor/stringize.hpp>

// Implementation note:
// "Anti-pattern" forward includes to reduce the verbosity of files that
// include this header.
// Required for PSI_VM_DIR_IMPL_INCLUDE users.
// (26.08.2011.) (Domagoj Saric)
#include <boost/preprocessor/facilities/empty.hpp>
#include <boost/preprocessor/facilities/identity.hpp>
//------------------------------------------------------------------------------
#if !defined( PSI_VM_IMPL )
#if defined( _WIN32 )
#define PSI_VM_IMPL() win32
#elif defined( _WIN32_WINNT )
#define PSI_VM_IMPL() nt
#elif defined( BOOST_HAS_UNISTD_H )
#define PSI_VM_IMPL() posix
#define PSI_VM_POSIX_INLINE inline
#else
#define PSI_VM_IMPL() xsi
#endif
# if defined( _WIN32 )
# define PSI_VM_IMPL() win32
# elif defined( _WIN32_WINNT )
# define PSI_VM_IMPL() nt
# elif __has_include( <unistd.h> )
# define PSI_VM_IMPL() posix
# define PSI_VM_POSIX_INLINE inline
# else
# define PSI_VM_IMPL() xsi
# endif
#endif // !defined( PSI_VM_IMPL )

#ifndef PSI_VM_POSIX_INLINE
#define PSI_VM_POSIX_INLINE
# define PSI_VM_POSIX_INLINE
#endif // PSI_VM_POSIX_INLINE

#define PSI_VM_IMPL_INCLUDE( prefix_path, include ) \
BOOST_PP_STRINGIZE( prefix_path()PSI_VM_IMPL()include() )
#define PSI_VM_DIR_IMPL_INCLUDE( include ) \
BOOST_PP_STRINGIZE( PSI_VM_IMPL()/include() )

#define PSI_VM_DIR_IMPL_PREFIXED_INCLUDE( prefix_path, include ) \
BOOST_PP_STRINGIZE( prefix_path()/PSI_VM_IMPL()/include() )

#define PSI_VM_IMPL_INCLUDE( include ) \
BOOST_PP_STRINGIZE( include.PSI_VM_IMPL().hpp )
//------------------------------------------------------------------------------
namespace psi::vm
{
Expand All @@ -58,4 +58,3 @@ inline namespace PSI_VM_IMPL() {}
//------------------------------------------------------------------------------
} // namespace psi::vm
//------------------------------------------------------------------------------
#endif // impl_selection_hpp
Loading

0 comments on commit 82aba42

Please sign in to comment.