Fixes for cmake build with visual studio (#144)

* Fixed CMake configuration for visual studio build

Added proper asm source and set correct type.

* Disabled stadard layout check of randomx_cache for visual studio debug

Required to silence static_assert which fails on Visual Studio Debug
configuation.

* Fixed warning message and defines check

* Removed unsupported flags for MSVC compiler

* Enabled AVX2 for msvc

* Fixed formatting in CmakeLists

* Added generation of configuration.asm by CMake for MSVC
This commit is contained in:
Vladimir 2019-11-22 19:24:16 +02:00 committed by tevador
parent 7e20c8e56e
commit 01914b49cd
2 changed files with 55 additions and 22 deletions

View File

@ -28,6 +28,8 @@
cmake_minimum_required(VERSION 2.8.7) cmake_minimum_required(VERSION 2.8.7)
project(RandomX)
set(randomx_sources set(randomx_sources
src/aes_hash.cpp src/aes_hash.cpp
src/argon2_ref.c src/argon2_ref.c
@ -96,8 +98,25 @@ endfunction()
# x86-64 # x86-64
if(ARCH_ID STREQUAL "x86_64" OR ARCH_ID STREQUAL "x86-64" OR ARCH_ID STREQUAL "amd64") if(ARCH_ID STREQUAL "x86_64" OR ARCH_ID STREQUAL "x86-64" OR ARCH_ID STREQUAL "amd64")
list(APPEND randomx_sources list(APPEND randomx_sources
src/jit_compiler_x86_static.S
src/jit_compiler_x86.cpp) src/jit_compiler_x86.cpp)
if(MSVC)
enable_language(ASM_MASM)
list(APPEND randomx_sources src/jit_compiler_x86_static.asm)
set_property(SOURCE src/jit_compiler_x86_static.asm PROPERTY LANGUAGE ASM_MASM)
set_source_files_properties(src/argon2_avx2.c COMPILE_FLAGS /arch:AVX2)
add_custom_command(OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/src/asm/configuration.asm
COMMAND powershell -ExecutionPolicy Bypass -File h2inc.ps1 ..\\src\\configuration.h > ..\\src\\asm\\configuration.asm SET ERRORLEVEL = 0
COMMENT "Generating configuration.asm at ${CMAKE_CURRENT_SOURCE_DIR}"
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/vcxproj)
add_custom_target(generate-asm
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/src/asm/configuration.asm)
else()
list(APPEND randomx_sources src/jit_compiler_x86_static.S)
# cheat because cmake and ccache hate each other # cheat because cmake and ccache hate each other
set_property(SOURCE src/jit_compiler_x86_static.S PROPERTY LANGUAGE C) set_property(SOURCE src/jit_compiler_x86_static.S PROPERTY LANGUAGE C)
set_property(SOURCE src/jit_compiler_x86_static.S PROPERTY XCODE_EXPLICIT_FILE_TYPE sourcecode.asm) set_property(SOURCE src/jit_compiler_x86_static.S PROPERTY XCODE_EXPLICIT_FILE_TYPE sourcecode.asm)
@ -117,6 +136,7 @@ if (ARCH_ID STREQUAL "x86_64" OR ARCH_ID STREQUAL "x86-64" OR ARCH_ID STREQUAL "
endif() endif()
endif() endif()
endif() endif()
endif()
# PowerPC # PowerPC
if(ARCH_ID STREQUAL "ppc64" OR ARCH_ID STREQUAL "ppc64le") if(ARCH_ID STREQUAL "ppc64" OR ARCH_ID STREQUAL "ppc64le")
@ -152,8 +172,12 @@ endif()
set(RANDOMX_INCLUDE "${CMAKE_CURRENT_SOURCE_DIR}/src" CACHE STRING "RandomX Include path") set(RANDOMX_INCLUDE "${CMAKE_CURRENT_SOURCE_DIR}/src" CACHE STRING "RandomX Include path")
add_library(randomx add_library(randomx ${randomx_sources})
${randomx_sources})
if(TARGET generate-asm)
add_dependencies(randomx generate-asm)
endif()
set_property(TARGET randomx PROPERTY POSITION_INDEPENDENT_CODE ON) set_property(TARGET randomx PROPERTY POSITION_INDEPENDENT_CODE ON)
set_property(TARGET randomx PROPERTY CXX_STANDARD 11) set_property(TARGET randomx PROPERTY CXX_STANDARD 11)
set_property(TARGET randomx PROPERTY CXX_STANDARD_REQUIRED ON) set_property(TARGET randomx PROPERTY CXX_STANDARD_REQUIRED ON)

View File

@ -61,8 +61,17 @@ struct randomx_cache {
//A pointer to a standard-layout struct object points to its initial member //A pointer to a standard-layout struct object points to its initial member
static_assert(std::is_standard_layout<randomx_dataset>(), "randomx_dataset must be a standard-layout struct"); static_assert(std::is_standard_layout<randomx_dataset>(), "randomx_dataset must be a standard-layout struct");
//the following assert fails when compiling Debug in Visual Studio (JIT mode will crash in Debug) //the following assert fails when compiling Debug in Visual Studio (JIT mode will crash in Debug)
#if defined(_MSC_VER) && !defined(__INTEL_COMPILER) && defined(_DEBUG)
#define TO_STR(x) #x
#define STR(x) TO_STR(x)
#pragma message ( __FILE__ "(" STR(__LINE__) ") warning: check std::is_standard_layout<randomx_cache>() is disabled for Debug configuration. JIT mode will crash." )
#undef STR
#undef TO_STR
#else
static_assert(std::is_standard_layout<randomx_cache>(), "randomx_cache must be a standard-layout struct"); static_assert(std::is_standard_layout<randomx_cache>(), "randomx_cache must be a standard-layout struct");
#endif
namespace randomx { namespace randomx {