From ff2c445076022fd70eac05aaa740a8d1e2cd39ec Mon Sep 17 00:00:00 2001 From: Gabriel Corona Date: Tue, 9 Jun 2015 02:35:56 +0200 Subject: [PATCH] Some (partial) fixes for cross-compiling to Windows --- CMakeLists.txt | 4 +- buildtools/Cmake/AddTests.cmake | 9 +- buildtools/Cmake/CompleteInFiles.cmake | 131 ++++++++++++--------- buildtools/Cmake/GenerateDocWin.cmake | 18 +-- buildtools/Cmake/MakeLibWin.cmake | 21 +--- buildtools/Cmake/test_prog/prog_sem_open.c | 6 +- buildtools/Cross/Mingw.cmake | 14 +++ include/xbt/xbt_os_thread.h | 2 +- src/mc/mc_process.h | 1 + src/mc/mc_record.cpp | 1 + 10 files changed, 114 insertions(+), 93 deletions(-) create mode 100644 buildtools/Cross/Mingw.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index 57f1afc82b..d783249ebe 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -189,7 +189,9 @@ if(WIN32) if(NSIS_WIN_VERSION MATCHES "") set(NSIS_WIN_VERSION $ENV{PROCESSOR_ARCHITECTURE}) endif() - string(TOLOWER ${NSIS_WIN_VERSION} NSIS_WIN_VERSION) + if(${NSIS_WIN_VERSION}) + string(TOLOWER ${NSIS_WIN_VERSION} NSIS_WIN_VERSION) + endif() set(_XBT_WIN32 1) diff --git a/buildtools/Cmake/AddTests.cmake b/buildtools/Cmake/AddTests.cmake index 4c0e4460a6..a44b3666ee 100644 --- a/buildtools/Cmake/AddTests.cmake +++ b/buildtools/Cmake/AddTests.cmake @@ -21,11 +21,12 @@ SET(DROP_SITE_CDASH TRUE) SET(TRIGGER_SITE "http://cdash.inria.fr/CDash/cgi-bin/Submit-Random-TestingResults.cgi") #If you use the --read-var-info option Memcheck will run more slowly but may give a more detailed description of any illegal address. -IF(WIN32) -SET(TESH_COMMAND perl.exe ${CMAKE_BINARY_DIR}/bin/tesh) -SET(TESH_OPTION $TESH_OPTION --timeout 50) +find_program(PERL_PROGRAM NAMES perl) +SET(TESH_COMMAND ${PERL_PROGRAM} ${CMAKE_BINARY_DIR}/bin/tesh) +IF(CMAKE_HOST_WIN32) + SET(TESH_OPTION $TESH_OPTION --timeout 50) ELSE() -SET(TESH_COMMAND perl ${CMAKE_BINARY_DIR}/bin/tesh) + SET(TESH_COMMAND perl ${CMAKE_BINARY_DIR}/bin/tesh) ENDIF() #some tests may take forever on non futexes systems, using busy_wait with n cores < n workers diff --git a/buildtools/Cmake/CompleteInFiles.cmake b/buildtools/Cmake/CompleteInFiles.cmake index f7804dcc4a..e3d4bd8fb7 100644 --- a/buildtools/Cmake/CompleteInFiles.cmake +++ b/buildtools/Cmake/CompleteInFiles.cmake @@ -145,7 +145,7 @@ CHECK_INCLUDE_FILE("sys/stat.h" HAVE_SYS_STAT_H) CHECK_INCLUDE_FILE("windows.h" HAVE_WINDOWS_H) CHECK_INCLUDE_FILE("winsock.h" HAVE_WINSOCK_H) CHECK_INCLUDE_FILE("winsock2.h" HAVE_WINSOCK2_H) -CHECK_INCLUDE_FILE("WinDef.h" HAVE_WINDEF_H) +CHECK_INCLUDE_FILE("windef.h" HAVE_WINDEF_H) CHECK_INCLUDE_FILE("errno.h" HAVE_ERRNO_H) CHECK_INCLUDE_FILE("unistd.h" HAVE_UNISTD_H) CHECK_INCLUDE_FILE("execinfo.h" HAVE_EXECINFO_H) @@ -314,6 +314,7 @@ if(pthread) OUTPUT_VARIABLE HAVE_SEM_OPEN_compil ) + # Test sem_open by compiling: if(HAVE_SEM_OPEN_compil) set(HAVE_SEM_OPEN 0) message(STATUS "Warning: sem_open not compilable") @@ -323,27 +324,29 @@ if(pthread) message(STATUS "sem_open is compilable") endif() - execute_process(COMMAND ./sem_open - WORKING_DIRECTORY ${CMAKE_BINARY_DIR} - RESULT_VARIABLE HAVE_SEM_OPEN_run - OUTPUT_VARIABLE var_compil - ) - file(REMOVE sem_open) - - if(NOT HAVE_SEM_OPEN_run) - set(HAVE_SEM_OPEN 1) - message(STATUS "sem_open is executable") - else() - set(HAVE_SEM_OPEN 0) - if(EXISTS "${CMAKE_BINARY_DIR}/sem_open") - message(STATUS "Bin ${CMAKE_BINARY_DIR}/sem_open exists!") + # If we're not crosscompiling, we check by executing the program: + if (HAVE_SEM_OPEN AND NOT CMAKE_CROSSCOMPILING) + execute_process(COMMAND ./sem_open + WORKING_DIRECTORY ${CMAKE_BINARY_DIR} + RESULT_VARIABLE HAVE_SEM_OPEN_run + OUTPUT_VARIABLE var_compil + ) + if (NOT HAVE_SEM_OPEN_run) + set(HAVE_SEM_OPEN 1) + message(STATUS "sem_open is executable") else() - message(STATUS "Bin ${CMAKE_BINARY_DIR}/sem_open not exists!") + set(HAVE_SEM_OPEN 0) + if(EXISTS "${CMAKE_BINARY_DIR}/sem_open") + message(STATUS "Bin ${CMAKE_BINARY_DIR}/sem_open exists!") + else() + message(STATUS "Bin ${CMAKE_BINARY_DIR}/sem_open not exists!") + endif() + message(STATUS "Warning: sem_open not executable") + message(STATUS "Compilation output: '${var_compil}'") + message(STATUS "Exit result of sem_open: ${HAVE_SEM_OPEN_run}") endif() - message(STATUS "Warning: sem_open not executable") - message(STATUS "Compilation output: '${var_compil}'") - message(STATUS "Exit result of sem_open: ${HAVE_SEM_OPEN_run}") endif() + file(REMOVE sem_open) else() set(HAVE_SEM_OPEN 0) @@ -354,6 +357,7 @@ if(pthread) WORKING_DIRECTORY ${CMAKE_BINARY_DIR} RESULT_VARIABLE HAVE_SEM_INIT_run OUTPUT_VARIABLE HAVE_SEM_INIT_compil) + # Test sem_init by compiling: if(HAVE_SEM_INIT_compil) set(HAVE_SEM_INIT 0) message(STATUS "Warning: sem_init not compilable") @@ -362,28 +366,30 @@ if(pthread) set(HAVE_SEM_INIT 1) message(STATUS "sem_init is compilable") endif() - execute_process(COMMAND ./sem_init - WORKING_DIRECTORY ${CMAKE_BINARY_DIR} - RESULT_VARIABLE HAVE_SEM_INIT_run - OUTPUT_VARIABLE var_compil - ) - file(REMOVE sem_init) - - if(NOT HAVE_SEM_INIT_run) - set(HAVE_SEM_INIT 1) - message(STATUS "sem_init is executable") - else() - set(HAVE_SEM_INIT 0) - if(EXISTS "${CMAKE_BINARY_DIR}/sem_init") - message(STATUS "Bin ${CMAKE_BINARY_DIR}/sem_init exists!") + # If we're not crosscompiling, we check by executing the program: + if (HAVE_SEM_INIT AND NOT CMAKE_CROSSCOMPILING) + execute_process(COMMAND ./sem_init + WORKING_DIRECTORY ${CMAKE_BINARY_DIR} + RESULT_VARIABLE HAVE_SEM_INIT_run + OUTPUT_VARIABLE var_compil + ) + if (NOT HAVE_SEM_INIT_run) + set(HAVE_SEM_INIT 1) + message(STATUS "sem_init is executable") else() - message(STATUS "Bin ${CMAKE_BINARY_DIR}/sem_init not exists!") + set(HAVE_SEM_INIT 0) + if(EXISTS "${CMAKE_BINARY_DIR}/sem_init") + message(STATUS "Bin ${CMAKE_BINARY_DIR}/sem_init exists!") + else() + message(STATUS "Bin ${CMAKE_BINARY_DIR}/sem_init not exists!") + endif() + message(STATUS "Warning: sem_init not executable") + message(STATUS "Compilation output: '${var_compil}'") + message(STATUS "Exit result of sem_init: ${HAVE_SEM_INIT_run}") endif() - message(STATUS "Warning: sem_init not executable") - message(STATUS "Compilation output: '${var_compil}'") - message(STATUS "Exit result of sem_init: ${HAVE_SEM_INIT_run}") endif() + file(REMOVE sem_init) endif() if(NOT HAVE_SEM_OPEN AND NOT HAVE_SEM_INIT) @@ -592,11 +598,16 @@ if(HAVE_MAKECONTEXT OR WIN32) file(REMOVE ${CMAKE_BINARY_DIR}/conftestval) - try_run(RUN_makecontext_VAR COMPILE_makecontext_VAR - ${CMAKE_BINARY_DIR} - ${CMAKE_HOME_DIRECTORY}/buildtools/Cmake/test_prog/prog_stacksetup.c - COMPILE_DEFINITIONS "${makecontext_CPPFLAGS} ${makecontext_CPPFLAGS_2}" - ) + if(CMAKE_CROSSCOMPILING) + set(RUN_makecontext_VAR "cross") + set(COMPILE_makecontext_VAR "cross") + else() + try_run(RUN_makecontext_VAR COMPILE_makecontext_VAR + ${CMAKE_BINARY_DIR} + ${CMAKE_HOME_DIRECTORY}/buildtools/Cmake/test_prog/prog_stacksetup.c + COMPILE_DEFINITIONS "${makecontext_CPPFLAGS} ${makecontext_CPPFLAGS_2}" + ) + endif() if(EXISTS ${CMAKE_BINARY_DIR}/conftestval) file(READ ${CMAKE_BINARY_DIR}/conftestval MAKECONTEXT_ADDR_SIZE) @@ -622,15 +633,24 @@ if (NOT CMAKE_CROSSCOMPILING) ${CMAKE_BINARY_DIR} ${CMAKE_HOME_DIRECTORY}/buildtools/Cmake/test_prog/prog_stackgrowth.c ) - file(READ "${CMAKE_BINARY_DIR}/conftestval" stack) - if(stack MATCHES "down") - set(PTH_STACKGROWTH "-1") + if (RUN_makecontext_VAR) + file(READ "${CMAKE_BINARY_DIR}/conftestval" stack) + if(stack MATCHES "down") + set(PTH_STACKGROWTH "-1") + endif() + if(stack MATCHES "up") + set(PTH_STACKGROWTH "1") + endif() endif() - if(stack MATCHES "up") - set(PTH_STACKGROWTH "1") +endif() +if(NOT PTH_STACKGROWTH) + if("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "x86_64") + set(PTH_STACKGROWTH "-1") + else() + message(ERROR "Could not figure the stack direction.") endif() - endif() + ############### ## System checks ## @@ -641,11 +661,16 @@ endif() #AC_PROG_MAKE_SET -#AC_PRINTF_NULL FIXME: this is too ancient to survive! -try_run(RUN_PRINTF_NULL_VAR COMPILE_PRINTF_NULL_VAR - ${CMAKE_BINARY_DIR} - ${CMAKE_HOME_DIRECTORY}/buildtools/Cmake/test_prog/prog_printf_null.c - ) +if(CMAKE_CROSSCOMPILING) + set(RUN_PRINTF_NULL_VAR "cross") + set(COMPILE_PRINTF_NULL_VAR "cross") +else() + #AC_PRINTF_NULL FIXME: this is too ancient to survive! + try_run(RUN_PRINTF_NULL_VAR COMPILE_PRINTF_NULL_VAR + ${CMAKE_BINARY_DIR} + ${CMAKE_HOME_DIRECTORY}/buildtools/Cmake/test_prog/prog_printf_null.c + ) +endif() if(RUN_PRINTF_NULL_VAR MATCHES "FAILED_TO_RUN") SET(PRINTF_NULL_WORKING "0") diff --git a/buildtools/Cmake/GenerateDocWin.cmake b/buildtools/Cmake/GenerateDocWin.cmake index 71b7f8dba0..bfac74bf3b 100644 --- a/buildtools/Cmake/GenerateDocWin.cmake +++ b/buildtools/Cmake/GenerateDocWin.cmake @@ -1,23 +1,23 @@ #### Generate the html documentation -find_path(WGET_PATH NAMES wget.exe PATHS NO_DEFAULT_PATHS) -find_path(NSIS_PATH NAMES makensis.exe PATHS NO_DEFAULT_PATHS) +find_program(WGET_PROGRAM NAMES wget) +find_program(NSIS_PROGRAM NAMES makensi) -message(STATUS "wget: ${WGET_PATH}") -message(STATUS "nsis: ${NSIS_PATH}") +message(STATUS "wget: ${WGET_PROGRAM}") +message(STATUS "nsis: ${NSIS_PROGRAM}") -if(WGET_PATH) +if(WGET_PROGRAM) ADD_CUSTOM_TARGET(simgrid_documentation COMMENT "Downloading the SimGrid documentation..." - COMMAND ${WGET_PATH}/wget.exe -r -np -nH -nd http://simgrid.gforge.inria.fr/simgrid/${release_version}/doc/ + COMMAND ${WGET_PROGRAM} -r -np -nH -nd http://simgrid.gforge.inria.fr/simgrid/${release_version}/doc/ WORKING_DIRECTORY ${CMAKE_HOME_DIRECTORY}/doc/html ) endif() -if(NSIS_PATH) +if(NSIS_PROGRAM) ADD_CUSTOM_TARGET(nsis - COMMENT "Generating the SimGrid installor for Windows..." + COMMENT "Generating the SimGrid installer for Windows..." DEPENDS simgrid simgrid graphicator simgrid-colorizer simgrid_update_xml - COMMAND ${NSIS_PATH}/makensis.exe simgrid.nsi + COMMAND ${NSIS_PROGRAM} simgrid.nsi WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/ ) endif() diff --git a/buildtools/Cmake/MakeLibWin.cmake b/buildtools/Cmake/MakeLibWin.cmake index 49a0833039..b1a8a3ac98 100644 --- a/buildtools/Cmake/MakeLibWin.cmake +++ b/buildtools/Cmake/MakeLibWin.cmake @@ -9,26 +9,7 @@ add_library(simgrid SHARED ${simgrid_sources}) set_target_properties(simgrid PROPERTIES COMPILE_FLAGS "-D_XBT_DLL_EXPORT -DDLL_EXPORT" LINK_FLAGS "-shared" VERSION ${libsimgrid_version} PREFIX "lib" SUFFIX ".dll" IMPORT_PREFIX "lib" IMPORT_SUFFIX ".dll") - -# libpthreadGC2.dll -if(ARCH_32_BITS) - find_library(PATH_PTHREAD_LIB - NAMES pthreadGC2.dll - HINTS - $ENV{PATH} - PATH_SUFFIXES bin/ c/bin - ) -else() - find_library(PATH_PTHREAD_LIB - NAMES pthreadGC2-w64.dll - HINTS - $ENV{PATH} - PATH_SUFFIXES bin/ c/bin - ) -endif() - -set(SIMGRID_DEP "-lws2_32 -L${PATH_PTHREAD_LIB} -lm -lpthreadGC2") - +set(SIMGRID_DEP "-lws2_32 -lpthread -lm") if(ARCH_32_BITS) set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -m32 -march=i486 -D_I_X86_") diff --git a/buildtools/Cmake/test_prog/prog_sem_open.c b/buildtools/Cmake/test_prog/prog_sem_open.c index 56a2c4b916..e657cc3f0d 100644 --- a/buildtools/Cmake/test_prog/prog_sem_open.c +++ b/buildtools/Cmake/test_prog/prog_sem_open.c @@ -14,12 +14,8 @@ #define SEM_FAILED (-1) #endif -int main(void) { -#ifdef WIN32 - int s; -#else +int main(void) { sem_t * s; -#endif s = sem_open("/0", O_CREAT, 0644, 10); if (s == SEM_FAILED){ // printf("sem_open failed\n"); diff --git a/buildtools/Cross/Mingw.cmake b/buildtools/Cross/Mingw.cmake new file mode 100644 index 0000000000..14a8165313 --- /dev/null +++ b/buildtools/Cross/Mingw.cmake @@ -0,0 +1,14 @@ +# cmake -DCMAKE_TOOLCHAIN_FILE=buildtools/Cross/Mingw.cmake .. + +set (CMAKE_SYSTEM_NAME Windows) +set (CMAKE_SYSTEM_PROCESSOR x86_64) + +set (CMAKE_C_COMPILER /usr/bin/x86_64-w64-mingw32-gcc-win32) +set (CMAKE_CXX_COMPILER /usr/bin/x86_64-w64-mingw32-g++-win32) +set (CMAKE_Fortran_COMPILER /usr/bin/x86_64-w64-mingw32-gfortran-win32) + +set (CMAKE_FIND_ROOT_PATH /usr/lib/gcc/x86_64-w64-mingw32/ /usr/i686-w64-mingw32/) + +set (CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) +set (CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) +set (CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) diff --git a/include/xbt/xbt_os_thread.h b/include/xbt/xbt_os_thread.h index ebf1b6fccd..539d57befa 100644 --- a/include/xbt/xbt_os_thread.h +++ b/include/xbt/xbt_os_thread.h @@ -28,7 +28,7 @@ typedef struct xbt_os_thread_ *xbt_os_thread_t; #include #ifdef _XBT_WIN32 /* defined if this is a windows system, 32bits or 64bits) */ -#include +#include typedef DWORD xbt_os_thread_key_t; #else /* assume that every non-windows system is POSIX-compatible */ typedef pthread_key_t xbt_os_thread_key_t; diff --git a/src/mc/mc_process.h b/src/mc/mc_process.h index e3513b7739..4aba8c42c9 100644 --- a/src/mc/mc_process.h +++ b/src/mc/mc_process.h @@ -63,6 +63,7 @@ public: Process(pid_t pid, int sockfd); ~Process(); + bool is_self() const { return this->process_flags & MC_PROCESS_SELF_FLAG; diff --git a/src/mc/mc_record.cpp b/src/mc/mc_record.cpp index 72831b8a18..c8d5a079f2 100644 --- a/src/mc/mc_record.cpp +++ b/src/mc/mc_record.cpp @@ -10,6 +10,7 @@ #include #include +#include "mc_replay.h" #include "mc_record.h" #include "mc_base.h" -- 2.20.1