Permalink
Browse files

Fixes for Windows compilation

  • Loading branch information...
Vincent Barichard Vincent Barichard
Vincent Barichard authored and Vincent Barichard committed Sep 25, 2014
1 parent 6c2db86 commit e271e10cbe2ae2c1be0cf74ee288262c2fb35e73
Showing with 70 additions and 103 deletions.
  1. +26 −29 CMakeLists.txt
  2. +21 −51 FindGecode.cmake
  3. +3 −3 examples/connect-four.cpp
  4. +13 −13 quacode/qcsp.hh
  5. +6 −6 quacode/qspaceinfo.hh
  6. +1 −1 quacode/search/qdfs.hpp
View
@@ -42,9 +42,7 @@ SET(BUILD_EXAMPLES ON CACHE BOOL "Build examples or not")
# and dump it in the cache along with proper documentation, otherwise set CMAKE_BUILD_TYPE
# to Debug prior to calling PROJECT()
#
IF(DEFINED CMAKE_BUILD_TYPE)
SET(CMAKE_BUILD_TYPE ${CMAKE_BUILD_TYPE} CACHE STRING "Choose the type of build, options are: None(CMAKE_CXX_FLAGS or CMAKE_C_FLAGS used) Debug Release RelWithDebInfo MinSizeRel.")
ELSE()
IF(NOT DEFINED CMAKE_BUILD_TYPE)
# Check if Gecode is configured with --enable-debug
FILE(STRINGS ${GECODE_BIN}/config.status GECODE_DEBUG_BUILD REGEX "S\\[\"DEBUG_BUILD\"\\]=")
IF(GECODE_DEBUG_BUILD MATCHES "yes")
@@ -69,10 +67,14 @@ ELSE()
ENDIF()
SET(LOG_AUDIT ${QUACODE_AUDIT} CACHE BOOL "Set to true to generate log output.")
# determine, whether we want a static binary
SET(STATIC_LINKING FALSE CACHE BOOL "Build a static binary?")
# do we want static libraries?
IF(STATIC_LINKING)
IF(UNIX)
# determine, whether we want a static binary
SET(STATIC_LINKING FALSE CACHE BOOL "Build a static binary?")
# do we want static libraries?
IF(STATIC_LINKING)
SET(BUILD_SHARED_LIBS OFF)
# To know in source file that we compil static
ADD_DEFINITIONS(-DQUACODE_STATIC_LIBS)
# When STATIC_LINKING is TRUE, than cmake looks for libraries ending
# with .a. This is for linux only!
SET(CMAKE_FIND_LIBRARY_SUFFIXES ".a")
@@ -83,9 +85,13 @@ IF(STATIC_LINKING)
# Use static libs for Boost
SET(Boost_USE_STATIC_LIBS ON)
SET(Boost_USE_STATIC_RUNTIME ON)
ENDIF(STATIC_LINKING)
ELSE(STATIC_LINKING)
SET(BUILD_SHARED_LIBS ON)
ENDIF(STATIC_LINKING)
ELSE(UNIX)
SET(BUILD_SHARED_LIBS ON)
ENDIF(UNIX)
INCLUDE(CheckCXXCompilerFlag)
SET(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_MODULE_PATH})
FIND_PACKAGE(Gecode)
@@ -97,6 +103,9 @@ ELSE (NOT GECODE_FOUND)
INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR})
INCLUDE_DIRECTORIES(${GECODE_SRC})
LINK_DIRECTORIES(${CMAKE_CURRENT_BINARY_DIR})
LINK_DIRECTORIES(${GECODE_BIN})
IF (CMAKE_COMPILER_IS_GNUCXX)
ADD_DEFINITIONS(-Wall)
ADD_DEFINITIONS(-Wextra)
@@ -112,17 +121,14 @@ ELSE (NOT GECODE_FOUND)
ADD_DEFINITIONS(-DLOG_AUDIT)
ENDIF()
INCLUDE(CheckCXXCompilerFlag)
check_cxx_compiler_flag(-fvisibility=hidden HAVE_VISIBILITY_HIDDEN_FLAG)
IF (HAVE_VISIBILITY_HIDDEN_FLAG)
SET(GECODE_GCC_HAS_CLASS_VISIBILITY "/**/")
ADD_DEFINITIONS(-fvisibility=hidden)
ADD_DEFINITIONS(-DQUACODE_GCC_HAS_CLASS_VISIBILITY)
ENDIF()
IF (WIN32)
SET(GECODE_THREADS_WINDOWS 1)
ELSE ()
SET(GECODE_THREADS_PTHREADS 1)
ENDIF ()
FIND_PACKAGE(Threads)
SET(QUACODE_HEADERS
quacode/qcsp.hh
@@ -168,31 +174,22 @@ ELSE (NOT GECODE_FOUND)
SET_SOURCE_FILES_PROPERTIES(${ALL_HPP} PROPERTIES HEADER_FILE_ONLY TRUE)
ADD_LIBRARY(quacode ${QUACODE_SRCS} ${QUACODE_HEADERS} ${QUACODE_HPP})
SET_TARGET_PROPERTIES(quacode PROPERTIES DEFINE_SYMBOL "GECODE_BUILD_QUACODE")
SET(QUACODE_LIBRARIES "")
IF (BUILD_SHARED_LIBS)
SET(QUACODE_LIBRARIES -L${CMAKE_CURRENT_BINARY_DIR} -lquacode)
ELSE()
SET(QUACODE_LIBRARIES quacode)
ENDIF()
SET_TARGET_PROPERTIES(quacode PROPERTIES COMPILE_DEFINITIONS "BUILD_QUACODE_LIB")
SET(QUACODE_LIBRARIES quacode)
IF(BUILD_EXAMPLES)
# Add targets for examples
FOREACH (example ${QUACODE_EXAMPLES_SRCS})
GET_FILENAME_COMPONENT(exampleBin ${example} NAME_WE)
ADD_EXECUTABLE(${exampleBin} ${example})
TARGET_LINK_LIBRARIES(${exampleBin} ${QUACODE_LIBRARIES} ${GECODE_LIBRARIES} pthread)
TARGET_LINK_LIBRARIES(${exampleBin} ${QUACODE_LIBRARIES} ${GECODE_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT})
# set -static, when STATIC_LINKING is TRUE and set LINK_SEARCH_END_STATIC
# to remove the additional -bdynamic from the linker line.
IF(STATIC_LINKING)
IF(UNIX AND STATIC_LINKING)
SET(CMAKE_EXE_LINKER_FLAGS "-static")
SET_TARGET_PROPERTIES(${exampleBin} PROPERTIES LINK_SEARCH_END_STATIC 1)
ENDIF(STATIC_LINKING)
IF (BUILD_SHARED_LIBS)
ADD_DEPENDENCIES(${exampleBin} quacode)
ENDIF()
ENDIF(UNIX AND STATIC_LINKING)
ENDFOREACH ()
ENDIF(BUILD_EXAMPLES)
View
@@ -35,84 +35,54 @@
SET(GECODE_SEARCH_PATH ${GECODE_BIN} /usr/lib /usr/local/lib)
FIND_LIBRARY(GECODE_KERNEL_LIBRARIES gecodekernel ${GECODE_SEARCH_PATH})
FILE(STRINGS ${GECODE_BIN}/config.status GECODE_DLL_ARCH LIMIT_COUNT 1 REGEX "S\\[\"DLL_ARCH\"\\]=")
STRING(REGEX MATCH "=\"[^\"]*" GECODE_DLL_ARCH "${GECODE_DLL_ARCH}")
STRING(SUBSTRING "${GECODE_DLL_ARCH}" 2 -1 GECODE_DLL_ARCH)
FIND_LIBRARY(GECODE_KERNEL_LIBRARIES gecodekernel${GECODE_DLL_ARCH} ${GECODE_SEARCH_PATH})
IF(GECODE_KERNEL_LIBRARIES)
SET(GECODE_FOUND TRUE)
GET_FILENAME_COMPONENT(LPATH ${GECODE_KERNEL_LIBRARIES} PATH)
SET(GECODE_KERNEL_LIBRARIES "-L${LPATH} -lgecodekernel")
SET(GECODE_LIBRARIES ${GECODE_KERNEL_LIBRARIES})
FIND_LIBRARY(GECODE_SUPPORT_LIBRARIES gecodesupport ${GECODE_SEARCH_PATH})
FIND_LIBRARY(GECODE_SUPPORT_LIBRARIES gecodesupport${GECODE_DLL_ARCH} ${GECODE_SEARCH_PATH})
IF(GECODE_SUPPORT_LIBRARIES)
GET_FILENAME_COMPONENT(LPATH ${GECODE_SUPPORT_LIBRARIES} PATH)
SET(GECODE_SUPPORT_LIBRARIES "-L${LPATH} -lgecodesupport")
STRING(REPLACE "-L${LPATH} " "" GECODE_LIBRARIES ${GECODE_LIBRARIES})
SET(GECODE_LIBRARIES "${GECODE_SUPPORT_LIBRARIES} ${GECODE_LIBRARIES}")
SET(GECODE_LIBRARIES ${GECODE_SUPPORT_LIBRARIES} ${GECODE_LIBRARIES})
ENDIF(GECODE_SUPPORT_LIBRARIES)
FIND_LIBRARY(GECODE_INT_LIBRARIES gecodeint ${GECODE_SEARCH_PATH})
FIND_LIBRARY(GECODE_INT_LIBRARIES gecodeint${GECODE_DLL_ARCH} ${GECODE_SEARCH_PATH})
IF(GECODE_INT_LIBRARIES)
GET_FILENAME_COMPONENT(LPATH ${GECODE_INT_LIBRARIES} PATH)
SET(GECODE_INT_LIBRARIES "-L${LPATH} -lgecodeint")
STRING(REPLACE "-L${LPATH} " "" GECODE_LIBRARIES ${GECODE_LIBRARIES})
SET(GECODE_LIBRARIES "${GECODE_INT_LIBRARIES} ${GECODE_LIBRARIES}")
SET(GECODE_LIBRARIES ${GECODE_INT_LIBRARIES} ${GECODE_LIBRARIES})
ENDIF(GECODE_INT_LIBRARIES)
FIND_LIBRARY(GECODE_FLOAT_LIBRARIES gecodefloat ${GECODE_SEARCH_PATH})
FIND_LIBRARY(GECODE_FLOAT_LIBRARIES gecodefloat${GECODE_DLL_ARCH} ${GECODE_SEARCH_PATH})
IF(GECODE_FLOAT_LIBRARIES)
GET_FILENAME_COMPONENT(LPATH ${GECODE_FLOAT_LIBRARIES} PATH)
SET(GECODE_FLOAT_LIBRARIES "-L${LPATH} -lgecodefloat")
STRING(REPLACE "-L${LPATH} " "" GECODE_LIBRARIES ${GECODE_LIBRARIES})
SET(GECODE_LIBRARIES "${GECODE_FLOAT_LIBRARIES} ${GECODE_LIBRARIES}")
SET(GECODE_LIBRARIES ${GECODE_FLOAT_LIBRARIES} ${GECODE_LIBRARIES})
ENDIF(GECODE_FLOAT_LIBRARIES)
FIND_LIBRARY(GECODE_SET_LIBRARIES gecodeset ${GECODE_SEARCH_PATH})
FIND_LIBRARY(GECODE_SET_LIBRARIES gecodeset${GECODE_DLL_ARCH} ${GECODE_SEARCH_PATH})
IF(GECODE_SET_LIBRARIES)
GET_FILENAME_COMPONENT(LPATH ${GECODE_SET_LIBRARIES} PATH)
SET(GECODE_SET_LIBRARIES "-L${LPATH} -lgecodeset")
STRING(REPLACE "-L${LPATH} " "" GECODE_LIBRARIES ${GECODE_LIBRARIES})
SET(GECODE_LIBRARIES "${GECODE_SET_LIBRARIES} ${GECODE_LIBRARIES}")
SET(GECODE_LIBRARIES ${GECODE_SET_LIBRARIES} ${GECODE_LIBRARIES})
ENDIF(GECODE_SET_LIBRARIES)
FIND_LIBRARY(GECODE_SEARCH_LIBRARIES gecodesearch ${GECODE_SEARCH_PATH})
FIND_LIBRARY(GECODE_SEARCH_LIBRARIES gecodesearch${GECODE_DLL_ARCH} ${GECODE_SEARCH_PATH})
IF(GECODE_SEARCH_LIBRARIES)
GET_FILENAME_COMPONENT(LPATH ${GECODE_SEARCH_LIBRARIES} PATH)
SET(GECODE_SEARCH_LIBRARIES "-L${LPATH} -lgecodesearch")
STRING(REPLACE "-L${LPATH} " "" GECODE_LIBRARIES ${GECODE_LIBRARIES})
SET(GECODE_LIBRARIES "${GECODE_SEARCH_LIBRARIES} ${GECODE_LIBRARIES}")
SET(GECODE_LIBRARIES ${GECODE_SEARCH_LIBRARIES} ${GECODE_LIBRARIES})
ENDIF(GECODE_SEARCH_LIBRARIES)
FIND_LIBRARY(GECODE_MINIMODEL_LIBRARIES gecodeminimodel ${GECODE_SEARCH_PATH})
FIND_LIBRARY(GECODE_MINIMODEL_LIBRARIES gecodeminimodel${GECODE_DLL_ARCH} ${GECODE_SEARCH_PATH})
IF(GECODE_MINIMODEL_LIBRARIES)
GET_FILENAME_COMPONENT(LPATH ${GECODE_MINIMODEL_LIBRARIES} PATH)
SET(GECODE_MINIMODEL_LIBRARIES "-L${LPATH} -lgecodeminimodel")
STRING(REPLACE "-L${LPATH} " "" GECODE_LIBRARIES ${GECODE_LIBRARIES})
SET(GECODE_LIBRARIES "${GECODE_MINIMODEL_LIBRARIES} ${GECODE_LIBRARIES}")
SET(GECODE_LIBRARIES ${GECODE_MINIMODEL_LIBRARIES} ${GECODE_LIBRARIES})
ENDIF(GECODE_MINIMODEL_LIBRARIES)
# FIND_LIBRARY(GECODE_FLATZINC_LIBRARIES gecodeflatzinc ${GECODE_SEARCH_PATH})
# IF(GECODE_FLATZINC_LIBRARIES)
# GET_FILENAME_COMPONENT(LPATH ${GECODE_FLATZINC_LIBRARIES} PATH)
# SET(GECODE_FLATZINC_LIBRARIES "-L${LPATH} -lgecodeflatzinc")
# STRING(REPLACE "-L${LPATH} " "" GECODE_LIBRARIES ${GECODE_LIBRARIES})
# SET(GECODE_LIBRARIES "${GECODE_FLATZINC_LIBRARIES} ${GECODE_LIBRARIES}")
# ENDIF(GECODE_FLATZINC_LIBRARIES)
FIND_LIBRARY(GECODE_DRIVER_LIBRARIES gecodedriver ${GECODE_SEARCH_PATH})
FIND_LIBRARY(GECODE_DRIVER_LIBRARIES gecodedriver${GECODE_DLL_ARCH} ${GECODE_SEARCH_PATH})
IF(GECODE_DRIVER_LIBRARIES)
GET_FILENAME_COMPONENT(LPATH ${GECODE_DRIVER_LIBRARIES} PATH)
SET(GECODE_DRIVER_LIBRARIES "-L${LPATH} -lgecodedriver")
STRING(REPLACE "-L${LPATH} " "" GECODE_LIBRARIES ${GECODE_LIBRARIES})
SET(GECODE_LIBRARIES "${GECODE_DRIVER_LIBRARIES} ${GECODE_LIBRARIES}")
SET(GECODE_LIBRARIES ${GECODE_DRIVER_LIBRARIES} ${GECODE_LIBRARIES})
ENDIF(GECODE_DRIVER_LIBRARIES)
FIND_LIBRARY(GECODE_GIST_LIBRARIES gecodegist ${GECODE_SEARCH_PATH})
FIND_LIBRARY(GECODE_GIST_LIBRARIES gecodegist${GECODE_DLL_ARCH} ${GECODE_SEARCH_PATH})
IF(GECODE_GIST_LIBRARIES)
GET_FILENAME_COMPONENT(LPATH ${GECODE_GIST_LIBRARIES} PATH)
SET(GECODE_GIST_LIBRARIES "-L${LPATH} -lgecodegist")
STRING(REPLACE "-L${LPATH} " "" GECODE_LIBRARIES ${GECODE_LIBRARIES})
SET(GECODE_LIBRARIES "${GECODE_GIST_LIBRARIES} ${GECODE_LIBRARIES}")
SET(GECODE_LIBRARIES ${GECODE_GIST_LIBRARIES} ${GECODE_LIBRARIES})
ENDIF(GECODE_GIST_LIBRARIES)
ENDIF(GECODE_KERNEL_LIBRARIES)
@@ -445,7 +445,7 @@ class ConnectFourAllState : public Script, public QSpaceInfo {
int c4Heuristic(IntVar x, int k) const {
if (k == 0) return x.max();
int boardBefore[row*col];
std::vector<int> boardBefore(row*col);
int offSet = row*col*(k-1);
for (int i=row-1; i>=0; i--)
for (int j=0; j<col; j++) {
@@ -488,7 +488,7 @@ class ConnectFourAllState : public Script, public QSpaceInfo {
}
template <int Player>
int check3lines(int board[]) const {
int check3lines(std::vector<int>& board) const {
int lines = 0;
// Detect winning blocks
for (int z=0; z<4; z++) { // Row(0) / Col(1) / Diag1(2) / Diag2(3)
@@ -526,7 +526,7 @@ class ConnectFourAllState : public Script, public QSpaceInfo {
}
template <int Player>
bool checklines(int board[]) const {
bool checklines(std::vector<int>& board) const {
// Detect winning blocks
for (int z=0; z<4; z++) { // Row(0) / Col(1) / Diag1(2) / Diag2(3)
for (int i=0; i < col; i++) {
View
@@ -34,30 +34,30 @@
*
*/
#ifndef __GECODE_QCSP_HH__
#define __GECODE_QCSP_HH__
#ifndef __QCSP_HH__
#define __QCSP_HH__
#include <gecode/kernel.hh>
/*
* Configure linking
*
*/
#if !defined(GECODE_STATIC_LIBS) && \
#if !defined(QUACODE_STATIC_LIB) && \
(defined(__CYGWIN__) || defined(__MINGW32__) || defined(_MSC_VER))
#ifdef GECODE_BUILD_QUACODE
#define GECODE_QCSP_EXPORT __declspec( dllexport )
#ifdef BUILD_QUACODE_LIB
#define QUACODE_EXPORT __declspec( dllexport )
#else
#define GECODE_QCSP_EXPORT __declspec( dllimport )
#define QUACODE_EXPORT __declspec( dllimport )
#endif
#else
#ifdef GECODE_GCC_HAS_CLASS_VISIBILITY
#define GECODE_QCSP_EXPORT __attribute__ ((visibility("default")))
#ifdef QUACODE_GCC_HAS_CLASS_VISIBILITY
#define QUACODE_EXPORT __attribute__ ((visibility("default")))
#else
#define GECODE_QCSP_EXPORT
#define QUACODE_EXPORT
#endif
#endif
@@ -176,7 +176,7 @@ namespace Gecode {
a[i] = x[i];
}
/// Allocate array with \a n elements and initialize with \a e0, ...
GECODE_QCSP_EXPORT
QUACODE_EXPORT
QuantArgs(int n, TQuantifier e0, ...) : PrimArgArray<TQuantifier>(n) {
va_list args;
va_start(args, e0);
@@ -197,7 +197,7 @@ namespace Gecode {
* Posts propagator for \f$ x_0 \diamond_{\mathit{o}} x_1 = x_2\f$
* \ingroup TaskModelIntRelBool
*/
GECODE_QCSP_EXPORT void
QUACODE_EXPORT void
qrel(Home home, QBoolVar qx0, BoolOpType o, QBoolVar qx1, BoolVar x2);
/** \brief Post domain consistent propagator for Quantified Boolean clause with positive variables \a x and negative variables \a y
@@ -210,7 +210,7 @@ namespace Gecode {
* from BOT_AND or BOT_OR.
* \ingroup TaskModelIntRelBool
*/
GECODE_QCSP_EXPORT void
QUACODE_EXPORT void
qclause(Home home, BoolOpType o, QBoolVarArgs x, QBoolVarArgs y,
BoolVar z);
/** \brief Post domain consistent propagator for Quantified Boolean clause with positive variables \a x and negative variables \a y
@@ -226,7 +226,7 @@ namespace Gecode {
* from BOT_AND or BOT_OR.
* \ingroup TaskModelIntRelBool
*/
GECODE_QCSP_EXPORT void
QUACODE_EXPORT void
qclause(Home home, BoolOpType o, QBoolVarArgs x, QBoolVarArgs y,
int n);
}
View
@@ -99,7 +99,7 @@ namespace Gecode {
// The storage of strategy is not obvious, for previous example, it will be:
// |id(x)|v1(x)|id(y)|v(y)|id(z)|v1(z)|v2(z)|v2(x)|id(y)|v(y)|id(z)|v1(z)|v2(z)|v3(x)|id(y)|v(y)|id(z)|v1(z)|v2(z)|
// Forward declaration
class Strategy {
class QUACODE_EXPORT Strategy {
friend class DynamicStrategy;
friend class DynamicExpandStrategy;
friend class StrategyExplore;
@@ -217,7 +217,7 @@ namespace Gecode {
// are expanded.
// For static expanded strategy, some data structures of Strategy are unused. For example
// curBranch is not needed as we don't need to know about the backtrack
class StaticExpandStrategy : public Strategy {
class QUACODE_EXPORT StaticExpandStrategy : public Strategy {
// Copy constructor
StaticExpandStrategy(const StaticExpandStrategy& s);
@@ -252,7 +252,7 @@ namespace Gecode {
// So it may increases computing time. But it does not require to allocate the
// full strategy in memory, so it may be uses to store strategies which cannot be
// stored with full tree, but are smaller because sub-trees are cut during the search.
class DynamicStrategy : public Strategy {
class QUACODE_EXPORT DynamicStrategy : public Strategy {
// Print current strategy
void print(std::ostream& os, Box* p, unsigned int curRemainingBlockSize, int depth) const;
@@ -309,7 +309,7 @@ namespace Gecode {
// are expanded.
// For dynamic expanded strategy, we use the curBranch data structure to store the blocks
// allowed. These blocks will be freed when backtrack because of failure
class DynamicExpandStrategy : public DynamicStrategy {
class QUACODE_EXPORT DynamicExpandStrategy : public DynamicStrategy {
// Copy constructor
DynamicExpandStrategy(const DynamicExpandStrategy& s);
// Convert constructor
@@ -370,7 +370,7 @@ namespace Gecode {
};
class QSpaceInfo {
class QUACODE_EXPORT QSpaceInfo {
friend class StaticExpandStrategy;
friend class DynamicExpandStrategy;
template<class View> friend class ::Gecode::Int::Watch;
@@ -439,7 +439,7 @@ namespace Gecode {
const std::vector<LkBinderVarObj>& linkIdVars(void) const;
};
class QSpaceSharedInfo : public SharedHandle {
class QUACODE_EXPORT QSpaceSharedInfo : public SharedHandle {
public:
/// Constructor
QSpaceSharedInfo(void);
View
@@ -38,7 +38,7 @@ namespace Gecode {
namespace Search {
/// Create depth-first engine for quantified variables
GECODE_QCSP_EXPORT Engine* qdfs(Space* s, const Options& o);
QUACODE_EXPORT Engine* qdfs(Space* s, const Options& o);
}
template<class T>

0 comments on commit e271e10

Please sign in to comment.