Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Building with Clang on Windows #300

Merged
merged 25 commits into from
Jul 23, 2020
5 changes: 5 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,11 @@ set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake/Modules)
set(SLEEF_SCRIPT_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake/Scripts CACHE PATH
"Path for finding sleef specific cmake scripts")

if (CMAKE_C_COMPILER_ID MATCHES "Clang" AND "x${CMAKE_C_SIMULATE_ID}" STREQUAL "xMSVC")
message(STATUS "Building with Clang on Windows")
set(SLEEF_CLANG_ON_WINDOWS TRUE)
endif()

# sleef-config.h.in passes cmake settings to the source code
include(Configure.cmake)
configure_file(
Expand Down
73 changes: 43 additions & 30 deletions Configure.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,6 @@ include(CheckCCompilerFlag)
include(CheckCSourceCompiles)
include(CheckTypeSize)

# Some toolchains require explicit linking of the libraries following.
find_library(LIB_MPFR mpfr)
find_library(LIBM m)
find_library(LIBGMP gmp)
find_library(LIBRT rt)
find_library(LIBFFTW3 fftw3)

if (NOT CMAKE_CROSSCOMPILING AND NOT SLEEF_FORCE_FIND_PACKAGE_SSL)
find_package(OpenSSL)
if (OPENSSL_FOUND)
Expand All @@ -32,25 +25,38 @@ if (ENFORCE_TESTER3 AND NOT SLEEF_OPENSSL_FOUND)
message(FATAL_ERROR "ENFORCE_TESTER3 is specified and OpenSSL not found")
endif()

if (LIB_MPFR)
find_path(MPFR_INCLUDE_DIR
NAMES mpfr.h
ONLY_CMAKE_FIND_ROOT_PATH)
endif(LIB_MPFR)

if (LIBFFTW3)
find_path(FFTW3_INCLUDE_DIR
NAMES fftw3.h
ONLY_CMAKE_FIND_ROOT_PATH)
endif(LIBFFTW3)

if (NOT LIBM)
set(LIBM "")
endif()
if (NOT (RUNNING_ON_APPVEYOR AND SLEEF_CLANG_ON_WINDOWS))
# We rely on Cygwin tools in order to test the builds on
# appveyor. However, if we try to link these libraries, cmake finds
# the Cygwin version of libraries, which causes errors.

# Some toolchains require explicit linking of the libraries following.
find_library(LIB_MPFR mpfr)
find_library(LIBM m)
find_library(LIBGMP gmp)
find_library(LIBRT rt)
find_library(LIBFFTW3 fftw3)

if (LIB_MPFR)
find_path(MPFR_INCLUDE_DIR
NAMES mpfr.h
ONLY_CMAKE_FIND_ROOT_PATH)
endif(LIB_MPFR)

if (LIBFFTW3)
find_path(FFTW3_INCLUDE_DIR
NAMES fftw3.h
ONLY_CMAKE_FIND_ROOT_PATH)
endif(LIBFFTW3)

if (NOT LIBM)
set(LIBM "")
endif()

if (NOT LIBRT)
set(LIBRT "")
endif()
if (NOT LIBRT)
set(LIBRT "")
endif()
endif(NOT SLEEF_CLANG_ON_WINDOWS)

# The library currently supports the following SIMD architectures
set(SLEEF_SUPPORTED_EXTENSIONS
Expand Down Expand Up @@ -310,6 +316,15 @@ if(CMAKE_C_COMPILER_ID MATCHES "(GNU|Clang)")
string(CONCAT FLAGS_WALL ${FLAGS_WALL} " -Wno-psabi")
set(FLAGS_ENABLE_NEON32 "-mfpu=neon")
endif(CMAKE_C_COMPILER_ID MATCHES "GNU")

if (SLEEF_CLANG_ON_WINDOWS)
# The following line is required to prevent clang from displaying
# many warnings. Clang on Windows references MSVC header files,
# which have deprecation and security attributes for many
# functions.

string(CONCAT FLAGS_WALL ${FLAGS_WALL} " -D_CRT_SECURE_NO_WARNINGS -Wno-deprecated-declarations")
fpetrogalli marked this conversation as resolved.
Show resolved Hide resolved
endif()
elseif(MSVC)
# Intel vector extensions.
if (CMAKE_CL_64)
Expand Down Expand Up @@ -656,6 +671,7 @@ CHECK_C_SOURCE_COMPILES("
if (COMPILER_SUPPORTS_WEAK_ALIASES AND
NOT CMAKE_SYSTEM_PROCESSOR MATCHES "arm" AND
NOT CMAKE_SYSTEM_PROCESSOR MATCHES "^(powerpc|ppc)64" AND
NOT SLEEF_CLANG_ON_WINDOWS AND
NOT MINGW AND BUILD_GNUABI_LIBS)
set(ENABLE_GNUABI ${COMPILER_SUPPORTS_WEAK_ALIASES})
endif()
Expand Down Expand Up @@ -716,16 +732,13 @@ if(SLEEF_SHOW_ERROR_LOG)
endif()
endif(SLEEF_SHOW_ERROR_LOG)

# Detect if cmake is running on Travis
string(COMPARE NOTEQUAL "" "$ENV{TRAVIS}" RUNNING_ON_TRAVIS)

if (${RUNNING_ON_TRAVIS} AND CMAKE_C_COMPILER_ID MATCHES "Clang")
if (RUNNING_ON_TRAVIS AND CMAKE_C_COMPILER_ID MATCHES "Clang")
message(STATUS "Travis bug workaround turned on")
set(COMPILER_SUPPORTS_OPENMP FALSE) # Workaround for https://github.com/travis-ci/travis-ci/issues/8613
set(COMPILER_SUPPORTS_FLOAT128 FALSE) # Compilation on unroll_0_vecextqp.c does not finish on Travis
endif()

if (MSVC)
if (MSVC OR SLEEF_CLANG_ON_WINDOWS)
set(COMPILER_SUPPORTS_OPENMP FALSE) # At this time, OpenMP is not supported on MSVC
endif()

Expand Down
20 changes: 15 additions & 5 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,31 +6,41 @@ configuration: Release
environment:
matrix:
- ENV_BUILD_STATIC: -DBUILD_SHARED_LIBS=TRUE -DENFORCE_TESTER=TRUE
COMPILER: MSVC
DO_TEST: TRUE
- ENV_BUILD_STATIC: -DBUILD_SHARED_LIBS=FALSE
COMPILER: MSVC
DO_TEST: FALSE
install:
- hostname
- call "D:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Auxiliary\Build\vcvars64.bat"
build_script:
- set BUILDFOLDER=%CD%
- set ORGPATH=%PATH%
# - if "%DO_TEST%" == "TRUE" "C:\\Cygwin64\\setup-x86_64.exe" -q -g -P libmpfr-devel,libgmp-devel,cmake
- if "%DO_TEST%" == "TRUE" echo PATH c:\Cygwin64\bin;c:\Cygwin64\usr\bin;%CD%\build-cygwin\bin;%PATH% > q.bat
- if "%DO_TEST%" == "TRUE" powershell -Command "(gc q.bat) -replace ' ;', ';' | Out-File -encoding ASCII p.bat"
- if "%DO_TEST%" == "TRUE" call p.bat
- if "%DO_TEST%" == "TRUE" "C:\\Cygwin64\\bin\\bash" -c 'mkdir build-mingw;cd build-mingw;CC=x86_64-w64-mingw32-gcc cmake -G Ninja .. -DBUILD_SHARED_LIBS=FALSE -DBUILD_QUAD=TRUE;ninja'
- if "%DO_TEST%" == "TRUE" "C:\\Cygwin64\\bin\\bash" -c 'mkdir build-mingw;cd build-mingw;CC=x86_64-w64-mingw32-gcc cmake -G Ninja .. -DRUNNING_ON_APPVEYOR=TRUE -DBUILD_SHARED_LIBS=FALSE -DBUILD_QUAD=TRUE;ninja'
- if "%DO_TEST%" == "TRUE" cd "%BUILDFOLDER%"
- if "%DO_TEST%" == "TRUE" "C:\\Cygwin64\\bin\\bash" -c 'mkdir build-cygwin;cd build-cygwin;cmake -G Ninja -DBUILD_QUAD=TRUE ..;ninja'
- if "%DO_TEST%" == "TRUE" "C:\\Cygwin64\\bin\\bash" -c 'mkdir build-cygwin;cd build-cygwin;cmake -G Ninja -DRUNNING_ON_APPVEYOR=TRUE -DBUILD_QUAD=TRUE ..;ninja'
- if "%DO_TEST%" == "TRUE" cd "%BUILDFOLDER%"
- if "%DO_TEST%" == "TRUE" del /Q /F build-cygwin\bin\iut*
- if "%DO_TEST%" == "TRUE" echo PATH %ORGPATH%;c:\Cygwin64\bin;c:\Cygwin64\usr\bin;%CD%\build-cygwin\bin;%CD%\build\bin > q.bat
- if "%DO_TEST%" == "TRUE" powershell -Command "(gc q.bat) -replace ' ;', ';' | Out-File -encoding ASCII p.bat"
- if "%DO_TEST%" == "TRUE" call p.bat
- mkdir build
- cd build
- cmake -G"Visual Studio 16 2019" .. -DCMAKE_INSTALL_PREFIX=install -DSLEEF_SHOW_CONFIG=1 -DSLEEF_SHOW_ERROR_LOG=1 -DENFORCE_TESTER3=TRUE -DBUILD_QUAD=TRUE %ENV_BUILD_STATIC%
build_script:
- cmake -G"Visual Studio 16 2019" .. -DRUNNING_ON_APPVEYOR=TRUE -DCMAKE_INSTALL_PREFIX=install -DSLEEF_SHOW_CONFIG=1 -DSLEEF_SHOW_ERROR_LOG=1 -DENFORCE_TESTER3=TRUE -DBUILD_QUAD=TRUE %ENV_BUILD_STATIC%
- cmake --build . --target install --config Release
- if "%DO_TEST%" == "TRUE" (ctest --output-on-failure -j 4 -C Release)
- cd "%BUILDFOLDER%"
- echo PATH %ORGPATH%;c:\Cygwin64\bin;c:\Cygwin64\usr\bin;%CD%\build-cygwin\bin;%CD%\build-clang\bin > q.bat
- powershell -Command "(gc q.bat) -replace ' ;', ';' | Out-File -encoding ASCII p.bat"
- call p.bat
- mkdir build-clang
- cd build-clang
- cmake -G Ninja .. -DRUNNING_ON_APPVEYOR=TRUE -DCMAKE_C_COMPILER:PATH="C:\Program Files\LLVM\bin\clang.exe" -DCMAKE_INSTALL_PREFIX=install -DSLEEF_SHOW_CONFIG=1 -DSLEEF_SHOW_ERROR_LOG=1 -DENFORCE_TESTER3=TRUE -DBUILD_QUAD=TRUE %ENV_BUILD_STATIC%
- ninja
test_script:
- if "%DO_TEST%" == "TRUE" (ctest --output-on-failure -j 4 -C Release)
artifacts:
Expand Down
6 changes: 3 additions & 3 deletions src/common/misc.h
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ typedef union {

//

#if defined (__GNUC__) || defined (__clang__) || defined(__INTEL_COMPILER)
#if (defined (__GNUC__) || defined (__clang__) || defined(__INTEL_COMPILER)) && !defined(_MSC_VER)

#define LIKELY(condition) __builtin_expect(!!(condition), 1)
#define UNLIKELY(condition) __builtin_expect(!!(condition), 0)
Expand Down Expand Up @@ -271,7 +271,7 @@ typedef union {
#define SLEEF_NANq (SLEEF_INFINITYq - SLEEF_INFINITYq)
#endif

#elif defined(_MSC_VER)
#elif defined(_MSC_VER) // #if (defined (__GNUC__) || defined (__clang__) || defined(__INTEL_COMPILER)) && !defined(_MSC_VER)

#define INLINE __forceinline
#define CONST
Expand Down Expand Up @@ -317,7 +317,7 @@ typedef union {
#endif
#endif

#endif // defined(_MSC_VER)
#endif // #elif defined(_MSC_VER) // #if (defined (__GNUC__) || defined (__clang__) || defined(__INTEL_COMPILER)) && !defined(_MSC_VER)

#if !defined(__linux__)
#define isinff(x) ((x) == SLEEF_INFINITYf || (x) == -SLEEF_INFINITYf)
Expand Down
4 changes: 2 additions & 2 deletions src/dft-tester/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ if (COMPILER_SUPPORTS_OPENMP)
set(COMMON_LINK_LIBRARIES ${COMMON_LINK_LIBRARIES} ${OpenMP_C_FLAGS})
endif()

if(NOT MSVC)
if((NOT MSVC) AND NOT SLEEF_CLANG_ON_WINDOWS)
# Target executable naivetestdp
set(TARGET_NAIVETESTDP "naivetestdp")
add_executable(${TARGET_NAIVETESTDP} naivetest.c ${PROJECT_SOURCE_DIR}/include/sleefdft.h)
Expand Down Expand Up @@ -162,7 +162,7 @@ if (LIBFFTW3)
add_test_dft(${TARGET_FFTWTEST2DSP}_10_10 $<TARGET_FILE:${TARGET_FFTWTEST2DSP}> 10 10)
add_test_dft(${TARGET_FFTWTEST2DSP}_5_15 $<TARGET_FILE:${TARGET_FFTWTEST2DSP}> 5 15)
else(LIBFFTW3)
if(MSVC)
if(MSVC OR SLEEF_CLANG_ON_WINDOWS)
# Test roundtriptestdp
add_test_dft(${TARGET_ROUNDTRIPTEST1DDP}_1 $<TARGET_FILE:${TARGET_ROUNDTRIPTEST1DDP}> 1 10)
add_test_dft(${TARGET_ROUNDTRIPTEST1DDP}_2 $<TARGET_FILE:${TARGET_ROUNDTRIPTEST1DDP}> 2 10)
Expand Down
10 changes: 5 additions & 5 deletions src/dft/dft.c
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ static int omp_thread_count() {
static void startAllThreads(const int nth) {
#ifdef _OPENMP
volatile int8_t *state = calloc(nth, 1);
int th;
int th=0;
#pragma omp parallel for
for(th=0;th<nth;th++) {
state[th] = 1;
Expand Down Expand Up @@ -376,7 +376,7 @@ static void transposeMT(real *RESTRICT ALIGNED(256) d, real *RESTRICT ALIGNED(25
typedef struct { real r[BS*2]; } row_t;
typedef struct { real r0, r1; } element_t;
#endif
int y;
int y=0;
#pragma omp parallel for
for(y=0;y<(1 << log2n);y+=BS) {
for(int x=0;x<(1 << log2m);x+=BS) {
Expand Down Expand Up @@ -919,7 +919,7 @@ static void measureBut(SleefDFT *p) {
if (p->tbl[N] == NULL || p->tbl[N][level] == NULL) continue;
if (p->vecwidth > (1 << N)) continue;
if ((config & CONFIG_MT) != 0) {
int i1;
int i1=0;
#ifdef _OPENMP
#pragma omp parallel for
#endif
Expand All @@ -945,7 +945,7 @@ static void measureBut(SleefDFT *p) {
if (p->vecwidth > 2 && p->log2len <= N+2) continue;
if ((int)p->log2len - (int)level < p->log2vecwidth) continue;
if ((config & CONFIG_MT) != 0) {
int i1;
int i1=0;
#ifdef _OPENMP
#pragma omp parallel for
#endif
Expand Down Expand Up @@ -1380,7 +1380,7 @@ EXPORT void EXECUTE(SleefDFT *p, const real *s0, real *d0) {
(((p->mode & SLEEF_MODE_DEBUG) == 0 && p->tmMT < p->tmNoMT) ||
((p->mode & SLEEF_MODE_DEBUG) != 0 && (rand() & 1))))
{
int y;
int y=0;
#pragma omp parallel for
for(y=0;y<p->vlen;y++) {
EXECUTE(p->instH, &s[p->hlen*2*y], &tBuf[p->hlen*2*y]);
Expand Down
Loading