Skip to content

Commit

Permalink
Windows Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
isuruf authored and xoviat committed Dec 23, 2017
1 parent 4fba341 commit c60f680
Show file tree
Hide file tree
Showing 31 changed files with 168 additions and 77 deletions.
32 changes: 20 additions & 12 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,17 @@ cmake_minimum_required(VERSION 2.8)
# In order to bootstrap the runtime library we need to skip
# CMake's Fortran tests
SET(CMAKE_Fortran_COMPILER_WORKS 1)
set(CMAKE_Fortran_PREPROCESS_SOURCE
"<CMAKE_Fortran_COMPILER> -Mpreprocess <DEFINES> <INCLUDES> <FLAGS> -E <SOURCE> -o <PREPROCESSED_SOURCE>")

if( NOT DEFINED TARGET_ARCHITECTURE )
execute_process(COMMAND uname -m OUTPUT_STRIP_TRAILING_WHITESPACE
OUTPUT_VARIABLE TARGET_ARCHITECTURE)
# If we are not building as a part of LLVM, build Flang as an
# standalone project, using LLVM as an external library:
if( CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR )
project(Flang)
endif()

if( NOT DEFINED TARGET_OS )
execute_process(COMMAND uname -s OUTPUT_STRIP_TRAILING_WHITESPACE
OUTPUT_VARIABLE TARGET_OS)
endif()
set(TARGET_OS ${CMAKE_HOST_SYSTEM_NAME})
set(TARGET_ARCHITECTURE ${CMAKE_HOST_SYSTEM_PROCESSOR})

if( ${TARGET_OS} STREQUAL "Linux" )
set(OS "LINUX")
Expand All @@ -51,16 +52,23 @@ if( ${TARGET_OS} STREQUAL "Linux" )
message("Unsupported architecture: ${TARGET_ARCHITECTURE}" )
return()
endif()
elseif(${TARGET_OS} STREQUAL "Windows" )
set(OS "WINDOWS")
set(OSNAME "Windows")
if( ${TARGET_ARCHITECTURE} STREQUAL "AMD64" )
set(TARGET_ARCHITECTURE "x86_64")
set(ARCHNAME x86-64)
set(ARCH X86)
set(WRDSZ 64)
else()
message("Unsupported architecture: ${TARGET_ARCHITECTURE}" )
return()
endif()
else()
message("Unsupported OS: ${TARGET_OS}" )
return()
endif()

# The cmake documentation states that these are set. They are not so we
# set them here
set(CMAKE_HOST_SYSTEM_NAME ${TARGET_OS})
set(CMAKE_HOST_SYSTEM_PROCESSOR ${TARGET_ARCHITECTURE})

# If we are not building as a part of LLVM, build Flang as an
# standalone project, using LLVM as an external library:
if( CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR )
Expand Down
2 changes: 2 additions & 0 deletions include/legacy-util-api.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ extern "C" {
#include <stdlib.h>
#include <string.h>
#include <time.h> /* time() */
#ifndef _WIN32
#include <unistd.h> /* getcwd() */
#endif

/* See tmpfile(3). */
FILE *tmpf(char *ignored);
Expand Down
4 changes: 2 additions & 2 deletions lib/scutil/cpu-stopwatch.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,12 @@ getcpu(void)
#else

#include <Windows.h>
#include "scutil.h"
//#include "scutil.h"

unsigned long
getcpu(void)
{
LARGE_INTEGER ticks_per_second = -1;
LARGE_INTEGER ticks_per_second = {-1};
LARGE_INTEGER ticks;

unsigned long last = 0;
Expand Down
2 changes: 1 addition & 1 deletion lib/scutil/host-fp-folding.c
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ configure_denormals(bool denorms_are_zeros, bool flush_to_zero)
fenv_t fenv;
if (fegetenv(&fenv) != 0)
fprintf(stderr, "fegetenv() failed: %s\n", strerror(errno));
#ifdef __x86_64__
#if defined(__x86_64__) && !defined(_WIN32)
fenv.__mxcsr &= ~0x0040;
if (denorms_are_zeros)
fenv.__mxcsr |= 0x0040;
Expand Down
6 changes: 5 additions & 1 deletion lib/scutil/lockfile.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,11 @@
* Clean up by deleting the uniquely named file we had created earlier.
*/

#ifdef _WIN32
#ifndef _WIN32
#include <unistd.h>
#else
#include <Winsock2.h>
#include <process.h>
#endif
#include <fcntl.h>
#include <stdio.h>
Expand All @@ -68,6 +69,9 @@ static char *udir = NULL;
*/
static long uwaiting;

#ifdef _WIN32
#define pid_t int
#endif
int
__pg_make_lock_file(char *dir)
{
Expand Down
2 changes: 2 additions & 0 deletions lib/scutil/path-utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@
#include "legacy-util-api.h"
#include <stddef.h>
#include <string.h>
#ifndef _WIN32
#include <unistd.h> /* access() */
#endif

void
basenam(const char *orig_path, const char *optional_suffix, char *basename)
Expand Down
11 changes: 8 additions & 3 deletions lib/scutil/pgnewfil.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,10 @@
#include <sys/stat.h>
#include <fcntl.h>

#if defined(HOST_WIN)
#if defined(_WIN32)
#include <direct.h>
#include <io.h>
#include <sys/stat.h>
extern unsigned long getpid(void);
#else
#include <unistd.h>
Expand All @@ -42,6 +43,10 @@ int pgnewfil_debug = 0;
#endif
extern size_t strlen();

#ifndef S_ISDIR
#define S_ISDIR(mode) (((mode) & S_IFMT) == S_IFDIR)
#endif

/*
* copy chars from q to p, terminate string, return end of string
*/
Expand Down Expand Up @@ -307,7 +312,7 @@ pg_makenewfile(char *pfx, char *sfx, int make)
if (!make) {
break;
} else {
#if defined(HOST_WIN)
#if defined(_WIN32)
fd = _open(filename, _O_CREAT | _O_BINARY | _O_EXCL | _O_RDWR, _S_IWRITE);
#else
fd = open(filename, O_CREAT | O_EXCL | O_RDWR, S_IRUSR | S_IWUSR);
Expand Down Expand Up @@ -353,7 +358,7 @@ pg_makenewdir(char *pfx, char *sfx, int make)
if (r == -1 && errno == ENOENT) {
if (make) {
int err;
#if defined(HOST_WIN) || defined(WINNT) || defined(WIN64)
#if defined(_WIN32) || defined(WINNT) || defined(WIN64)
err = _mkdir(filename);
#else
err = mkdir(filename, S_IRWXG | S_IRWXO | S_IXUSR | S_IWUSR | S_IRUSR);
Expand Down
15 changes: 12 additions & 3 deletions runtime/flang/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -480,7 +480,12 @@ add_flang_library(flang_static
${FTN_SUPPORT}
${SHARED_SOURCES}
)

if (MSVC)
set_property(TARGET flang_static PROPERTY OUTPUT_NAME flang_static)
else()
set_property(TARGET flang_static PROPERTY OUTPUT_NAME flang)
endif()

set(SHARED_LIBRARY TRUE)
add_flang_library(flang_shared
Expand All @@ -489,9 +494,12 @@ add_flang_library(flang_shared
${SHARED_SOURCES}
)
set_property(TARGET flang_shared PROPERTY OUTPUT_NAME flang)
target_link_libraries(flang_shared ${CMAKE_BINARY_DIR}/${CMAKE_CFG_INTDIR}/lib/libflangrti.so)
target_link_libraries(flang_shared flangrti_shared)
# Resolve symbols against libm and librt
target_link_libraries(flang_shared m rt)
target_link_libraries(flang_shared rt)
if (NOT MSVC)
target_link_libraries(flang_shared m)
endif()

set(SHARED_LIBRARY FALSE)

Expand Down Expand Up @@ -523,6 +531,7 @@ set_property(
## CMake does not handle module dependencies between Fortran files,
## we need to help it

if (NOT MSVC)
# State the module that the source is producing
set_source_files_properties(
iso_c_bind.F95
Expand All @@ -537,7 +546,7 @@ set_source_files_properties(
PROPERTIES
OBJECT_DEPENDS ${CMAKE_Fortran_MODULE_DIRECTORY}/iso_c_binding.mod
)

endif()

set_target_properties(flang_static flang_shared
PROPERTIES
Expand Down
17 changes: 12 additions & 5 deletions runtime/flangrti/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,11 @@ add_flang_library(flangrti_static
${PGC_SRC_FILES}
${SHARED_SOURCES}
)
set_property(TARGET flangrti_static PROPERTY OUTPUT_NAME flangrti)
if (MSVC)
set_property(TARGET flangrti_static PROPERTY OUTPUT_NAME flangrti_static)
else()
set_property(TARGET flangrti_static PROPERTY OUTPUT_NAME flangrti)
endif()


set(SHARED_LIBRARY TRUE)
Expand All @@ -189,16 +193,19 @@ add_flang_library(flangrti_shared
)

# Resolve symbols against libm
target_link_libraries(flangrti_shared m)

if (NOT MSVC)
target_link_libraries(flangrti_shared m)
endif()

# Import OpenMP
if (NOT DEFINED LIBOMP_EXPORT_DIR)
#if (NOT DEFINED LIBOMP_EXPORT_DIR)
find_library(
FLANG_LIBOMP
libomp.so
libomp
HINTS ${CMAKE_BINARY_DIR}/lib)
target_link_libraries(flangrti_shared ${FLANG_LIBOMP})
endif()
#endif()

if( ${TARGET_ARCHITECTURE} STREQUAL "aarch64" )
target_compile_definitions(flangrti_static PRIVATE TARGET_LINUX_ARM)
Expand Down
4 changes: 4 additions & 0 deletions runtime/flangrti/cacos.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,11 @@
CMPLXFUNC_C(__mth_i_cacos)
{
CMPLXARGS_C;
#ifndef _WIN32
complex float f = real + imag * I;
#else
_Fcomplex f = {real, imag};
#endif
f = CACOSF(f);
CRETURN_C(f);
}
4 changes: 4 additions & 0 deletions runtime/flangrti/casin.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,11 @@
CMPLXFUNC_C(__mth_i_casin)
{
CMPLXARGS_C;
#ifndef _WIN32
complex float f = real + imag * I;
#else
_Fcomplex f = {real, imag};
#endif
f = CASINF(f);
CRETURN_C(f);
}
4 changes: 4 additions & 0 deletions runtime/flangrti/catan.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,11 @@
CMPLXFUNC_C(__mth_i_catan)
{
CMPLXARGS_C;
#ifndef _WIN32
complex float f = real + imag * I;
#else
_Fcomplex f = {real, imag};
#endif
f = CATANF(f);
CRETURN_C(f);
}
4 changes: 4 additions & 0 deletions runtime/flangrti/ccosh.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,11 @@
CMPLXFUNC_C(__mth_i_ccosh)
{
CMPLXARGS_C;
#ifndef _WIN32
complex float f = real + imag * I;
#else
_Fcomplex f = {real, imag};
#endif
f = CCOSHF(f);
CRETURN_C(f);
}
4 changes: 4 additions & 0 deletions runtime/flangrti/cdacos.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,11 @@
ZMPLXFUNC_Z(__mth_i_cdacos)
{
ZMPLXARGS_Z;
#ifndef _WIN32
complex double d = real + imag * I;
#else
_Dcomplex d = {real, imag};
#endif
d = cacos(d);
ZRETURN_Z(d);
}
4 changes: 4 additions & 0 deletions runtime/flangrti/cdasin.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,11 @@
ZMPLXFUNC_Z(__mth_i_cdasin)
{
ZMPLXARGS_Z;
#ifndef _WIN32
complex double d = real + imag * I;
#else
_Dcomplex d = {real, imag};
#endif
d = casin(d);
ZRETURN_Z(d);
}
4 changes: 4 additions & 0 deletions runtime/flangrti/cdatan.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,11 @@
ZMPLXFUNC_Z(__mth_i_cdatan)
{
ZMPLXARGS_Z;
#ifndef _WIN32
complex double d = real + imag * I;
#else
_Dcomplex d = {real, imag};
#endif
d = catan(d);
ZRETURN_Z(d);
}
4 changes: 4 additions & 0 deletions runtime/flangrti/cdcosh.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,11 @@
ZMPLXFUNC_Z(__mth_i_cdcosh)
{
ZMPLXARGS_Z;
#ifndef _WIN32
complex double d = real + imag * I;
#else
_Dcomplex d = {real, imag};
#endif
d = ccosh(d);
ZRETURN_Z(d);
}
4 changes: 4 additions & 0 deletions runtime/flangrti/cdsinh.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,11 @@
ZMPLXFUNC_Z(__mth_i_cdsinh)
{
ZMPLXARGS_Z;
#ifndef _WIN32
complex double d = real + imag * I;
#else
_Dcomplex d = {real, imag};
#endif
d = csinh(d);
ZRETURN_Z(d);
}
4 changes: 4 additions & 0 deletions runtime/flangrti/cdtan.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,11 @@
ZMPLXFUNC_Z(__mth_i_cdtan)
{
ZMPLXARGS_Z;
#ifndef _WIN32
complex double d = real + imag * I;
#else
_Dcomplex d = {real, imag};
#endif
d = ctan(d);
ZRETURN_Z(d);
}
4 changes: 4 additions & 0 deletions runtime/flangrti/cdtanh.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,11 @@
ZMPLXFUNC_Z(__mth_i_cdtanh)
{
ZMPLXARGS_Z;
#ifndef _WIN32
complex double d = real + imag * I;
#else
_Dcomplex d = {real, imag};
#endif
d = ctanh(d);
ZRETURN_Z(d);
}
4 changes: 4 additions & 0 deletions runtime/flangrti/csinh.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,11 @@
CMPLXFUNC_C(__mth_i_csinh)
{
CMPLXARGS_C;
#ifndef _WIN32
complex float f = real + imag * I;
#else
_Fcomplex f = {real, imag};
#endif
f = CSINHF(f);
CRETURN_C(f);
}
4 changes: 4 additions & 0 deletions runtime/flangrti/ctan.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,11 @@
CMPLXFUNC_C(__mth_i_ctan)
{
CMPLXARGS_C;
#ifndef _WIN32
complex float f = real + imag * I;
#else
_Fcomplex f = {real, imag};
#endif
f = CTANF(f);
CRETURN_C(f);
}
Loading

0 comments on commit c60f680

Please sign in to comment.