From 63c62561d84b23ab2985128f54bd46ec2c49396b Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Sun, 8 Apr 2012 20:24:14 +0400 Subject: [PATCH] fix complation with mingw and openssl --- CMakeLists.txt | 21 +++++++------------ backends/libpurple/CMakeLists.txt | 4 ++-- backends/template/CMakeLists.txt | 2 +- .../TLS/OpenSSL/OpenSSLServerContext.cpp | 9 ++++---- .../TLS/OpenSSL/OpenSSLServerContext.h | 3 ++- include/transport/CMakeLists.txt | 2 +- msvc-deps/protobuf/libprotobuf/config.h | 2 +- src/CMakeLists.txt | 16 ++++++++------ src/config.cpp | 2 +- 9 files changed, 31 insertions(+), 30 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 522fe87b..22029d2a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -6,7 +6,7 @@ set(CMAKE_MODULE_PATH "cmake_modules") set(cppunit_DIR "${CMAKE_SOURCE_DIR}/cmake_modules") find_package(cppunit) -if (WIN32) +if (NOT CMAKE_COMPILER_IS_GNUCXX) ADD_SUBDIRECTORY(msvc-deps) else() set(sqlite3_DIR "${CMAKE_SOURCE_DIR}/cmake_modules") @@ -22,6 +22,10 @@ find_package(purple) set(glib_DIR "${CMAKE_SOURCE_DIR}/cmake_modules") find_package(glib) +set(libxml2_DIR "${CMAKE_SOURCE_DIR}/cmake_modules") +find_package(libxml2) + + if (NOT WIN32) set(popt_DIR "${CMAKE_SOURCE_DIR}/cmake_modules") find_package(popt) @@ -47,7 +51,7 @@ endif() find_package(Boost COMPONENTS program_options date_time system filesystem regex signals REQUIRED) message( STATUS "Found Boost: ${Boost_LIBRARIES}, ${Boost_INCLUDE_DIR}") -if (NOT WIN32) +if (CMAKE_COMPILER_IS_GNUCXX) set(Protobuf_DIR "${CMAKE_SOURCE_DIR}/cmake_modules") find_package(Protobuf REQUIRED) else() @@ -205,23 +209,14 @@ if (WIN32) ADD_DEFINITIONS(-DLOG4CXX_STATIC) ADD_DEFINITIONS(-D_WIN32_WINNT=0x501) ADD_DEFINITIONS(-DWIN32_LEAN_AND_MEAN) +ADD_DEFINITIONS(-DBOOST_USE_WINDOWS_H) +ADD_DEFINITIONS(-DBOOST_THREAD_USE_LIB) endif() if(CMAKE_BUILD_TYPE MATCHES Debug) if (CMAKE_COMPILER_IS_GNUCXX) ADD_DEFINITIONS(-O3) ADD_DEFINITIONS(-ggdb) - ADD_DEFINITIONS(-Wall) - ADD_DEFINITIONS(-W) - ADD_DEFINITIONS(-Wcast-align) - ADD_DEFINITIONS(-Wextra -Wno-sign-compare -Wno-unused-parameter) - ADD_DEFINITIONS(-Winit-self) - ADD_DEFINITIONS(-Wmissing-declarations) - ADD_DEFINITIONS(-Wpointer-arith) - ADD_DEFINITIONS(-Wreorder) - ADD_DEFINITIONS(-Woverloaded-virtual) - ADD_DEFINITIONS(-Wsign-promo) - ADD_DEFINITIONS(-Wundef -Wunused) endif() ADD_DEFINITIONS(-DDEBUG) message("Debug : yes") diff --git a/backends/libpurple/CMakeLists.txt b/backends/libpurple/CMakeLists.txt index a01f1ab9..7d8c9f0d 100644 --- a/backends/libpurple/CMakeLists.txt +++ b/backends/libpurple/CMakeLists.txt @@ -3,11 +3,11 @@ FILE(GLOB SRC *.cpp) ADD_EXECUTABLE(spectrum2_libpurple_backend ${SRC}) -if(NOT WIN32) +if(CMAKE_COMPILER_IS_GNUCXX) target_link_libraries(spectrum2_libpurple_backend ${PURPLE_LIBRARY} ${GLIB2_LIBRARIES} ${EVENT_LIBRARIES} transport-plugin pthread) else() include_directories("${CMAKE_SOURCE_DIR}/msvc-deps/protobuf/libprotobuf") -target_link_libraries(spectrum2_libpurple_backend ${PURPLE_LIBRARY} ${GLIB2_LIBRARIES} ${EVENT_LIBRARIES} transport-plugin libprotobuf) +target_link_libraries(spectrum2_libpurple_backend ${PURPLE_LIBRARY} ${GLIB2_LIBRARIES} ${LIBXML2_LIBRARIES} ${EVENT_LIBRARIES} transport-plugin libprotobuf) endif() INSTALL(TARGETS spectrum2_libpurple_backend RUNTIME DESTINATION bin) diff --git a/backends/template/CMakeLists.txt b/backends/template/CMakeLists.txt index 52fd6fee..b40d31ef 100644 --- a/backends/template/CMakeLists.txt +++ b/backends/template/CMakeLists.txt @@ -4,7 +4,7 @@ FILE(GLOB SRC *.c *.cpp) ADD_EXECUTABLE(spectrum2_template_backend ${SRC}) -if (NOT WIN32) +if (CMAKE_COMPILER_IS_GNUCXX) target_link_libraries(spectrum2_template_backend transport pthread ${Boost_LIBRARIES} ${SWIFTEN_LIBRARY} ${LOG4CXX_LIBRARIES}) else() include_directories("${CMAKE_SOURCE_DIR}/msvc-deps/protobuf/libprotobuf") diff --git a/include/Swiften/TLS/OpenSSL/OpenSSLServerContext.cpp b/include/Swiften/TLS/OpenSSL/OpenSSLServerContext.cpp index 40218daa..c224a37a 100644 --- a/include/Swiften/TLS/OpenSSL/OpenSSLServerContext.cpp +++ b/include/Swiften/TLS/OpenSSL/OpenSSLServerContext.cpp @@ -180,15 +180,16 @@ void OpenSSLServerContext::sendPendingDataToApplication() { } } -bool OpenSSLServerContext::setServerCertificate(const PKCS12Certificate& certificate) { - if (certificate.isNull()) { +bool OpenSSLServerContext::setServerCertificate(CertificateWithKey::ref certref) { + boost::shared_ptr certificate = boost::dynamic_pointer_cast(certref); + if (certificate->isNull()) { LOG4CXX_ERROR(logger, "TLS WILL NOT WORK: Certificate can't be loaded."); return false; } // Create a PKCS12 structure BIO* bio = BIO_new(BIO_s_mem()); - BIO_write(bio, vecptr(certificate.getData()), certificate.getData().size()); + BIO_write(bio, vecptr(certificate->getData()), certificate->getData().size()); boost::shared_ptr pkcs12(d2i_PKCS12_bio(bio, NULL), PKCS12_free); BIO_free(bio); if (!pkcs12) { @@ -200,7 +201,7 @@ bool OpenSSLServerContext::setServerCertificate(const PKCS12Certificate& certifi X509 *certPtr = 0; EVP_PKEY* privateKeyPtr = 0; STACK_OF(X509)* caCertsPtr = 0; - int result = PKCS12_parse(pkcs12.get(), reinterpret_cast(vecptr(certificate.getPassword())), &privateKeyPtr, &certPtr, &caCertsPtr); + int result = PKCS12_parse(pkcs12.get(), reinterpret_cast(vecptr(certificate->getPassword())), &privateKeyPtr, &certPtr, &caCertsPtr); if (result != 1) { LOG4CXX_ERROR(logger, "TLS WILL NOT WORK: Certificate is not in PKCS#12 format."); return false; diff --git a/include/Swiften/TLS/OpenSSL/OpenSSLServerContext.h b/include/Swiften/TLS/OpenSSL/OpenSSLServerContext.h index 9d556e6f..d913c4da 100644 --- a/include/Swiften/TLS/OpenSSL/OpenSSLServerContext.h +++ b/include/Swiften/TLS/OpenSSL/OpenSSLServerContext.h @@ -12,6 +12,7 @@ #include "Swiften/TLS/TLSServerContext.h" #include "Swiften/Base/ByteArray.h" +#include namespace Swift { class PKCS12Certificate; @@ -22,7 +23,7 @@ namespace Swift { ~OpenSSLServerContext(); void connect(); - bool setServerCertificate(const PKCS12Certificate& cert); + bool setServerCertificate(CertificateWithKey::ref cert); void handleDataFromNetwork(const SafeByteArray&); void handleDataFromApplication(const SafeByteArray&); diff --git a/include/transport/CMakeLists.txt b/include/transport/CMakeLists.txt index 1104bc8f..771e051e 100644 --- a/include/transport/CMakeLists.txt +++ b/include/transport/CMakeLists.txt @@ -1,5 +1,5 @@ if (PROTOBUF_FOUND) - if (WIN32) + if (NOT CMAKE_COMPILER_IS_GNUCXX) set (PROTOBUF_PROTOC_EXECUTABLE protoc) endif() ADD_CUSTOM_COMMAND( diff --git a/msvc-deps/protobuf/libprotobuf/config.h b/msvc-deps/protobuf/libprotobuf/config.h index 2c64450a..f6e9928b 100644 --- a/msvc-deps/protobuf/libprotobuf/config.h +++ b/msvc-deps/protobuf/libprotobuf/config.h @@ -10,7 +10,7 @@ // http://blogs.msdn.com/vcblog/archive/2009/05/25/stl-breaking-changes-in-visual-studio-2010-beta-1.aspx // TODO(kenton): Use unordered_map instead, which is available in MSVC 2010. #if _MSC_VER < 1310 || _MSC_VER >= 1600 -#define HASH_NAMESPACE std +#define HASH_NAMESPACE ext #else #define HASH_NAMESPACE stdext #endif diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 75ecf494..ca1ded70 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -2,8 +2,10 @@ cmake_minimum_required(VERSION 2.6) FILE(GLOB SRC *.cpp *.h) FILE(GLOB_RECURSE SWIFTEN_SRC ../include/Swiften/*.cpp) -# Build without openssl on windows -if (WIN32) +# Build without openssl on msvc +if (CMAKE_COMPILER_IS_GNUCXX) + string(REGEX REPLACE "[^;]+;?/Schannel/[^;]+;?" "" SWIFTEN_SRC "${SWIFTEN_SRC}") +else() string(REGEX REPLACE "[^;]+;?/OpenSSL/[^;]+;?" "" SWIFTEN_SRC "${SWIFTEN_SRC}") endif() @@ -37,15 +39,17 @@ else(PROTOBUF_FOUND) endif(PROTOBUF_FOUND) if (CMAKE_COMPILER_IS_GNUCXX) - ADD_DEFINITIONS(-fPIC) + if (NOT WIN32) + ADD_DEFINITIONS(-fPIC) + endif() endif() -if (WIN32) +if (NOT CMAKE_COMPILER_IS_GNUCXX) include_directories("${CMAKE_SOURCE_DIR}/msvc-deps/protobuf/libprotobuf") TARGET_LINK_LIBRARIES(transport transport-plugin ${PQXX_LIBRARY} ${PQ_LIBRARY} ${SQLITE3_LIBRARIES} ${MYSQL_LIBRARIES} ${SWIFTEN_LIBRARY} ${PROTOBUF_LIBRARIES} ${LOG4CXX_LIBRARIES}) -else (WIN32) +else () TARGET_LINK_LIBRARIES(transport transport-plugin ${PQXX_LIBRARY} ${PQ_LIBRARY} ${SQLITE3_LIBRARIES} ${MYSQL_LIBRARIES} ${SWIFTEN_LIBRARY} ${PROTOBUF_LIBRARIES} ${LOG4CXX_LIBRARIES} ${POPT_LIBRARY}) -endif(WIN32) +endif() SET_TARGET_PROPERTIES(transport PROPERTIES VERSION ${TRANSPORT_VERSION} SOVERSION ${TRANSPORT_VERSION} diff --git a/src/config.cpp b/src/config.cpp index 5962cc25..6917d858 100644 --- a/src/config.cpp +++ b/src/config.cpp @@ -20,7 +20,7 @@ #include "transport/config.h" #include -#ifdef _MSC_VER +#ifdef _WIN32 #include #define getcwd _getcwd #include