Fix MSVC support

This commit is contained in:
JackCarterSmith 2024-11-02 10:12:06 +01:00
parent 098345409f
commit f1a1c2199f
Signed by: JackCarterSmith
GPG Key ID: 832E52F4E23F8F24
6 changed files with 102 additions and 45 deletions

View File

@ -44,6 +44,7 @@ include(CheckCSourceCompiles)
find_package(SFML REQUIRED)
include_directories(sfml::sfml)
include_directories("3rdParty")
list(APPEND EXTLIBS "sfml::sfml")
# define src/headers files groups
include(srcs.list)
@ -55,6 +56,11 @@ endif()
# targets declarations
add_executable(${PROJECT_NAME})
set_target_properties(${PROJECT_NAME} PROPERTIES
OUTPUT_NAME ${PROJECT_NAME}${BUILDNAME_SUFFIX}
CXX_STANDARD 17
CXX_STANDARD_REQUIRED ON
)
target_precompile_headers(${PROJECT_NAME} PRIVATE
"$<$<COMPILE_LANGUAGE:CXX>:<string$<ANGLE-R>>"
"$<$<COMPILE_LANGUAGE:CXX>:<stdexcept$<ANGLE-R>>"
@ -70,22 +76,8 @@ target_sources(${PROJECT_NAME} PRIVATE
"${CMAKE_CURRENT_SOURCE_DIR}/Engine/Utils/3DMaths_mat.inl"
"${CMAKE_CURRENT_SOURCE_DIR}/Engine/Utils/3DMaths_bs.inl"
)
if(NOT MSVC)
target_compile_options(${PROJECT_NAME} PRIVATE -pg -ggdb3 -no-pie)
target_link_options(${PROJECT_NAME} PRIVATE -pg -ggdb3 -no-pie)
endif()
target_link_libraries(${PROJECT_NAME} -static gcc stdc++ pthread -dynamic sfml::sfml)
set_target_properties(${PROJECT_NAME} PROPERTIES
OUTPUT_NAME ${PROJECT_NAME}${BUILDNAME_SUFFIX}
CXX_STANDARD 17
CXX_STANDARD_REQUIRED ON
)
# targets build options
if(MSVC)
# msvc does not append 'lib' - do it here to have consistent name
set_target_properties(${PROJECT_NAME} PROPERTIES IMPORT_PREFIX "lib")
endif()
if(DISABLE_CPU_OPTI)
target_compile_definitions(${PROJECT_NAME} PUBLIC DISABLE_INTRINSICS)
else()
@ -94,6 +86,34 @@ else()
target_compile_definitions(${PROJECT_NAME} PUBLIC AVX2_INTRINSICS)
endif()
if(MSVC)
if(NOT DISABLE_CPU_OPTI)
list(APPEND LINKLIBS -LTCG -FORCE:MULTIPLE)
endif()
list(APPEND LINKLIBS -FORCE:MULTIPLE)
# msvc does not append 'lib' - do it here to have consistent name
set_target_properties(${PROJECT_NAME} PROPERTIES IMPORT_PREFIX "lib")
else()
# GCC profiler options
list(APPEND COMPOPTS -pg -ggdb3 -no-pie)
list(APPEND LINKOPTS -pg -ggdb3 -no-pie)
# static linking of stdlib
if(MINGW)
list(APPEND LINKLIBS -static gcc stdc++ pthread -dynamic)
else()
list(APPEND LINKLIBS -Wl,-Bstatic -lgcc -lstdc++ -lpthread -Wl,-Bdynamic)
endif()
endif()
list(APPEND LINKLIBS ${EXTLIBS})
target_compile_options(${PROJECT_NAME} PRIVATE ${COMPOPTS})
target_link_options(${PROJECT_NAME} PRIVATE ${LINKOPTS})
target_link_libraries(${PROJECT_NAME} ${LINKLIBS})
# GPG signature custom command
#add_custom_command(
# OUTPUT ""

View File

@ -119,7 +119,7 @@ void Graphic3DRenderer::Draw(sf::RenderTexture& context) {
{
size_t vCount = obj->GetObjectVerticesCount();
auto& oMesh = obj->GetObjectMesh();
M3D_F4 projVertices[vCount];
M3D_F4* projVertices = new M3D_F4[vCount];
// Vertices homogeneous clip space transformation
M3D_V3Transform(
@ -186,6 +186,8 @@ void Graphic3DRenderer::Draw(sf::RenderTexture& context) {
}
}
}
std::destroy_at(projVertices);
}
}
}

View File

@ -1,8 +1,6 @@
#pragma once
#include <cstdint>
#include <cmath>
#include <cfloat>
#ifndef DISABLE_INTRINSICS
// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#
// https://stackoverflow.com/tags/sse/info
@ -15,6 +13,21 @@
#error This header requires C++
#endif
#if defined(_MSC_VER) && (_MSC_VER < 1910)
#error M3D requires Visual C++ 2017 or later.
#endif
#ifdef _MSC_VER
#pragma warning(push)
#pragma warning(disable : 4987)
// C4987: Off by default noise
#endif
#include <cmath>
#include <cfloat>
#ifdef _MSC_VER
#pragma warning(pop)
#endif
#ifdef _MSC_VER
#define INLINE_AVX_FIX
#else
@ -62,14 +75,14 @@
#endif
#if __cplusplus >= 201703L
#define M3D_ALIGNED_DATA(x) alignas(x)
#define M3D_ALIGNED_STRUCT(x) struct alignas(x)
#define M3D_ALIGNED_DATA(x) alignas(x)
#define M3D_ALIGNED_STRUCT(x) struct alignas(x)
#elif defined(__GNUC__)
#define M3D_ALIGNED_DATA(x) __attribute__ ((aligned(x)))
#define M3D_ALIGNED_STRUCT(x) struct __attribute__ ((aligned(x)))
#define M3D_ALIGNED_DATA(x) __attribute__ ((aligned(x)))
#define M3D_ALIGNED_STRUCT(x) struct __attribute__ ((aligned(x)))
#else
#define M3D_ALIGNED_DATA(x) __declspec(align(x))
#define M3D_ALIGNED_STRUCT(x) __declspec(align(x)) struct
#define M3D_ALIGNED_DATA(x) __declspec(align(x))
#define M3D_ALIGNED_STRUCT(x) __declspec(align(x)) struct
#endif
//
@ -119,7 +132,7 @@ using M3D_VECTOR = sM3DV4;
using M3D_VECTOR = __m128;
#endif
struct __attribute__((aligned(16))) M3D_V4F32 {
M3D_ALIGNED_STRUCT(16) M3D_V4F32 {
union {
float f[4];
M3D_VECTOR v;
@ -133,7 +146,7 @@ struct __attribute__((aligned(16))) M3D_V4F32 {
#endif
};
struct __attribute__((aligned(16))) M3D_V4U8 {
M3D_ALIGNED_STRUCT(16) M3D_V4U8 {
union {
uint8_t u[16];
M3D_VECTOR v;
@ -147,7 +160,7 @@ struct __attribute__((aligned(16))) M3D_V4U8 {
#endif
};
struct __attribute__((aligned(16))) M3D_V4U32 {
M3D_ALIGNED_STRUCT(16) M3D_V4U32 {
union {
uint32_t u[4];
M3D_VECTOR v;
@ -161,7 +174,7 @@ struct __attribute__((aligned(16))) M3D_V4U32 {
#endif
};
struct __attribute__((aligned(16))) M3D_V4I32 {
M3D_ALIGNED_STRUCT(16) M3D_V4I32 {
union {
int32_t i[4];
M3D_VECTOR v;
@ -188,7 +201,7 @@ struct M3D_F2 {
constexpr M3D_F2(float _x, float _y) noexcept : x(_x), y(_y) {}
};
struct __attribute__((aligned(16))) M3D_F2A : public M3D_F2 {
M3D_ALIGNED_STRUCT(16) M3D_F2A : public M3D_F2 {
using M3D_F2::M3D_F2;
};
@ -206,7 +219,7 @@ struct M3D_F3 {
constexpr M3D_F3(float _x, float _y, float _z) noexcept : x(_x), y(_y), z(_z) {}
};
struct __attribute__((aligned(16))) M3D_F3A : public M3D_F3 {
M3D_ALIGNED_STRUCT(16) M3D_F3A : public M3D_F3 {
using M3D_F3::M3D_F3;
};
@ -230,7 +243,7 @@ struct M3D_F4 {
auto operator <=> (const M3D_F4&) const = default;
#endif
};
struct __attribute__((aligned(16))) M3D_F4A : public M3D_F4 {
M3D_ALIGNED_STRUCT(16) M3D_F4A : public M3D_F4 {
using M3D_F4::M3D_F4;
};
@ -269,8 +282,7 @@ struct M3D_F4X4 {
auto operator <=> (const M3D_F4X4&) const = default;
#endif
};
struct __attribute__((aligned(16))) M3D_F4X4A : public M3D_F4X4
{
M3D_ALIGNED_STRUCT(16) M3D_F4X4A : public M3D_F4X4 {
using M3D_F4X4::M3D_F4X4;
};
@ -295,7 +307,7 @@ struct M3D_MATRIX {
float mat[4][4];
};
#else
struct __attribute__((aligned(16))) M3D_MATRIX {
M3D_ALIGNED_STRUCT(16) M3D_MATRIX {
M3D_VECTOR rows[4];
#endif
M3D_MATRIX() = default;
@ -866,8 +878,8 @@ namespace M3D_TriangleTests {
M3D_GCONST M3D_V4F32 M3D_BRayEpsilon = {{{1e-20f, 1e-20f, 1e-20f, 1e-20f}}};
M3D_GCONST M3D_V4F32 M3D_BRayNegEpsilon = {{{-1e-20f, -1e-20f, -1e-20f, -1e-20f}}};
M3D_GCONST M3D_V4F32 M3D_BFltMin = {{{-__FLT_MAX__, -__FLT_MAX__, -__FLT_MAX__, -__FLT_MAX__}}};
M3D_GCONST M3D_V4F32 M3D_BFltMax = {{{__FLT_MAX__, __FLT_MAX__, __FLT_MAX__, __FLT_MAX__}}};
M3D_GCONST M3D_V4F32 M3D_BFltMin = {{{-FLT_MAX, -FLT_MAX, -FLT_MAX, -FLT_MAX}}};
M3D_GCONST M3D_V4F32 M3D_BFltMax = {{{FLT_MAX, FLT_MAX, FLT_MAX, FLT_MAX}}};
M3D_GCONST M3D_V4F32 M3D_BBoxOffset[8] = {
{{{-1.0f, -1.0f, 1.0f, 0.0f}}},
{{{ 1.0f, -1.0f, 1.0f, 0.0f}}},

View File

@ -1,6 +1,6 @@
#include "Perfs.hpp"
#ifdef __MINGW32__
#if defined(__MINGW32__) || defined(_MSC_VER)
#include <windows.h>
#include <psapi.h>
#else
@ -9,7 +9,7 @@
#include "string.h"
#endif
#ifndef __MINGW32__
#if !(defined(__MINGW32__) || defined(_MSC_VER))
static int parseLine(char* line) {
// This assumes that a digit will be found and the line ends in "kB".
int i = strlen(line);
@ -23,6 +23,7 @@ static int parseLine(char* line) {
// Returned value in KB!
static int getLinuxVirtualMemUsage() {
FILE* file = fopen("/proc/self/status", "r");
int result = -1;
char line[128];
@ -39,6 +40,7 @@ static int getLinuxVirtualMemUsage() {
// Returned value in KB!
static int getLinuxPhysicalMemUsage() {
FILE* file = fopen("/proc/self/status", "r");
int result = -1;
char line[128];
@ -57,7 +59,7 @@ static int getLinuxPhysicalMemUsage() {
// Returned value in KB!
const size_t PerfsGetVirtMem(void) {
size_t out;
#ifdef __MINGW32__
#if defined(__MINGW32__) || defined(_MSC_VER)
PROCESS_MEMORY_COUNTERS_EX memCounter;
GetProcessMemoryInfo(GetCurrentProcess(), (PROCESS_MEMORY_COUNTERS*)&memCounter, sizeof(memCounter));
out = memCounter.PrivateUsage / 1000;
@ -70,7 +72,7 @@ const size_t PerfsGetVirtMem(void) {
// Returned value in KB!
const size_t PerfsGetPhysMem(void) {
size_t out;
#ifdef __MINGW32__
#if defined(__MINGW32__) || defined(_MSC_VER)
PROCESS_MEMORY_COUNTERS_EX memCounter;
GetProcessMemoryInfo(GetCurrentProcess(), (PROCESS_MEMORY_COUNTERS*)&memCounter, sizeof(memCounter));
out = memCounter.WorkingSetSize / 1000;

View File

@ -1,7 +1,23 @@
#pragma once
#include <cstddef>
#if (defined(__clang__) || defined(__GNUC__)) && (__x86_64__ || __i386__) && !defined(__MINGW32__)
#include <cpuid.h>
#endif
#ifndef DISABLE_INTRINSICS
#ifdef _MSC_VER
#pragma warning(push)
#pragma warning(disable : 4987)
// C4987: Off by default noise
#endif
#if defined(_MSC_VER) || defined(__MINGW32__)
#include <intrin.h>
#endif
#ifdef _MSC_VER
#pragma warning(pop)
#endif
#endif
#ifndef __cplusplus
@ -15,7 +31,7 @@ inline bool PerfsCPUSIMDReady(void) noexcept {
#if !defined(DISABLE_INTRINSICS)
int CPUInfo[4] = {-1};
#if defined(__GNUC__)
#if (defined(__clang__) || defined(__GNUC__)) && defined(__cpuid)
__cpuid(0, CPUInfo[0], CPUInfo[1], CPUInfo[2], CPUInfo[3]);
#else
__cpuid(CPUInfo, 0);
@ -29,7 +45,7 @@ inline bool PerfsCPUSIMDReady(void) noexcept {
return false;
#endif
#if defined(__GNUC__)
#if (defined(__clang__) || defined(__GNUC__)) && defined(__cpuid)
__cpuid(1, CPUInfo[0], CPUInfo[1], CPUInfo[2], CPUInfo[3]);
#else
__cpuid(CPUInfo, 1);

View File

@ -1,6 +1,7 @@
from conan import ConanFile
from conan.tools.cmake import CMakeToolchain#,cmake_layout
from conan.tools.cmake import CMakeToolchain,cmake_layout
from conan.tools.files import copy
from conan.tools.microsoft import is_msvc
import os
required_conan_version = ">=1.59"
@ -36,8 +37,9 @@ class ProtoTank(ConanFile):
def requirements(self):
self.requires("sfml/[~2.6]")
# def layout(self):
# cmake_layout(self)
def layout(self):
self.folders.build_folder_vars = ["settings.os", "settings.compiler", "settings.build_type"]
cmake_layout(self)
def generate(self):
tc = CMakeToolchain(self)
@ -46,7 +48,10 @@ class ProtoTank(ConanFile):
for dep in self.dependencies.values():
if len(dep.cpp_info.bindirs) > 0:
if self.settings.os == "Windows":
copy(self, "*.dll", dep.cpp_info.bindirs[0], os.path.join(self.build_folder, "bin"))
if is_msvc(self):
copy(self, "*.dll", dep.cpp_info.bindirs[0], os.path.join(self.build_folder, "bin", str(self.settings.build_type)))
else:
copy(self, "*.dll", dep.cpp_info.bindirs[0], os.path.join(self.build_folder, "bin"))
else:
copy(self, "*.so", dep.cpp_info.bindirs[0], os.path.join(self.build_folder, "bin"))