From 851e3a631d9f265c65dec7663a56a888d49236c4 Mon Sep 17 00:00:00 2001 From: PBerger Date: Fri, 7 Dec 2012 13:09:43 +0100 Subject: [PATCH] Fixed CMakeLists.txt, made everything compile under Windows/MSVC Added popcnt for MSVC Fixed line ending detection in parser --- CMakeLists.txt | 35 ++++++++++++++++++++++++++--------- src/mrmc.cpp | 1 + src/parser/parser.cpp | 6 ++---- src/parser/parser.h | 5 ++++- src/parser/readLabFile.cpp | 4 ++++ src/storage/BitVector.h | 5 +++++ src/utility/osDetection.h | 13 ++++++++----- 7 files changed, 50 insertions(+), 19 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 99386c34b..77b790509 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -9,17 +9,32 @@ set (MRMC_CPP_VERSION_MINOR 0) # Set all GTest references to the version in the repository and show it as output set (GTEST_INCLUDE_DIR resources/3rdparty/gtest-1.6.0/include) -set (GTEST_LIBRARY ${PROJECT_SOURCE_DIR}/resources/3rdparty/gtest-1.6.0/libgtest.a) -set (GTEST_MAIN_LIBRARY ${PROJECT_SOURCE_DIR}/resources/3rdparty/gtest-1.6.0/libgtest_main.a) +if(MSVC) + set (MRMC_LIB_SUFFIX lib) + set (GTEST_LIBRARY_DEBUG ${PROJECT_SOURCE_DIR}/resources/3rdparty/gtest-1.6.0/build/Debug/gtest.${MRMC_LIB_SUFFIX}) + set (GTEST_MAIN_LIBRARY_DEBUG ${PROJECT_SOURCE_DIR}/resources/3rdparty/gtest-1.6.0/build/Debug/gtest_main.${MRMC_LIB_SUFFIX}) + set (GTEST_LIBRARY ${PROJECT_SOURCE_DIR}/resources/3rdparty/gtest-1.6.0/build/Release/gtest.${MRMC_LIB_SUFFIX}) + set (GTEST_MAIN_LIBRARY ${PROJECT_SOURCE_DIR}/resources/3rdparty/gtest-1.6.0/build/Release/gtest_main.${MRMC_LIB_SUFFIX}) + set (GTEST_LIBRARIES optimized ${GTEST_LIBRARY} debug ${GTEST_LIBRARY_DEBUG}) +else() + set (MRMC_LIB_SUFFIX a) + set (GTEST_LIBRARY ${PROJECT_SOURCE_DIR}/resources/3rdparty/gtest-1.6.0/libgtest.${MRMC_LIB_SUFFIX}) + set (GTEST_MAIN_LIBRARY ${PROJECT_SOURCE_DIR}/resources/3rdparty/gtest-1.6.0/libgtest_main.${MRMC_LIB_SUFFIX}) + set (GTEST_LIBRARIES ${GTEST_LIBRARY}) # as we dont use FindGTest anymore +endif() message(STATUS "GTEST_INCLUDE_DIR is ${GTEST_INCLUDE_DIR}") message(STATUS "GTEST_LIBRARY is ${GTEST_LIBRARY}") message(STATUS "GTEST_MAIN_LIBRARY is ${GTEST_MAIN_LIBRARY}") # Set all log4cplus references the version in the repository set (LOG4CPLUS_INCLUDE_DIR ${PROJECT_SOURCE_DIR}/resources/3rdparty/log4cplus-1.1.0/include) -set (LOG4CPLUS_LIBRARY ${PROJECT_SOURCE_DIR}/resources/3rdparty/log4cplus-1.1.0/src/liblog4cplus.a) +if (MSVC) + set (LOG4CPLUS_LIBRARIES optimized ${PROJECT_SOURCE_DIR}/resources/3rdparty/log4cplus-1.1.0/msvc10/x64/bin.Release/log4cplusS.${MRMC_LIB_SUFFIX} debug ${PROJECT_SOURCE_DIR}/resources/3rdparty/log4cplus-1.1.0/msvc10/x64/bin.Debug/log4cplusSD.${MRMC_LIB_SUFFIX}) +else() + set (LOG4CPLUS_LIBRARIES ${PROJECT_SOURCE_DIR}/resources/3rdparty/log4cplus-1.1.0/src/liblog4cplus.${MRMC_LIB_SUFFIX}) +endif() message(STATUS "LOG4CPLUS_INCLUDE_DIR is ${LOG4CPLUS_INCLUDE_DIR}") -message(STATUS "LOG4CPLUS_LIBRARY is ${LOG4CPLUS_LIBRARY}") +message(STATUS "LOG4CPLUS_LIBRARY is ${LOG4CPLUS_LIBRARIES}") # Set all Eigen references the version in the repository set(EIGEN3_INCLUDE_DIR ${PROJECT_SOURCE_DIR}/resources/3rdparty/eigen) @@ -52,7 +67,8 @@ if(CMAKE_COMPILER_IS_GNUCC) set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mpopcnt") endif(USE_POPCNT) elseif(MSVC) - + # required for GMM to compile, ugly error directive in their code + add_definitions(/D_SCL_SECURE_NO_DEPRECATE) else(CLANG) # Set standard flags for GCC set (CMAKE_CXX_FLAGS "-std=c++11 -stdlib=libc++ -Wall -Werror -pedantic -Wno-unused-variable") @@ -88,12 +104,13 @@ source_group(Headers FILES ${MRMC_TEST_HEADERS}) source_group(Sources FILES ${MRMC_TEST_SOURCES}) # Add base folder for better inclusion paths +include_directories("${PROJECT_SOURCE_DIR}") include_directories("${PROJECT_SOURCE_DIR}/src") # Set required external packages find_package(Threads REQUIRED) find_package(Doxygen REQUIRED) -#set(Boost_USE_STATIC_LIBS ON) +set(Boost_USE_STATIC_LIBS ON) set(Boost_USE_MULTITHREADED ON) set(Boost_USE_STATIC_RUNTIME OFF) find_package(Boost REQUIRED COMPONENTS program_options) @@ -141,7 +158,7 @@ if (GTEST_INCLUDE_DIR) enable_testing() include_directories(${GTEST_INCLUDE_DIR}) - target_link_libraries(mrmc-tests ${GTEST_LIBRARY} ${GTEST_MAIN_LIBRARY}) + target_link_libraries(mrmc-tests ${GTEST_LIBRARIES}) add_test(NAME mrmc-tests COMMAND mrmc-tests) if(MSVC) # VS2012 doesn't support correctly the tuples yet @@ -151,8 +168,8 @@ endif(GTEST_INCLUDE_DIR) if (LOG4CPLUS_INCLUDE_DIR) include_directories(${LOG4CPLUS_INCLUDE_DIR}) - target_link_libraries(mrmc ${LOG4CPLUS_LIBRARY}) - target_link_libraries(mrmc-tests ${LOG4CPLUS_LIBRARY}) + target_link_libraries(mrmc ${LOG4CPLUS_LIBRARIES}) + target_link_libraries(mrmc-tests ${LOG4CPLUS_LIBRARIES}) # On Linux, we have to link against librt if (UNIX AND NOT APPLE) target_link_libraries(mrmc rt) diff --git a/src/mrmc.cpp b/src/mrmc.cpp index a63ea0f4e..c531102f5 100644 --- a/src/mrmc.cpp +++ b/src/mrmc.cpp @@ -12,6 +12,7 @@ * Description: Central part of the application containing the main() Method */ +#include "src/utility/osDetection.h" #include #include #include diff --git a/src/parser/parser.cpp b/src/parser/parser.cpp index 403ff6fd9..9e5558291 100644 --- a/src/parser/parser.cpp +++ b/src/parser/parser.cpp @@ -1,15 +1,13 @@ #include "src/parser/parser.h" #if defined LINUX || defined MACOSX - #include +# include +# include #elif defined WINDOWS #endif #include #include -//#if defined MACOSX - #include -//#endif #include #include #include diff --git a/src/parser/parser.h b/src/parser/parser.h index b7819c7be..78b8dd890 100644 --- a/src/parser/parser.h +++ b/src/parser/parser.h @@ -11,8 +11,10 @@ #include "src/utility/osDetection.h" #if defined LINUX || defined MACOSX - #include +# include #elif defined WINDOWS +# include +# include #endif #include @@ -20,6 +22,7 @@ #include #include +#include #include "src/exceptions/file_IO_exception.h" #include "src/exceptions/wrong_file_format.h" diff --git a/src/parser/readLabFile.cpp b/src/parser/readLabFile.cpp index 42a7566e2..7bb020e5a 100644 --- a/src/parser/readLabFile.cpp +++ b/src/parser/readLabFile.cpp @@ -57,7 +57,11 @@ LabParser::LabParser(uint_fast64_t node_count, const char * filename) /* * first run: obtain number of propositions */ +#ifdef WINDOWS + char separator[] = " \r\n\t"; +#else char separator[] = " \n\t"; +#endif bool foundDecl = false, foundEnd = false; uint_fast32_t proposition_count = 0; { diff --git a/src/storage/BitVector.h b/src/storage/BitVector.h index dca00e61d..a7c063eb4 100644 --- a/src/storage/BitVector.h +++ b/src/storage/BitVector.h @@ -10,6 +10,7 @@ #include "src/exceptions/invalid_argument.h" #include "src/exceptions/out_of_range.h" +#include "src/utility/osDetection.h" #include "log4cplus/logger.h" #include "log4cplus/loggingmacros.h" @@ -394,6 +395,10 @@ public: // Check if we are using g++ or clang++ and, if so, use the built-in function #if (defined (__GNUG__) || defined(__clang__)) result += __builtin_popcountll(this->bucketArray[i]); +#elif defined WINDOWS + #include + // if the target machine does not support SSE4, this will fail. + result += _mm_popcnt_u64(this->bucketArray[i]); #else uint_fast32_t cnt; uint_fast64_t bitset = this->bucketArray[i]; diff --git a/src/utility/osDetection.h b/src/utility/osDetection.h index da72a909f..a88e8354c 100644 --- a/src/utility/osDetection.h +++ b/src/utility/osDetection.h @@ -1,12 +1,15 @@ #pragma once #if defined __linux__ || defined __linux - #define LINUX +# define LINUX #elif defined TARGET_OS_MAC || defined __apple__ || defined __APPLE__ - #define MACOSX - #define _DARWIN_USE_64_BIT_INODE +# define MACOSX +# define _DARWIN_USE_64_BIT_INODE #elif defined _WIN32 || defined _WIN64 - #define WINDOWS +# define WINDOWS +# define NOMINMAX +# include +# include #else - #error Could not detect Operating System +# error Could not detect Operating System #endif