Skip to content
Snippets Groups Projects
Commit e6ae4b56 authored by ilor's avatar ilor
Browse files

Merge branch 'win32-compat'

parents 49df8b35 22f15f15
Branches
No related tags found
No related merge requests found
...@@ -41,6 +41,9 @@ endif(CMAKE_COMPILER_IS_GNUCXX) ...@@ -41,6 +41,9 @@ endif(CMAKE_COMPILER_IS_GNUCXX)
set(LIBS "") set(LIBS "")
include_directories(${Corpus2Library_SOURCE_DIR}) include_directories(${Corpus2Library_SOURCE_DIR})
set(Boost_USE_STATIC_LIBS ON)
set(Boost_USE_MULTITHREADED ON)
set(Boost_USE_STATIC_RUNTIME OFF)
find_package(Boost 1.41 REQUIRED COMPONENTS program_options filesystem regex) find_package(Boost 1.41 REQUIRED COMPONENTS program_options filesystem regex)
set(LIBCORPUS2_INSTALL_DATA_DIR share/corpus2) set(LIBCORPUS2_INSTALL_DATA_DIR share/corpus2)
...@@ -48,7 +51,25 @@ FIND_PATH(LIBCORPUS2_SRC_DATA_DIR ...@@ -48,7 +51,25 @@ FIND_PATH(LIBCORPUS2_SRC_DATA_DIR
test.tagset test.tagset
${CMAKE_SOURCE_DIR}/corpus2data ${CMAKE_SOURCE_DIR}/corpus2data
) )
MARK_AS_ADVANCED(LIBMACA_SRC_DATA_DIR) MARK_AS_ADVANCED(LIBCORPUS2_SRC_DATA_DIR)
# For DLLs on Windows (aka SHARED libraries) you have to explicitly
# specify the external API of the library. Nothing is exported
# by default.
# For UNIX on the other hand everything is exported by default.
# We were building libraries SHARED but without specyfing
# external API. It worked on UNIX but not on Windows.
# This is changed now so add_library entries do not specify library
# type and therefore use default. Below, the default is set
# to build SHARED libs on anything but WIN32, so for Windows/cygwin
# we are building STATIC (todo: is cygwin ok w/o externs?)
# To make DLLs on Windows, exports have to be defined and then
# add_library entry changed to state SHARED for given library.
# Once this is done for all libraries, and all are marked
# explicitly as SHARED, the below will won't make a difference.
if(NOT WIN32)
set(BUILD_SHARED_LIBS TRUE)
endif(NOT WIN32)
add_subdirectory(libpwrutils) add_subdirectory(libpwrutils)
add_subdirectory(libcorpus2) add_subdirectory(libcorpus2)
......
FIND_PATH(LOKI_INCLUDE_DIR LokiExport.h /usr/include/loki /usr/local/include/loki) FIND_PATH(LOKI_INCLUDE_DIR loki/LokiExport.h /usr/include /usr/local/include)
FIND_LIBRARY(LOKI_LIBRARY NAMES loki PATH /usr/lib /usr/local/lib) FIND_LIBRARY(LOKI_LIBRARY NAMES loki PATHS /usr/lib /usr/local/lib)
MARK_AS_ADVANCED(LOKI_LIBRARY) MARK_AS_ADVANCED(LOKI_LIBRARY)
MARK_AS_ADVANCED(LOKI_INCLUDE_DIR) MARK_AS_ADVANCED(LOKI_INCLUDE_DIR)
......
...@@ -68,7 +68,7 @@ SET(libcorpus2_STAT_SRC ...@@ -68,7 +68,7 @@ SET(libcorpus2_STAT_SRC
file(GLOB_RECURSE INCS "*.h") file(GLOB_RECURSE INCS "*.h")
add_library(corpus2 SHARED ${libcorpus2_STAT_SRC} ${INCS}) add_library(corpus2 ${libcorpus2_STAT_SRC} ${INCS})
target_link_libraries(corpus2 ${LIBS}) target_link_libraries(corpus2 ${LIBS})
set_target_properties(corpus2 PROPERTIES set_target_properties(corpus2 PROPERTIES
VERSION "${corpus2_ver_major}.${corpus2_ver_minor}" VERSION "${corpus2_ver_major}.${corpus2_ver_minor}"
......
...@@ -280,7 +280,12 @@ Tag Tagset::make_tag(idx_t pos_idx, mask_t values, bool allow_extra) const ...@@ -280,7 +280,12 @@ Tag Tagset::make_tag(idx_t pos_idx, mask_t values, bool allow_extra) const
Tag Tagset::make_ign_tag() const Tag Tagset::make_ign_tag() const
{ {
#ifndef _MSC_VER
mask_t ign_pos_mask = get_pos_mask("ign"); mask_t ign_pos_mask = get_pos_mask("ign");
#else //no const char* to std::string::const_iterator conversion
static const std::string ign("ign");
mask_t ign_pos_mask = get_pos_mask(ign);
#endif
assert(ign_pos_mask.any()); assert(ign_pos_mask.any());
return Tag(ign_pos_mask); return Tag(ign_pos_mask);
} }
......
...@@ -135,7 +135,11 @@ public: ...@@ -135,7 +135,11 @@ public:
*/ */
void parse_tag(const char* c, bool allow_extra, void parse_tag(const char* c, bool allow_extra,
boost::function<void (const Tag&)> sink) const { boost::function<void (const Tag&)> sink) const {
#ifndef _MSC_VER
parse_tag(std::make_pair(c, c + strlen(c)), allow_extra, sink); parse_tag(std::make_pair(c, c + strlen(c)), allow_extra, sink);
#else // no const char* to std::string::const_iterator conversion
parse_tag(std::string(c), allow_extra, sink);
#endif
} }
/** /**
...@@ -174,7 +178,11 @@ public: ...@@ -174,7 +178,11 @@ public:
* version. * version.
*/ */
std::vector<Tag> parse_tag(const char* c, bool allow_extra) const { std::vector<Tag> parse_tag(const char* c, bool allow_extra) const {
#ifndef _MSC_VER
return parse_tag(std::make_pair(c, c + strlen(c)), allow_extra); return parse_tag(std::make_pair(c, c + strlen(c)), allow_extra);
#else // no const char* to std::string::const_iterator conversion
return parse_tag(std::string(c), allow_extra);
#endif
} }
/** /**
...@@ -201,8 +209,12 @@ public: ...@@ -201,8 +209,12 @@ public:
* version. * version.
*/ */
Tag parse_simple_tag(const char* c, bool allow_extra) const { Tag parse_simple_tag(const char* c, bool allow_extra) const {
#ifndef _MSC_VER
return parse_simple_tag(std::make_pair(c, c + strlen(c)), return parse_simple_tag(std::make_pair(c, c + strlen(c)),
allow_extra); allow_extra);
#else // no const char* to std::string::const_iterator conversion
return parse_simple_tag(std::string(c), allow_extra);
#endif
} }
/** /**
......
...@@ -56,10 +56,13 @@ namespace { ...@@ -56,10 +56,13 @@ namespace {
void TokenTimer::register_signal_handler() void TokenTimer::register_signal_handler()
{ {
#ifdef SIGUSR1
struct sigaction s; struct sigaction s;
memset(&s, 0, sizeof(s)); memset(&s, 0, sizeof(s));
s.sa_handler = &handler; s.sa_handler = &handler;
if (sigaction(SIGUSR1, &s, 0) != 0) { if (sigaction(SIGUSR1, &s, 0) != 0)
#endif
{
std::cerr << "Signal handler registration error\n"; std::cerr << "Signal handler registration error\n";
} }
} }
......
...@@ -34,7 +34,7 @@ SET(libpwrutils_STAT_SRC ...@@ -34,7 +34,7 @@ SET(libpwrutils_STAT_SRC
file(GLOB_RECURSE INCS "*.h") file(GLOB_RECURSE INCS "*.h")
add_library(pwrutils SHARED ${libpwrutils_STAT_SRC} ${INCS}) add_library(pwrutils ${libpwrutils_STAT_SRC} ${INCS})
target_link_libraries(pwrutils ${LIBS} ) target_link_libraries(pwrutils ${LIBS} )
set_target_properties(pwrutils PROPERTIES set_target_properties(pwrutils PROPERTIES
VERSION "${pwrutils_ver_major}.${pwrutils_ver_minor}" VERSION "${pwrutils_ver_major}.${pwrutils_ver_minor}"
......
...@@ -8,6 +8,10 @@ ...@@ -8,6 +8,10 @@
#include <boost/pending/lowest_bit.hpp> #include <boost/pending/lowest_bit.hpp>
#include <climits> #include <climits>
#ifdef _MSC_VER
#include <intrin.h>
#pragma intrinsic(_BitScanForward)
#endif
namespace PwrNlp { namespace PwrNlp {
...@@ -37,13 +41,6 @@ size_t count_bits_set(const std::bitset<S>& b) ...@@ -37,13 +41,6 @@ size_t count_bits_set(const std::bitset<S>& b)
return b.count(); return b.count();
} }
template <size_t S> inline
size_t lowest_bit(const bitset<S>& b)
{
// GCC specific
return b._Find_first();
}
/** /**
* Get index of lowest set bit in an integral type * Get index of lowest set bit in an integral type
*/ */
...@@ -55,8 +52,49 @@ inline size_t lowest_bit(const unsigned long long& t) ...@@ -55,8 +52,49 @@ inline size_t lowest_bit(const unsigned long long& t)
inline size_t lowest_bit(const unsigned long& t) inline size_t lowest_bit(const unsigned long& t)
{ {
#ifndef _MSC_VER
if (t <= 0) return static_cast<size_t>(-1); if (t <= 0) return static_cast<size_t>(-1);
return boost::lowest_bit(t); return boost::lowest_bit(t);
#else
unsigned long index = 0;
if(_BitScanForward(&index, t)) return index;
return static_cast<size_t>(-1);
#endif
}
template <size_t S> inline
size_t lowest_bit(const bitset<S>& b)
{
#ifdef __GNUC__
return b._Find_first();
#elif _MSC_VER
for(size_t w = 0; w <= S / ulong_bits; ++w) {
unsigned long index = 0;
if(_BitScanForward(&index, b._Getword(w))) {
return index + w * PwrNlp::ulong_bits;
}
}
return static_cast<size_t>(-1);
#else
if(b.none()) return static_cast<size_t>(-1);
const bitset<S> mask(std::numeric_limits<unsigned long>::max());
bitset<S> c(b);
unsigned long offset = 0;
unsigned long ul = (c & mask).to_ulong();
while(ul == 0) {
c >>= PwrNlp::ulong_bits;
offset += PwrNlp::ulong_bits;
ul = (c & mask).to_ulong();
}
return lowest_bit(ul) + offset;
#endif
}
template<> inline
size_t lowest_bit(const word_bitset& b)
{
return lowest_bit(b.to_ulong());
} }
/// Helper iterator class for iterating through set bits /// Helper iterator class for iterating through set bits
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment