Skip to content

Commit

Permalink
Fix compile issues on MinGW
Browse files Browse the repository at this point in the history
  • Loading branch information
ashb committed Oct 19, 2009
1 parent 3417f15 commit a312878
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 21 deletions.
14 changes: 12 additions & 2 deletions CMakeLists.txt
Expand Up @@ -115,11 +115,21 @@ option(
${_ENABLE_TESTS_DEFAULT})

if(CMAKE_COMPILER_IS_GNUCXX)
# MinGW doesn't set this by default
if(WIN32)
add_definitions(-DWIN32)
endif()

option(ENABLE_DEBUG_WARNINGS "Enable -Wpadded and -Weffc++" OFF)

add_definitions("-pedantic-errors -Wall -Wextra"
"-Winit-self -Woverloaded-virtual -Wnon-virtual-dtor -Wsign-promo"
"-Wstrict-aliasing=1")
"-Winit-self -Woverloaded-virtual -Wnon-virtual-dtor -Wsign-promo")

if (NOT WIN32)
# Boost 1.39 on mingw seems to produce a lot of these - they are very
# noisy
add_definitions("-Wstrict-aliasing=1")
endif()

if(ENABLE_DEBUG_WARNINGS)
add_definitions("-Wpadded -Weffc++")
Expand Down
34 changes: 23 additions & 11 deletions CMakeModules/FindSelfExe.cmake
Expand Up @@ -39,6 +39,29 @@ if (APPLE)
endif()
endif()

if(WIN32 AND NOT FLUSSPFERD_HAVE_SELF_EXE)
# This might need an explicit link against kernel32.lib. Probably not
list(APPEND CMAKE_REQUIRED_LIBRARIES "kernel32")
check_cxx_source_runs(
"#include <windows.h>
int main() {
char buf[1024];
if (GetModuleFileName(NULL, buf, 1024) > 0)
return EXIT_SUCCESS;
else
return EXIT_FAILURE;
}
"
FLUSSPFERD_SELF_EXE_GetModuleFilename)
list(REMOVE_ITEM CMAKE_REQUIRED_LIBRARIES "kernel32")

if(FLUSSPFERD_SELF_EXE_GetModuleFilename)
add_definitions("-DFLUSSPFERD_SELF_EXE_GetModuleFilename")
set(FLUSSPFERD_HAVE_SELF_EXE ON)
endif()
endif()


if(NOT FLUSSPFERD_HAVE_SELF_EXE)
# Linux-ism. /proc/self/exe is a symlink to the actual binary
check_cxx_source_runs(
Expand Down Expand Up @@ -117,14 +140,3 @@ if(NOT FLUSSPFERD_HAVE_SELF_EXE)
set(FLUSSPFERD_HAVE_SELF_EXE ON)
endif()
endif()

if(WIN32 AND NOT FLUSSPFERD_HAVE_SELF_EXE)
# This might need an explicit link against kernel32.lib. Probably not
check_function_exists(GetModuleFileName SELF_EXE_GetModuleFilename)

if(SELF_EXE_GetModuleFilename)
add_definitions("-DFLUSSPFERD_SELF_EXE_GetModuleFilename")
set(FLUSSPFERD_HAVE_SELF_EXE ON)
endif()
endif()

2 changes: 1 addition & 1 deletion CMakeModules/FindSpidermonkey.cmake
Expand Up @@ -56,7 +56,7 @@ endif()
if(SPIDERMONKEY_ROOT)
find_library(
SPIDERMONKEY_LIBRARY
NAMES mozjs js js32
NAMES mozjs js js32 js3250
PATHS "${SPIDERMONKEY_ROOT}/lib"
NO_DEFAULT_PATH)
else()
Expand Down
4 changes: 3 additions & 1 deletion include/flusspferd/io/filesystem-base.hpp
Expand Up @@ -51,16 +51,18 @@ namespace fs_base {
void make_directory(std::string const &target);
void remove_directory(std::string const &target);

string read_link(std::string const &link);

string working_directory();
void change_working_directory(std::string const &path);

string owner(std::string const &path);
void change_owner(std::string const &path, std::string owner);

#ifndef WIN32
string read_link(std::string const &link);
void link(std::string const &source, std::string const &target);
void hard_link(std::string const &source, std::string const &target);
#endif

bool exists(std::string const &path);
bool is_file(std::string const &path);
Expand Down
5 changes: 3 additions & 2 deletions src/core/flusspferd_module.cpp
Expand Up @@ -213,8 +213,9 @@ std::string get_exe_name_from_argv(std::string const &argv0) {
#include <windows.h>
optional<std::string> get_exe_name() {
char buf[MAX_PATH];
if (GetModuleFileName( NULL, buf, MAX_PATH))
return buf;
DWORD len = GetModuleFileName( NULL, buf, MAX_PATH);
if (len > 0)
return std::string(buf, len);
else
return boost::none;
}
Expand Down
16 changes: 14 additions & 2 deletions src/io/filesystem-base.cpp
Expand Up @@ -34,6 +34,13 @@ THE SOFTWARE.

#ifdef WIN32
#include <stdio.h>
#include <io.h>

#define access _access

//int const R_OK = 04;
//int const W_OK = 02;

#else
#include <unistd.h>
#endif
Expand Down Expand Up @@ -70,9 +77,11 @@ void flusspferd::load_filesystem_base_module(object container) {
create_native_function(exports, "same", &fs_base::same);


#ifndef WIN32
create_native_function(exports, "link", &fs_base::link);
create_native_function(exports, "hardLink", &fs_base::hard_link);
create_native_function(exports, "readLink", &fs_base::read_link);
#endif


create_native_function(exports, "makeDirectory", &fs_base::make_directory);
Expand Down Expand Up @@ -116,7 +125,6 @@ string fs_base::canonical(std::string const &path) {
// Resolve symlinks
fs::path fs_base::canonicalize(fs::path in) {
fs::path accum;
char buff[PATH_MAX];

if (!in.has_root_path()) {
// dir is relative!
Expand All @@ -136,7 +144,9 @@ fs::path fs_base::canonicalize(fs::path in) {
}

accum /= seg;
#ifndef WIN32
if (fs::is_symlink(accum)) {
char buff[PATH_MAX];
ssize_t len = readlink(accum.string().c_str(), buff, PATH_MAX);
if (len == -1) {
format fmt = format(error_fmt) % "canonical"
Expand All @@ -154,6 +164,7 @@ fs::path fs_base::canonicalize(fs::path in) {
accum = canonicalize(accum / link_path);
}
}
#endif
}

// This trickery forces a trailing / onto the dir
Expand Down Expand Up @@ -297,6 +308,7 @@ bool fs_base::same(std::string const &source, std::string const &target) {\
return fs::equivalent(source, target);
}

#ifndef WIN32
void fs_base::link(std::string const &source, std::string const &target) {
security &sec = security::get();
if (!sec.check_path(source, security::ACCESS)) {
Expand Down Expand Up @@ -356,7 +368,7 @@ string fs_base::read_link(std::string const &link) {
}
return string(buff, len);
}

#endif

void fs_base::make_directory(std::string const &dir) {
if (!security::get().check_path(dir, security::CREATE)) {
Expand Down
5 changes: 3 additions & 2 deletions src/spidermonkey/value.cpp
Expand Up @@ -34,7 +34,8 @@ THE SOFTWARE.
#include <js/jsapi.h>
#include <cassert>
#include <cmath>
#ifdef WIN32

#ifdef _MSC_VER
#include <float.h>
#endif

Expand Down Expand Up @@ -95,7 +96,7 @@ double value::to_number() const {

double value::to_integral_number(int bits, bool signedness) const {
long double value = to_number();
#ifdef WIN32
#ifdef _MSC_VER
if (!_finite(value))
return 0;
#else
Expand Down

0 comments on commit a312878

Please sign in to comment.