Skip to content

Commit

Permalink
Normalized build for MinGW-w64 (#432)
Browse files Browse the repository at this point in the history
* Normalized build for MinGW-w64

* Creared default build config

* Moved inclusion of build config to top in single_file_split.h

* Moved inclusion of build config to top in local_filesys.cc

* Commented out #define FOPEN_64_PRESENT

* Excluded include/dmlc/build_config.h from lint.

* Use existing logic for fopen64 when CMake is not called

* Pass build_config.h to lint check

* Use dmlc/base.h in local_filesys.cc to capture DMLC_USE_FOPEN64 flag
  • Loading branch information
KOLANICH authored and hcho3 committed Sep 5, 2018
1 parent e3377de commit 946a540
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 17 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,4 @@ build
# CLion
.idea
cmake-build-*
/include/dmlc/build_config.h
12 changes: 10 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/build/private/local_config.cmake)
include(${CMAKE_CURRENT_SOURCE_DIR}/build/private/local_config.cmake)
endif()

list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake/Modules)
set(CMAKE_LOCAL "${PROJECT_SOURCE_DIR}/cmake")
list(APPEND CMAKE_MODULE_PATH ${CMAKE_LOCAL}/Modules)

include(CheckCXXSymbolExists)
include(cmake/Utils.cmake)
#include(cmake/dmlccore.cmake)

Expand All @@ -19,7 +21,9 @@ dmlccore_option(USE_OPENMP "Build with OpenMP" ON)
dmlccore_option(USE_CXX14_IF_AVAILABLE "Build with C++14 if the compiler supports it" OFF)

# include path
include_directories("include")
set(INCLUDE_ROOT "${CMAKE_CURRENT_SOURCE_DIR}/include")
set(INCLUDE_DMLC_DIR "${INCLUDE_ROOT}/dmlc")
include_directories("${INCLUDE_ROOT}")

set(dmlccore_LINKER_LIBS "")
# HDFS configurations
Expand Down Expand Up @@ -57,6 +61,10 @@ endif()
# Older stdc++ enable c++11 items
add_definitions(-D__USE_XOPEN2K8)

check_symbol_exists(fopen64 stdio.h FOPEN_64_PRESENT)
message(STATUS "${CMAKE_LOCAL}/build_config.h.in -> ${INCLUDE_DMLC_DIR}/build_config.h")
configure_file("${CMAKE_LOCAL}/build_config.h.in" "${INCLUDE_DMLC_DIR}/build_config.h")

# compile
if(MSVC)
add_definitions(-DDMLC_USE_CXX11)
Expand Down
11 changes: 11 additions & 0 deletions cmake/build_config.h.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#ifndef DMLC_BUILD_CONFIG_H_
#define DMLC_BUILD_CONFIG_H_

#cmakedefine FOPEN_64_PRESENT

#if !defined(FOPEN_64_PRESENT) && DMLC_USE_FOPEN64
#warning "Redefining fopen64 with std::fopen"
#define fopen64 std::fopen
#endif

#endif // DMLC_BUILD_CONFIG_H_
10 changes: 2 additions & 8 deletions include/dmlc/base.h
Original file line number Diff line number Diff line change
Expand Up @@ -172,16 +172,8 @@
# endif
#endif

#if DMLC_USE_FOPEN64 && \
(!defined(__GNUC__) || (defined __ANDROID__) || ((defined __MINGW32__) && !(defined __MINGW64__)))
#define fopen64 std::fopen
#endif

#ifdef __APPLE__
# define off64_t off_t
# if DMLC_USE_FOPEN64
# define fopen64 std::fopen
# endif
#endif

#ifdef _MSC_VER
Expand All @@ -198,6 +190,8 @@
#endif
#endif

#include <dmlc/build_config.h>


extern "C" {
#include <sys/types.h>
Expand Down
17 changes: 17 additions & 0 deletions include/dmlc/build_config.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/*!
* Copyright (c) 2018 by Contributors
* \file build_config.h
* \brief Default detection logic for fopen64. May be overriden by CMake
* \author KOLANICH
*/
#ifndef DMLC_BUILD_CONFIG_H_
#define DMLC_BUILD_CONFIG_H_

#if DMLC_USE_FOPEN64 && \
(!defined(__GNUC__) || (defined __ANDROID__) || (defined __FreeBSD__) \
|| (defined __APPLE__) || ((defined __MINGW32__) && !(defined __MINGW64__)))
#warning "Redefining fopen64 with std::fopen"
#define fopen64 std::fopen
#endif

#endif // DMLC_BUILD_CONFIG_H_
5 changes: 1 addition & 4 deletions src/io/local_filesys.cc
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// Copyright by Contributors

#include <dmlc/base.h>
#include <dmlc/logging.h>
#include <errno.h>
extern "C" {
Expand All @@ -17,10 +18,6 @@ extern "C" {

#include "./local_filesys.h"

#if defined(__FreeBSD__) && DMLC_USE_FOPEN64
#define fopen64 std::fopen
#endif


namespace dmlc {
namespace io {
Expand Down
4 changes: 1 addition & 3 deletions src/io/single_file_split.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,14 @@
#ifndef DMLC_IO_SINGLE_FILE_SPLIT_H_
#define DMLC_IO_SINGLE_FILE_SPLIT_H_

#include <dmlc/base.h>
#include <dmlc/io.h>
#include <dmlc/logging.h>
#include <sys/stat.h>
#include <cstdio>
#include <string>
#include <algorithm>

#if defined(__FreeBSD__) && DMLC_USE_FOPEN64
#define fopen64 std::fopen
#endif

namespace dmlc {
namespace io {
Expand Down

0 comments on commit 946a540

Please sign in to comment.