From 12a3d01e7de3d8fdefa0aeedeb0cee96936567f0 Mon Sep 17 00:00:00 2001 From: navarrop Date: Mon, 13 Sep 2010 08:23:36 +0000 Subject: [PATCH] Windows compatibility. git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/simgrid/simgrid/trunk@8175 48e7efb5-ca39-0410-a469-dd3cf9ba447f --- CMakeLists.txt | 41 ++++++++++++++++++--------- buildtools/Cmake/DefinePackages.cmake | 26 +++++++++++------ buildtools/Cmake/MakeExeLibWin.cmake | 29 +++++-------------- src/CMakeLists.txt | 6 +++- src/simix/smx_context.c | 6 ++-- src/win32/config.h | 16 +++++------ src/xbt/xbt_sg_stubs.c | 2 ++ testsuite/simdag/CMakeLists.txt | 4 +++ testsuite/surf/CMakeLists.txt | 10 ++++++- testsuite/xbt/CMakeLists.txt | 6 ++++ tools/gras/CMakeLists.txt | 6 +++- 11 files changed, 95 insertions(+), 57 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index a8ac91d054..333be68663 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -34,32 +34,25 @@ ELSE(SIZEOF_LONG EQUAL 4) ENDIF(SIZEOF_LONG EQUAL 4) if(WIN32) + set(INCLUDES_MORE $ENV{INCLUDE}) string(REPLACE "\\" "/" INCLUDES_MORE "${INCLUDES_MORE}") foreach(include_dir ${INCLUDES_MORE}) set(INCLUDES "${INCLUDES} -I\"${include_dir}\"") endforeach(include_dir ${INCLUDES_MORE}) - message("Be sure all those variables are correctely set.") - message(" -- C_COMPILER $ENV{CC}") - message(" -- CXX_COMPILER $ENV{CXX}") - message(" -- RC_COMPILER $ENV{RC}") - message(" -- INCLUDE $ENV{INCLUDE}") - message(" -- LIB $ENV{LIB}") - message(" -- MAKE_PROGRAM ${CMAKE_MAKE_PROGRAM}") - message(" -- CMAKE_BUILD_TOOL ${CMAKE_BUILD_TOOL}") - message(" -- LINKER ${CMAKE_LINKER}") - message(" -- CMAKE_GENERATOR ${CMAKE_GENERATOR}") - message(" -- INCLUDES ${INCLUDES}") - message(" -- BORLAND ${BORLAND}") - message(" -- VISUALC ${MSVC}") - message(" -- GNUC ${CMAKE_COMPILER_IS_GNUCC}\n\n") + set(INCLUDES "${INCLUDES} -I${PROJECT_DIRECTORY}/include/xbt -I${PROJECT_DIRECTORY}/src/xbt") #for win32_ucontext.[ch] + if(BORLAND) ### BORLAND COMPILER set(__BORLANDC__ 1) + set(CMAKE_COMPILER_IS_GNUCC 0) + set(MSVC 0) set(_XBT_BORLANDC_COMPILER 1) endif(BORLAND) if(MSVC) ### MicroSoftVisualC COMPILER set(__VISUALC__ 1) + set(BORLAND 0) + set(CMAKE_COMPILER_IS_GNUCC 0) set(_XBT_VISUALC_COMPILER 1) set(_MSC_VER 1) set(__STRICT_ANSI__ 1) @@ -68,6 +61,8 @@ if(WIN32) if(CMAKE_COMPILER_IS_GNUCC) set(__GNUC__ 1) + set(MSVC 0) + set(BORLAND 0) endif(CMAKE_COMPILER_IS_GNUCC) if(ARCH_32_BITS) ### Arch 32bits @@ -77,6 +72,22 @@ if(WIN32) endif(ARCH_32_BITS) set(_XBT_WIN32 1) + + message("Be sure all those variables are correctely set.") + message(" -- C_COMPILER $ENV{CC}") + message(" -- CXX_COMPILER $ENV{CXX}") + message(" -- RC_COMPILER $ENV{RC}") + message(" -- INCLUDE $ENV{INCLUDE}") + message(" -- LIB $ENV{LIB}") + message(" -- MAKE_PROGRAM ${CMAKE_MAKE_PROGRAM}") + message(" -- CMAKE_BUILD_TOOL ${CMAKE_BUILD_TOOL}") + message(" -- LINKER ${CMAKE_LINKER}") + message(" -- CMAKE_GENERATOR ${CMAKE_GENERATOR}") + message(" -- INCLUDES ${INCLUDES}") + message(" -- BORLAND ${BORLAND}") + message(" -- VISUALC ${MSVC}") + message(" -- GNUC ${CMAKE_COMPILER_IS_GNUCC}\n\n") + endif(WIN32) add_definitions (${INCLUDES}) @@ -123,8 +134,10 @@ if(HAVE_JAVA) endif(HAVE_JAVA) ### Make tests +if(NOT WIN32) include(${PROJECT_DIRECTORY}/buildtools/Cmake/AddTests.cmake) include(${PROJECT_DIRECTORY}/buildtools/Cmake/CTestConfig.cmake) +endif(NOT WIN32) ### Setup the distrib include(${PROJECT_DIRECTORY}/buildtools/Cmake/Distrib.cmake) diff --git a/buildtools/Cmake/DefinePackages.cmake b/buildtools/Cmake/DefinePackages.cmake index 1c01327d2e..ed0ef3191e 100755 --- a/buildtools/Cmake/DefinePackages.cmake +++ b/buildtools/Cmake/DefinePackages.cmake @@ -445,7 +445,7 @@ src/xbt/xbt_synchro.c ### depend of some variables setted upper # -->CONTEXT_THREADS -if(${CONTEXT_THREADS} OR WIN32) +if(${CONTEXT_THREADS}) #pthread set(SURF_SRC ${SURF_SRC} src/xbt/xbt_os_thread.c @@ -455,17 +455,27 @@ if(${CONTEXT_THREADS} OR WIN32) ${EXTRA_DIST} src/simix/smx_context_sysv.c ) -else(${CONTEXT_THREADS} OR WIN32) +else(${CONTEXT_THREADS}) #ucontext set(SURF_SRC ${SURF_SRC} src/simix/smx_context_sysv.c ) - set(EXTRA_DIST - ${EXTRA_DIST} - src/xbt/xbt_os_thread.c - src/simix/smx_context_thread.c - ) -endif(${CONTEXT_THREADS} OR WIN32) + + if(WIN32) + set(SURF_SRC + ${SURF_SRC} + src/xbt/xbt_os_thread.c + src/simix/smx_context_thread.c) + else(WIN32) + set(EXTRA_DIST + ${EXTRA_DIST} + src/xbt/xbt_os_thread.c + src/simix/smx_context_thread.c) + endif(WIN32) +endif(${CONTEXT_THREADS}) + + + # -->HAVE_GTNETS if(HAVE_GTNETS) diff --git a/buildtools/Cmake/MakeExeLibWin.cmake b/buildtools/Cmake/MakeExeLibWin.cmake index 56e8e53a6a..df0fc0596a 100644 --- a/buildtools/Cmake/MakeExeLibWin.cmake +++ b/buildtools/Cmake/MakeExeLibWin.cmake @@ -1,28 +1,18 @@ ### Make Libs - -add_library(simgrid SHARED ${simgrid_sources}) -add_library(simgrid_static STATIC ${simgrid_sources}) -add_library(gras SHARED ${gras_sources}) -add_library(gras_static STATIC ${gras_sources}) - -set_target_properties(simgrid PROPERTIES VERSION ${libsimgrid_version}) -set_target_properties(gras PROPERTIES VERSION ${libgras_version}) - +#>gcc c:\simgrid-trunk\examples\msg\icomms\peer.c -static -Lc:\simgrid-trunk\lib -lsimgrid -Ic:\simgrid-trunk\include -lwsock32 +add_library(simgrid STATIC ${simgrid_sources}) +add_library(gras STATIC ${gras_sources}) if(MSVC) - set_target_properties(gras PROPERTIES COMPILE_FLAGS "/D _XBT_DLL_EXPORT") - set_target_properties(gras_static PROPERTIES COMPILE_FLAGS "/D _XBT_DLL_STATIC" + set_target_properties(gras PROPERTIES COMPILE_FLAGS "/D _XBT_DLL_STATIC" OUTPUT_NAME "gras") - set_target_properties(simgrid PROPERTIES COMPILE_FLAGS "/D _XBT_DLL_EXPORT") - set_target_properties(simgrid_static PROPERTIES COMPILE_FLAGS "/D _XBT_DLL_STATIC" + set_target_properties(simgrid PROPERTIES COMPILE_FLAGS "/D _XBT_DLL_STATIC" OUTPUT_NAME "simgrid") else(MSVC) if(CMAKE_COMPILER_IS_GNUCC) - set_target_properties(gras PROPERTIES COMPILE_FLAGS "-D _XBT_DLL_EXPORT") - set_target_properties(gras_static PROPERTIES COMPILE_FLAGS "-D _XBT_DLL_STATIC" + set_target_properties(gras PROPERTIES COMPILE_FLAGS "-D _XBT_DLL_STATIC" OUTPUT_NAME "gras") - set_target_properties(simgrid PROPERTIES COMPILE_FLAGS "-D _XBT_DLL_EXPORT") - set_target_properties(simgrid_static PROPERTIES COMPILE_FLAGS "-D _XBT_DLL_STATIC" + set_target_properties(simgrid PROPERTIES COMPILE_FLAGS "-D _XBT_DLL_STATIC" OUTPUT_NAME "simgrid") else(CMAKE_COMPILER_IS_GNUCC) message(FATAL_ERROR "Compilateur non connu!!!") @@ -33,9 +23,7 @@ set(GRAS_DEP "wsock32") set(SIMGRID_DEP "wsock32") target_link_libraries(simgrid ${SIMGRID_DEP}) -target_link_libraries(simgrid_static ${SIMGRID_DEP}) target_link_libraries(gras ${GRAS_DEP}) -target_link_libraries(gras_static ${GRAS_DEP}) ### Make EXEs @@ -48,8 +36,5 @@ add_subdirectory(${PROJECT_DIRECTORY}/examples/msg/icomms) #testsuite/xbt add_subdirectory(${PROJECT_DIRECTORY}/testsuite/xbt) -#testsuite/surf -add_subdirectory(${PROJECT_DIRECTORY}/testsuite/surf) - #testsuite/simdag add_subdirectory(${PROJECT_DIRECTORY}/testsuite/simdag) \ No newline at end of file diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 876654bf87..9554134b2f 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -13,6 +13,10 @@ PROPERTIES GENERATED true) add_executable(testall ${USE_TEST_UNITS}) ### Add definitions for compile -target_link_libraries(testall gras m) +if(NOT WIN32) + target_link_libraries(testall gras m) +else(NOT WIN32) + target_link_libraries(testall gras) +endif(NOT WIN32) add_dependencies(testall units_files) \ No newline at end of file diff --git a/src/simix/smx_context.c b/src/simix/smx_context.c index 09c75b03bd..77efb14038 100644 --- a/src/simix/smx_context.c +++ b/src/simix/smx_context.c @@ -18,7 +18,7 @@ #ifdef HAVE_RUBY void SIMIX_ctx_ruby_factory_init(smx_context_factory_t *factory); #endif - + XBT_LOG_NEW_DEFAULT_SUBCATEGORY(simix_context, simix, "Context switching mecanism"); const char *xbt_ctx_factory_to_use = NULL; @@ -37,9 +37,11 @@ void SIMIX_context_mod_init(void) #ifdef CONTEXT_THREADS /* context switch based os thread */ SIMIX_ctx_thread_factory_init(&simix_global->context_factory); -#elif !defined(_XBT_WIN32) +#elif defined(CONTEXT_UCONTEXT) /* context switch based ucontext */ SIMIX_ctx_sysv_factory_init(&simix_global->context_factory); +#elif defined(_XBT_WIN32) + /* context switch based windows */ #else /* context switch is not allowed on Windows */ #error ERROR [__FILE__, line __LINE__]: no context based implementation specified. diff --git a/src/win32/config.h b/src/win32/config.h index fa25dbc6dd..c276c69546 100644 --- a/src/win32/config.h +++ b/src/win32/config.h @@ -17,17 +17,17 @@ #if defined(_XBT_BORLAND_COMPILER) -# include - + # include #elif defined(__GNUC__) - /* data comes from autoconf when using gnuc (cross-compiling?) */ -# include "gras_config.h" -typedef unsigned int uint32_t; - + /* data comes from autoconf when using gnuc (cross-compiling?) */ + # include "gras_config.h" + #ifndef _XBT_WIN32 + typedef unsigned int uint32_t; + #endif #elif defined(_XBT_VISUALC_COMPILER) -# include + # include # else -# error "Unknown compiler - please report the problems to the main simgrid mailing list (http://gforge.inria.fr/mail/?group_id=12)" + # error "Unknown compiler - please report the problems to the main simgrid mailing list (http://gforge.inria.fr/mail/?group_id=12)" #endif typedef int socklen_t; diff --git a/src/xbt/xbt_sg_stubs.c b/src/xbt/xbt_sg_stubs.c index b609c109d3..56a9bbe117 100644 --- a/src/xbt/xbt_sg_stubs.c +++ b/src/xbt/xbt_sg_stubs.c @@ -21,6 +21,7 @@ #include "portable.h" /* CONTEXT_THREADS */ #ifndef CONTEXT_THREADS +#ifndef WIN32 /* xbt_threads is loaded in libsimgrid when they are used to implement the xbt_context. * The decision (and the loading) is made in xbt/context.c. @@ -141,3 +142,4 @@ void xbt_os_cond_destroy(xbt_os_cond_t cond) ("No pthread in SG when compiled against the ucontext (xbt_os_cond_destroy)"); } #endif +#endif diff --git a/testsuite/simdag/CMakeLists.txt b/testsuite/simdag/CMakeLists.txt index 72c239380d..972e780350 100644 --- a/testsuite/simdag/CMakeLists.txt +++ b/testsuite/simdag/CMakeLists.txt @@ -5,4 +5,8 @@ set(EXECUTABLE_OUTPUT_PATH "${PROJECT_DIRECTORY}/testsuite/simdag/") add_executable(sd_test sd_test.c) ### Add definitions for compile +if(NOT WIN32) target_link_libraries(sd_test simgrid m ) +else(NOT WIN32) +target_link_libraries(sd_test simgrid ) +endif(NOT WIN32) diff --git a/testsuite/surf/CMakeLists.txt b/testsuite/surf/CMakeLists.txt index 8b617d9162..a6ec710f2f 100644 --- a/testsuite/surf/CMakeLists.txt +++ b/testsuite/surf/CMakeLists.txt @@ -9,8 +9,16 @@ add_executable(surf_usage2 "surf_usage2.c") add_executable(trace_usage "trace_usage.c") ### Add definitions for compile +if(NOT WIN32) target_link_libraries(lmm_usage simgrid m ) target_link_libraries(maxmin_bench simgrid m ) target_link_libraries(surf_usage simgrid m ) target_link_libraries(surf_usage2 simgrid m ) -target_link_libraries(trace_usage simgrid m ) +target_link_libraries(trace_usage simgrid m ) +else(NOT WIN32) +target_link_libraries(lmm_usage simgrid ) +target_link_libraries(maxmin_bench simgrid ) +target_link_libraries(surf_usage simgrid ) +target_link_libraries(surf_usage2 simgrid ) +target_link_libraries(trace_usage simgrid ) +endif(NOT WIN32) \ No newline at end of file diff --git a/testsuite/xbt/CMakeLists.txt b/testsuite/xbt/CMakeLists.txt index f6593ec07f..69a1cdafb9 100644 --- a/testsuite/xbt/CMakeLists.txt +++ b/testsuite/xbt/CMakeLists.txt @@ -7,6 +7,12 @@ add_executable(graphxml_usage "graphxml_usage.c") add_executable(heap_bench "heap_bench.c") ### Add definitions for compile +if(NOT WIN32) target_link_libraries(log_usage gras m ) target_link_libraries(graphxml_usage simgrid m ) target_link_libraries(heap_bench gras m ) +else(NOT WIN32) +target_link_libraries(log_usage gras ) +target_link_libraries(graphxml_usage simgrid ) +target_link_libraries(heap_bench gras ) +endif(NOT WIN32) \ No newline at end of file diff --git a/tools/gras/CMakeLists.txt b/tools/gras/CMakeLists.txt index cb2501361a..7897ee2af6 100644 --- a/tools/gras/CMakeLists.txt +++ b/tools/gras/CMakeLists.txt @@ -5,4 +5,8 @@ set(EXECUTABLE_OUTPUT_PATH "${CMAKE_BINARY_DIR}/bin") add_executable(gras_stub_generator stub_generator.c unix_stub_generator.c windows_stub_generator.c) ### Add definitions for compile -target_link_libraries(gras_stub_generator simgrid pthread m) \ No newline at end of file +if(NOT WIN32) + target_link_libraries(gras_stub_generator gras simgrid pthread m) +else(NOT WIN32) + target_link_libraries(gras_stub_generator gras simgrid) +endif(NOT WIN32) \ No newline at end of file -- 2.20.1