Skip to content

Commit

Permalink
Clang compiler, libc++ and modules
Browse files Browse the repository at this point in the history
- Added support for Clang compiler
- Added support for llvm's libc++
- Initial improvemets for c++ modules support (inline instead of static)

Signed-off-by: Matteo De Carlo <[email protected]>
  • Loading branch information
portaloffreedom committed Jan 4, 2024
1 parent 26ae5cf commit 8f3f61b
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 23 deletions.
14 changes: 14 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ cmake_minimum_required(VERSION 3.8)
set(WICKED_ROOT_DIR ${CMAKE_CURRENT_SOURCE_DIR})

option(WICKED_DYNAMIC_LIBRARY "Build WickedEngine as a dynamic library" OFF)
option(USE_LIBCXX "Link WickedEngine to llvm libc++ library - only available with the Clang compiler" OFF)

option(WICKED_EDITOR "Build WickedEngine editor" ON)
option(WICKED_TESTS "Build WickedEngine tests" ON)
Expand Down Expand Up @@ -31,6 +32,19 @@ elseif(UNIX)
set(DXC_TARGET "dxc")
endif()


if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fdeclspec -fms-extensions")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} $<$<NOT:$<WICKED_DYNAMIC_LIBRARY>>:--for-linker=-no-pie>" )
if (USE_LIBCXX)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -stdlib=libc++ -lc++abi")
endif()
elseif (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
else()
endif()


add_subdirectory(WickedEngine)

if (WICKED_EDITOR)
Expand Down
14 changes: 14 additions & 0 deletions WickedEngine/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,19 @@ else ()
)
set(WICKEDENGINE_STATIC_LIBRARIES ${WICKEDENGINE_STATIC_LIBRARIES} FAudio)

if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
target_compile_options(${TARGET_NAME} PRIVATE
-Wuninitialized
#-Wwrite-strings
#-Winit-self
#-Wreturn-type
#-Wreorder
#-Werror=delete-non-virtual-dtor
#-Werror
#uncomment this to stop the compilation at the first error
# -Wfatal-errors
)
elseif (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
# add some warnings and set them as errors
# read more details here: https://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html
target_compile_options(${TARGET_NAME} PRIVATE
Expand All @@ -270,6 +283,7 @@ else ()
#uncomment this to stop the compilation at the first error
# -Wfatal-errors
)
endif()

target_link_libraries(${TARGET_NAME} PRIVATE dl)

Expand Down
12 changes: 4 additions & 8 deletions WickedEngine/sdl2.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,10 @@ namespace sdl2 {
// Very useful function from Eric Scott Barr:
// https://eb2.co/blog/2014/04/c-plus-plus-14-and-sdl2-managing-resources/
template <typename Creator, typename Destructor, typename... Arguments>
auto make_resource(Creator c, Destructor d, Arguments&&... args)
inline auto make_resource(Creator c, Destructor d, Arguments&&... args)
{
using std::decay_t;
using std::forward;
using std::unique_ptr;

auto r = c(forward<Arguments>(args)...);
return unique_ptr<decay_t<decltype(*r)>, decltype(d)>(r, d);
auto r = c(std::forward<Arguments>(args)...);
return std::unique_ptr<std::decay_t<decltype(*r)>, decltype(d)>(r, d);
}

// The "internal type" of the SDL System
Expand Down Expand Up @@ -99,7 +95,7 @@ class SDLError : public std::exception
{
return error_message.c_str();
}

};

} // namespace sdl2
8 changes: 4 additions & 4 deletions WickedEngine/wiECS.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ namespace wi::ecs
// The entity can be a different value on a different run of the application, if it was serialized
// It must be only serialized with the SerializeEntity() function. It will ensure that entities still match with their components correctly after serialization
using Entity = uint32_t;
static const Entity INVALID_ENTITY = 0;
inline constexpr Entity INVALID_ENTITY = 0;
// Runtime can create a new entity with this
inline Entity CreateEntity()
{
Expand Down Expand Up @@ -98,7 +98,7 @@ namespace wi::ecs
}
}

// This is an interface class to implement a ComponentManager,
// This is an interface class to implement a ComponentManager,
// inherit this class if you want to work with ComponentLibrary
class ComponentManager_Interface
{
Expand Down Expand Up @@ -152,7 +152,7 @@ namespace wi::ecs
lookup = other.lookup;
}

// Merge in an other component manager of the same type to this.
// Merge in an other component manager of the same type to this.
// The other component manager MUST NOT contain any of the same entities!
// The other component manager is not retained after this operation!
inline void Merge(ComponentManager<Component>& other)
Expand Down Expand Up @@ -399,7 +399,7 @@ namespace wi::ecs
}

// Retrieve component index by entity handle (if not exists, returns ~0ull value)
inline size_t GetIndex(Entity entity) const
inline size_t GetIndex(Entity entity) const
{
if (lookup.empty())
return ~0ull;
Expand Down
6 changes: 3 additions & 3 deletions WickedEngine/wiEventHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@

namespace wi::eventhandler
{
static constexpr int EVENT_THREAD_SAFE_POINT = -1;
static constexpr int EVENT_RELOAD_SHADERS = -2;
static constexpr int EVENT_SET_VSYNC = -3;
inline constexpr int EVENT_THREAD_SAFE_POINT = -1;
inline constexpr int EVENT_RELOAD_SHADERS = -2;
inline constexpr int EVENT_SET_VSYNC = -3;

struct Handle
{
Expand Down
16 changes: 8 additions & 8 deletions WickedEngine/wiMath.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

#if __has_include("DirectXMath.h")
// In this case, DirectXMath is coming from Windows SDK.
// It is better to use this on Windows as some Windows libraries could depend on the same
// It is better to use this on Windows as some Windows libraries could depend on the same
// DirectXMath headers
#include <DirectXMath.h>
#include <DirectXPackedVector.h>
Expand All @@ -29,8 +29,8 @@ using namespace DirectX::PackedVector;

namespace wi::math
{
static constexpr XMFLOAT4X4 IDENTITY_MATRIX = XMFLOAT4X4(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1);
static constexpr float PI = XM_PI;
inline constexpr XMFLOAT4X4 IDENTITY_MATRIX = XMFLOAT4X4(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1);
inline constexpr float PI = XM_PI;

inline bool float_equal(float f1, float f2) {
return (std::abs(f1 - f2) <= std::numeric_limits<float>::epsilon() * std::max(std::abs(f1), std::abs(f2)));
Expand Down Expand Up @@ -395,12 +395,12 @@ namespace wi::math


//-----------------------------------------------------------------------------
// Compute the intersection of a ray (Origin, Direction) with a triangle
// (V0, V1, V2). Return true if there is an intersection and also set *pDist
// Compute the intersection of a ray (Origin, Direction) with a triangle
// (V0, V1, V2). Return true if there is an intersection and also set *pDist
// to the distance along the ray to the intersection.
//
// The algorithm is based on Moller, Tomas and Trumbore, "Fast, Minimum Storage
// Ray-Triangle Intersection", Journal of Graphics Tools, vol. 2, no. 1,
//
// The algorithm is based on Moller, Tomas and Trumbore, "Fast, Minimum Storage
// Ray-Triangle Intersection", Journal of Graphics Tools, vol. 2, no. 1,
// pp 21-28, 1997.
//
// Modified for WickedEngine to return barycentrics and support TMin, TMax
Expand Down

0 comments on commit 8f3f61b

Please sign in to comment.