Skip to content

Commit

Permalink
Fix windows build.
Browse files Browse the repository at this point in the history
  • Loading branch information
egorpugin committed Nov 24, 2016
1 parent 64159c7 commit 6444695
Show file tree
Hide file tree
Showing 19 changed files with 58 additions and 52 deletions.
2 changes: 0 additions & 2 deletions api/baseapi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@
// workaround for stdlib.h with -std=c++11 for _splitpath and _MAX_FNAME
#undef __STRICT_ANSI__
#endif // _MSC_VER
#include <stdlib.h>
#include <windows.h>
#include <fcntl.h>
#include <io.h>
#else
Expand Down
1 change: 0 additions & 1 deletion api/tesseractmain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
#if defined(HAVE_TIFFIO_H) && defined(_WIN32)

#include <tiffio.h>
#include <windows.h>

static void Win32WarningHandler(const char* module, const char* fmt,
va_list ap) {
Expand Down
3 changes: 0 additions & 3 deletions ccmain/pagesegmain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@
**********************************************************************/

#ifdef _WIN32
#ifndef __GNUC__
#include <windows.h>
#endif // __GNUC__
#ifndef unlink
#include <io.h>
#endif
Expand Down
2 changes: 0 additions & 2 deletions ccmain/tesseract_cube_combiner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@
// the recognition results of Tesseract and Cube at the word level

#include <algorithm>
#include <string>
#include <vector>
#include <wctype.h>

#include "tesseract_cube_combiner.h"
Expand Down
20 changes: 5 additions & 15 deletions ccmain/tesseract_cube_combiner.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,6 @@
#include <vector>
#include "pageres.h"

#ifdef _WIN32
#include <windows.h>
using namespace std;
#endif

#ifdef USE_STD_NAMESPACE
using std::string;
using std::vector;
#endif

namespace tesseract {

class CubeObject;
Expand Down Expand Up @@ -72,27 +62,27 @@ class TesseractCubeCombiner {
// output parameter will be true if both answers are identical,
// false otherwise. Modifies the cube_alt_list, so no assumptions
// should be made about its state upon return.
bool ComputeCombinerFeatures(const string &tess_res,
bool ComputeCombinerFeatures(const std::string &tess_res,
int tess_confidence,
CubeObject *cube_obj,
WordAltList *cube_alt_list,
vector<double> *features,
std::vector<double> *features,
bool *agreement);

// Is the word valid according to Tesseract's language model
bool ValidWord(const string &str);
bool ValidWord(const std::string &str);

// Loads the combiner neural network from file, using cube_cntxt_
// to find path.
bool LoadCombinerNet();
private:
// Normalize a UTF-8 string. Converts the UTF-8 string to UTF32 and optionally
// strips punc and/or normalizes case and then converts back
string NormalizeString(const string &str, bool remove_punc, bool norm_case);
std::string NormalizeString(const std::string &str, bool remove_punc, bool norm_case);

// Compares 2 strings after optionally normalizing them and or stripping
// punctuation
int CompareStrings(const string &str1, const string &str2, bool ignore_punc,
int CompareStrings(const std::string &str1, const std::string &str2, bool ignore_punc,
bool norm_case);

NeuralNet *combiner_net_; // pointer to the combiner NeuralNet object
Expand Down
6 changes: 3 additions & 3 deletions ccstruct/imagedata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@

#include "imagedata.h"

#include <unistd.h>

#include "allheaders.h"
#include "boxread.h"
#include "callcpp.h"
#include "helpers.h"
#include "tprintf.h"

#include <thread>

// Number of documents to read ahead while training. Doesn't need to be very
// large.
const int kMaxReadAhead = 8;
Expand Down Expand Up @@ -449,7 +449,7 @@ const ImageData* DocumentData::GetPage(int index) {
if (needs_loading) LoadPageInBackground(index);
// We can't directly load the page, or the background load will delete it
// while the caller is using it, so give it a chance to work.
sleep(1);
std::this_thread::sleep_for(std::chrono::seconds(1));
}
return page;
}
Expand Down
4 changes: 1 addition & 3 deletions ccutil/ccutil.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,7 @@
#include "params.h"
#include "unicharset.h"

#ifdef _WIN32
#include <windows.h>
#else
#ifndef _WIN32
#include <pthread.h>
#include <semaphore.h>
#endif
Expand Down
3 changes: 2 additions & 1 deletion ccutil/host.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@
/* _WIN32 */
#ifdef _WIN32
#include <windows.h>
#include <winbase.h> // winbase.h contains windows.h
#undef min
#undef max
#endif

#include <stdint.h> // int32_t, ...
Expand Down
1 change: 0 additions & 1 deletion ccutil/ocrclass.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@

#ifndef __GNUC__
#ifdef _WIN32
#include <windows.h>
#include "gettimeofday.h"
#endif
#else
Expand Down
2 changes: 2 additions & 0 deletions ccutil/platform.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@

#define DLLSYM
#ifdef _WIN32
#define NOMINMAX
#define WIN32_LEAN_AND_MEAN
#ifdef __GNUC__
#define ultoa _ultoa
#endif /* __GNUC__ */
Expand Down
2 changes: 2 additions & 0 deletions cmake/SourceGroups.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,15 @@ set(H_CPP "(${H}|${CPP})")
source_group("Resource files" ".*\\.(rc|ico)")

source_group("api" "${SSRC}/api/${H_CPP}")
source_group("arch" "${SSRC}/arch/${H_CPP}")
source_group("ccmain" "${SSRC}/ccmain/${H_CPP}")
source_group("ccstruct" "${SSRC}/ccstruct/${H_CPP}")
source_group("ccutil" "${SSRC}/ccutil/${H_CPP}")
source_group("classify" "${SSRC}/classify/${H_CPP}")
source_group("cube" "${SSRC}/cube/${H_CPP}")
source_group("cutil" "${SSRC}/cutil/${H_CPP}")
source_group("dict" "${SSRC}/dict/${H_CPP}")
source_group("lstm" "${SSRC}/lstm/${H_CPP}")
source_group("neural" "${SSRC}/neural_networks/runtime/${H_CPP}")
source_group("opencl" "${SSRC}/opencl/${H_CPP}")
source_group("textord" "${SSRC}/textord/${H_CPP}")
Expand Down
10 changes: 10 additions & 0 deletions cppan.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
local_settings:
cppan_dir: cppan
use_shared_libs: true

type: library

files:
- api/.*\.cpp
- arch/.*\.cpp
- ccmain/.*\.cpp
- ccstruct/.*\.cpp
- ccutil/.*\.cpp
Expand All @@ -18,6 +22,7 @@ files:
- wordrec/.*\.cpp

- api/.*\.h
- arch/.*\.h
- ccmain/.*\.h
- ccstruct/.*\.h
- ccutil/.*\.h
Expand All @@ -34,8 +39,13 @@ files:

- vs2010/port/.*

exclude_from_build:
- api/tesseractmain.cpp
- viewer/svpaint.cpp

include_directories:
private:
- arch
- classify
- cube
- cutil
Expand Down
2 changes: 1 addition & 1 deletion lstm/weightmatrix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
#define NONX86_BUILD 1
#endif

#ifndef NONX86_BUILD
#if defined(__linux__) && !defined(NONX86_BUILD)
#include <cpuid.h>
#endif
#include "dotproductavx.h"
Expand Down
2 changes: 0 additions & 2 deletions opencl/openclwrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@
// limitations under the License.
#ifdef _WIN32
#include <io.h>
#include <windows.h>

#else
#include <sys/types.h>
#include <unistd.h>
Expand Down
45 changes: 29 additions & 16 deletions training/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,11 @@ project_group (tessopt "Training Tools")

set(common_training_src
commandlineflags.cpp
commontraining.cpp
)
set(common_training_hdr
commandlineflags.h
commontraining.cpp
commontraining.h
)
add_library (common_training ${common_training_src} ${common_training_hdr})
add_library (common_training ${common_training_src})
target_link_libraries (common_training tesseract tessopt)
project_group (common_training "Training Tools")

Expand Down Expand Up @@ -159,25 +157,42 @@ target_link_libraries (wordlist2dawg tesseract)
project_group (wordlist2dawg "Training Tools")


########################################
# EXECUTABLE set_unicharset_properties
########################################

if (ICU_FOUND)

include_directories(${ICU_INCLUDE_DIRS})

add_executable (set_unicharset_properties
set_unicharset_properties.cpp
unicharset_training_utils.cpp
unicharset_training_utils.h
########################################
# LIBRARY unicharset_training
########################################

set(unicharset_training_src
fileio.cpp
fileio.h
icuerrorcode.h
normstrngs.cpp
normstrngs.h
icuerrorcode.h
unicharset_training_utils.cpp
unicharset_training_utils.h
)
target_link_libraries (set_unicharset_properties common_training ${ICU_LIBRARIES})
add_library (unicharset_training ${unicharset_training_src})
target_link_libraries (unicharset_training common_training ${ICU_LIBRARIES})
project_group (unicharset_training "Training Tools")


########################################
# EXECUTABLE lstmtraining
########################################

add_executable (lstmtraining lstmtraining.cpp)
target_link_libraries (lstmtraining unicharset_training)
project_group (lstmtraining "Training Tools")

########################################
# EXECUTABLE set_unicharset_properties
########################################

add_executable (set_unicharset_properties set_unicharset_properties.cpp)
target_link_libraries (set_unicharset_properties unicharset_training)
project_group (set_unicharset_properties "Training Tools")


Expand All @@ -199,8 +214,6 @@ set(text2image_src
boxchar.h
degradeimage.cpp
degradeimage.h
fileio.cpp
fileio.h
ligature_table.cpp
ligature_table.h
normstrngs.cpp
Expand Down
1 change: 0 additions & 1 deletion training/fileio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
*
**********************************************************************/
#ifdef _WIN32
#include <windows.h>
#ifndef unlink
#include <io.h>
#endif
Expand Down
1 change: 1 addition & 0 deletions viewer/svutil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

#include <stdio.h>
#ifdef _WIN32
#include <windows.h>
struct addrinfo {
struct sockaddr* ai_addr;
int ai_addrlen;
Expand Down
1 change: 1 addition & 0 deletions viewer/svutil.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

#ifdef _WIN32
#ifndef __GNUC__
#include "platform.h"
#include <windows.h>
#if defined(_MSC_VER) && _MSC_VER < 1900
#define snprintf _snprintf
Expand Down
2 changes: 1 addition & 1 deletion wordrec/language_model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
#include "params.h"
#include "params_training_featdef.h"

#if defined(_MSC_VER) || defined(ANDROID)
#if (defined(_MSC_VER) && _MSC_VER < 1900) || defined(ANDROID)
double log2(double n) {
return log(n) / log(2.0);
}
Expand Down

0 comments on commit 6444695

Please sign in to comment.