From 6db8abf95cef7cda4ff7e9cecd8bef90c066ac2a Mon Sep 17 00:00:00 2001 From: kaetemi Date: Fri, 20 Feb 2015 16:24:19 +0100 Subject: [PATCH] Visual Studio 2013 compilation support for NLMISC --HG-- branch : develop --- code/CMakeLists.txt | 10 +- code/CMakeModules/FindIconv.cmake | 131 +++++++++++-------------- code/CMakeModules/FindMSVC.cmake | 2 +- code/CMakeModules/nel.cmake | 19 +++- code/nel/include/nel/misc/types_nl.h | 6 ++ code/nel/src/misc/debug.cpp | 29 +++--- code/nel/src/misc/displayer.cpp | 26 ++--- code/nel/src/misc/words_dictionary.cpp | 2 +- 8 files changed, 114 insertions(+), 111 deletions(-) diff --git a/code/CMakeLists.txt b/code/CMakeLists.txt index dcc9f9c93..0ffef9c1e 100644 --- a/code/CMakeLists.txt +++ b/code/CMakeLists.txt @@ -112,16 +112,20 @@ IF(WITH_STATIC_LIBXML2) SET(LIBXML2_DEFINITIONS ${LIBXML2_DEFINITIONS} -DLIBXML_STATIC) ENDIF(WITH_STATIC_LIBXML2) +IF(WITH_LIBXML2_ICONV) + FIND_PACKAGE(Iconv REQUIRED) + INCLUDE_DIRECTORIES(${ICONV_INCLUDE_DIR}) + SET(LIBXML2_LIBRARIES ${LIBXML2_LIBRARIES} ${ICONV_LIBRARIES}) +ENDIF(WITH_LIBXML2_ICONV) + IF(WITH_STATIC) # libxml2 could need winsock2 library SET(LIBXML2_LIBRARIES ${LIBXML2_LIBRARIES} ${WINSOCK2_LIB}) # on Mac OS X libxml2 requires iconv and liblzma IF(APPLE) - FIND_PACKAGE(Iconv REQUIRED) FIND_PACKAGE(LibLZMA REQUIRED) - SET(LIBXML2_LIBRARIES ${LIBXML2_LIBRARIES} ${ICONV_LIBRARIES} ${LIBLZMA_LIBRARIES}) - INCLUDE_DIRECTORIES(${ICONV_INCLUDE_DIR}) + SET(LIBXML2_LIBRARIES ${LIBXML2_LIBRARIES} ${LIBLZMA_LIBRARIES}) ENDIF(APPLE) ENDIF(WITH_STATIC) diff --git a/code/CMakeModules/FindIconv.cmake b/code/CMakeModules/FindIconv.cmake index 5e9e48250..092b35702 100644 --- a/code/CMakeModules/FindIconv.cmake +++ b/code/CMakeModules/FindIconv.cmake @@ -1,4 +1,4 @@ -# - Try to find Iconv on Mac OS X +# - Try to find Iconv # Once done this will define # # ICONV_FOUND - system has Iconv @@ -6,78 +6,59 @@ # ICONV_LIBRARIES - Link these to use Iconv # ICONV_SECOND_ARGUMENT_IS_CONST - the second argument for iconv() is const # +include(CheckCCompilerFlag) +include(CheckCSourceCompiles) -IF(APPLE) - include(CheckCCompilerFlag) - include(CheckCSourceCompiles) - - IF (ICONV_INCLUDE_DIR AND ICONV_LIBRARIES) - # Already in cache, be silent - SET(ICONV_FIND_QUIETLY TRUE) - ENDIF (ICONV_INCLUDE_DIR AND ICONV_LIBRARIES) - - IF(APPLE) - FIND_PATH(ICONV_INCLUDE_DIR iconv.h - PATHS - /opt/local/include/ - NO_CMAKE_SYSTEM_PATH - ) - - FIND_LIBRARY(ICONV_LIBRARIES NAMES iconv libiconv c - PATHS - /opt/local/lib/ - NO_CMAKE_SYSTEM_PATH - ) - ENDIF(APPLE) - - FIND_PATH(ICONV_INCLUDE_DIR iconv.h PATHS /opt/local/include /sw/include) - - string(REGEX REPLACE "(.*)/include/?" "\\1" ICONV_INCLUDE_BASE_DIR "${ICONV_INCLUDE_DIR}") - - FIND_LIBRARY(ICONV_LIBRARIES NAMES iconv libiconv c HINTS "${ICONV_INCLUDE_BASE_DIR}/lib" PATHS /opt/local/lib) - - IF(ICONV_INCLUDE_DIR AND ICONV_LIBRARIES) - SET(ICONV_FOUND TRUE) - ENDIF(ICONV_INCLUDE_DIR AND ICONV_LIBRARIES) - - set(CMAKE_REQUIRED_INCLUDES ${ICONV_INCLUDE_DIR}) - set(CMAKE_REQUIRED_LIBRARIES ${ICONV_LIBRARIES}) - IF(ICONV_FOUND) - check_c_compiler_flag("-Werror" ICONV_HAVE_WERROR) - set (CMAKE_C_FLAGS_BACKUP "${CMAKE_C_FLAGS}") - if(ICONV_HAVE_WERROR) - set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Werror") - endif(ICONV_HAVE_WERROR) - check_c_source_compiles(" - #include - int main(){ - iconv_t conv = 0; - const char* in = 0; - size_t ilen = 0; - char* out = 0; - size_t olen = 0; - iconv(conv, &in, &ilen, &out, &olen); - return 0; - } - " ICONV_SECOND_ARGUMENT_IS_CONST ) - set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS_BACKUP}") - ENDIF(ICONV_FOUND) - set(CMAKE_REQUIRED_INCLUDES) - set(CMAKE_REQUIRED_LIBRARIES) - - IF(ICONV_FOUND) - IF(NOT ICONV_FIND_QUIETLY) - MESSAGE(STATUS "Found Iconv: ${ICONV_LIBRARIES}") - ENDIF(NOT ICONV_FIND_QUIETLY) - ELSE(ICONV_FOUND) - IF(Iconv_FIND_REQUIRED) - MESSAGE(FATAL_ERROR "Could not find Iconv") - ENDIF(Iconv_FIND_REQUIRED) - ENDIF(ICONV_FOUND) - - MARK_AS_ADVANCED( - ICONV_INCLUDE_DIR - ICONV_LIBRARIES - ICONV_SECOND_ARGUMENT_IS_CONST - ) -ENDIF(APPLE) +IF (ICONV_INCLUDE_DIR AND ICONV_LIBRARIES) + # Already in cache, be silent + SET(ICONV_FIND_QUIETLY TRUE) +ENDIF (ICONV_INCLUDE_DIR AND ICONV_LIBRARIES) + +FIND_PATH(ICONV_INCLUDE_DIR iconv.h HINTS /sw/include/ PATHS /opt/local) + +FIND_LIBRARY(ICONV_LIBRARIES NAMES iconv libiconv c PATHS /opt/local) + +IF(ICONV_INCLUDE_DIR AND ICONV_LIBRARIES) + SET(ICONV_FOUND TRUE) +ENDIF(ICONV_INCLUDE_DIR AND ICONV_LIBRARIES) + +set(CMAKE_REQUIRED_INCLUDES ${ICONV_INCLUDE_DIR}) +set(CMAKE_REQUIRED_LIBRARIES ${ICONV_LIBRARIES}) +IF(ICONV_FOUND) + check_c_compiler_flag("-Werror" ICONV_HAVE_WERROR) + set (CMAKE_C_FLAGS_BACKUP "${CMAKE_C_FLAGS}") + if(ICONV_HAVE_WERROR) + set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Werror") + endif(ICONV_HAVE_WERROR) + check_c_source_compiles(" + #include + int main(){ + iconv_t conv = 0; + const char* in = 0; + size_t ilen = 0; + char* out = 0; + size_t olen = 0; + iconv(conv, &in, &ilen, &out, &olen); + return 0; + } +" ICONV_SECOND_ARGUMENT_IS_CONST ) + set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS_BACKUP}") +ENDIF(ICONV_FOUND) +set(CMAKE_REQUIRED_INCLUDES) +set(CMAKE_REQUIRED_LIBRARIES) + +IF(ICONV_FOUND) + IF(NOT ICONV_FIND_QUIETLY) + MESSAGE(STATUS "Found Iconv: ${ICONV_LIBRARIES}") + ENDIF(NOT ICONV_FIND_QUIETLY) +ELSE(ICONV_FOUND) + IF(Iconv_FIND_REQUIRED) + MESSAGE(FATAL_ERROR "Could not find Iconv") + ENDIF(Iconv_FIND_REQUIRED) +ENDIF(ICONV_FOUND) + +MARK_AS_ADVANCED( + ICONV_INCLUDE_DIR + ICONV_LIBRARIES + ICONV_SECOND_ARGUMENT_IS_CONST +) diff --git a/code/CMakeModules/FindMSVC.cmake b/code/CMakeModules/FindMSVC.cmake index 644fc57e6..94146775d 100644 --- a/code/CMakeModules/FindMSVC.cmake +++ b/code/CMakeModules/FindMSVC.cmake @@ -62,7 +62,7 @@ IF(MSVC12) IF(NOT MSVC12_REDIST_DIR) # If you have VC++ 2013 Express, put x64/Microsoft.VC120.CRT/*.dll in ${EXTERNAL_PATH}/redist SET(MSVC12_REDIST_DIR "${EXTERNAL_PATH}/redist") - ENDIF(NOT MSVC11_REDIST_DIR) + ENDIF(NOT MSVC12_REDIST_DIR) ELSEIF(MSVC11) DETECT_VC_VERSION("11.0") SET(MSVC_TOOLSET "110") diff --git a/code/CMakeModules/nel.cmake b/code/CMakeModules/nel.cmake index 15f6d131d..081da67ca 100644 --- a/code/CMakeModules/nel.cmake +++ b/code/CMakeModules/nel.cmake @@ -255,6 +255,11 @@ MACRO(NL_SETUP_DEFAULT_OPTIONS) ELSE(WITH_STATIC) OPTION(WITH_STATIC_LIBXML2 "With static libxml2" OFF) ENDIF(WITH_STATIC) + IF(APPLE) + OPTION(WITH_LIBXML2_ICONV "With libxml2 using iconv" ON ) + ELSE(APPLE) + OPTION(WITH_LIBXML2_ICONV "With libxml2 using iconv" OFF) + ENDIF(APPLE) OPTION(WITH_STATIC_DRIVERS "With static drivers." OFF) IF(WIN32) OPTION(WITH_EXTERNAL "With provided external." ON ) @@ -558,9 +563,15 @@ MACRO(NL_SETUP_BUILD) # Ignore default include paths ADD_PLATFORM_FLAGS("/X") - IF(MSVC11) + IF(MSVC12) ADD_PLATFORM_FLAGS("/Gy- /MP") - # /Ox is working with VC++ 2010, but custom optimizations don't exist + # /Ox is working with VC++ 2013, but custom optimizations don't exist + SET(RELEASE_CFLAGS "/Ox /GF /GS- ${RELEASE_CFLAGS}") + # without inlining it's unusable, use custom optimizations again + SET(DEBUG_CFLAGS "/Od /Ob1 /GF- ${DEBUG_CFLAGS}") + ELSEIF(MSVC11) + ADD_PLATFORM_FLAGS("/Gy- /MP") + # /Ox is working with VC++ 2012, but custom optimizations don't exist SET(RELEASE_CFLAGS "/Ox /GF /GS- ${RELEASE_CFLAGS}") # without inlining it's unusable, use custom optimizations again SET(DEBUG_CFLAGS "/Od /Ob1 /GF- ${DEBUG_CFLAGS}") @@ -582,9 +593,9 @@ MACRO(NL_SETUP_BUILD) SET(RELEASE_CFLAGS "/Ox /GF /GS- ${RELEASE_CFLAGS}") # without inlining it's unusable, use custom optimizations again SET(DEBUG_CFLAGS "/Od /Ob1 ${DEBUG_CFLAGS}") - ELSE(MSVC11) + ELSE(MSVC12) MESSAGE(FATAL_ERROR "Can't determine compiler version ${MSVC_VERSION}") - ENDIF(MSVC11) + ENDIF(MSVC12) ADD_PLATFORM_FLAGS("/D_CRT_SECURE_NO_DEPRECATE /D_CRT_SECURE_NO_WARNINGS /D_CRT_NONSTDC_NO_WARNINGS /DWIN32 /D_WINDOWS /Zm1000 /wd4250") diff --git a/code/nel/include/nel/misc/types_nl.h b/code/nel/include/nel/misc/types_nl.h index f1ed871fc..7a6ee2662 100644 --- a/code/nel/include/nel/misc/types_nl.h +++ b/code/nel/include/nel/misc/types_nl.h @@ -414,6 +414,12 @@ extern void operator delete[](void *p) throw(); # define CHashMap stdext::hash_map # define CHashSet stdext::hash_set # define CHashMultiMap stdext::hash_multimap +#elif defined(NL_COMP_VC) && (NL_COMP_VC_VERSION == 110) +# include +# include +# define CHashMap ::std::hash_map +# define CHashSet ::std::hash_set +# define CHashMultiMap ::std::hash_multimap #elif defined(NL_COMP_GCC) // GCC4 # include # include diff --git a/code/nel/src/misc/debug.cpp b/code/nel/src/misc/debug.cpp index c7667acc2..a4037607f 100644 --- a/code/nel/src/misc/debug.cpp +++ b/code/nel/src/misc/debug.cpp @@ -17,20 +17,6 @@ #include "stdmisc.h" #include "nel/misc/types_nl.h" -#include "nel/misc/debug.h" - -#ifdef HAVE_NELCONFIG_H -# include "nelconfig.h" -#endif // HAVE_NELCONFIG_H - -#include "nel/misc/log.h" -#include "nel/misc/displayer.h" -#include "nel/misc/mem_displayer.h" -#include "nel/misc/command.h" -#include "nel/misc/report.h" -#include "nel/misc/path.h" -#include "nel/misc/variable.h" -#include "nel/misc/system_info.h" #ifdef NL_OS_WINDOWS # define _WIN32_WINDOWS 0x0410 @@ -59,6 +45,21 @@ # include #endif +#include "nel/misc/debug.h" + +#ifdef HAVE_NELCONFIG_H +# include "nelconfig.h" +#endif // HAVE_NELCONFIG_H + +#include "nel/misc/log.h" +#include "nel/misc/displayer.h" +#include "nel/misc/mem_displayer.h" +#include "nel/misc/command.h" +#include "nel/misc/report.h" +#include "nel/misc/path.h" +#include "nel/misc/variable.h" +#include "nel/misc/system_info.h" + #define NL_NO_DEBUG_FILES 1 using namespace std; diff --git a/code/nel/src/misc/displayer.cpp b/code/nel/src/misc/displayer.cpp index d48c44d02..8b6b7a577 100644 --- a/code/nel/src/misc/displayer.cpp +++ b/code/nel/src/misc/displayer.cpp @@ -18,6 +18,19 @@ #include "nel/misc/types_nl.h" +#ifdef NL_OS_WINDOWS +// these defines is for IsDebuggerPresent(). it'll not compile on windows 95 +// just comment this and the IsDebuggerPresent to compile on windows 95 +# define _WIN32_WINDOWS 0x0410 +# ifndef NL_COMP_MINGW +# define WINVER 0x0400 +# define NOMINMAX +# endif +# include +#else +# define IsDebuggerPresent() false +#endif + #ifdef NL_OS_WINDOWS # include # include @@ -35,19 +48,6 @@ #include "nel/misc/debug.h" -#ifdef NL_OS_WINDOWS -// these defines is for IsDebuggerPresent(). it'll not compile on windows 95 -// just comment this and the IsDebuggerPresent to compile on windows 95 -# define _WIN32_WINDOWS 0x0410 -# ifndef NL_COMP_MINGW -# define WINVER 0x0400 -# define NOMINMAX -# endif -# include -#else -# define IsDebuggerPresent() false -#endif - #include "nel/misc/displayer.h" using namespace std; diff --git a/code/nel/src/misc/words_dictionary.cpp b/code/nel/src/misc/words_dictionary.cpp index e2113e62d..4d5057dd7 100644 --- a/code/nel/src/misc/words_dictionary.cpp +++ b/code/nel/src/misc/words_dictionary.cpp @@ -251,7 +251,7 @@ void CWordsDictionary::exactLookupByKey( const CSString& key, CVectorSString& re */ inline CSString CWordsDictionary::makeResult( const CSString &key, const CSString &word ) { - return key + CSString(": ") + word; + return key + ": " + word.c_str(); }