diff options
author | Marius Kintel <marius@kintel.net> | 2012-01-04 17:01:21 (GMT) |
---|---|---|
committer | Marius Kintel <marius@kintel.net> | 2012-01-04 17:01:21 (GMT) |
commit | 5b503543a4befe057a38a0250261b53066200ffb (patch) | |
tree | 9299349df9c5b5a85a2c1e500f44dfcc866a799a | |
parent | cc147f9612e176f111737c5936e4acc46bb0be81 (diff) | |
parent | f5b1e37f2d4a080826a55d2b783f17c1389f6805 (diff) |
Merge pull request #56 from openscad/mingw_cross_tests
Mingw cross tests
-rw-r--r-- | doc/testing.txt | 16 | ||||
-rw-r--r-- | tests/CMakeLists.txt | 61 | ||||
-rw-r--r-- | tests/CMingw-cross-env.cmake | 144 | ||||
-rw-r--r-- | tests/FindGLEW.cmake | 6 | ||||
-rw-r--r-- | tests/OffscreenContextWGL.cc | 4 | ||||
-rw-r--r-- | tests/dumptest.cc | 3 | ||||
-rw-r--r-- | tests/echotest.cc | 2 | ||||
-rwxr-xr-x | tests/test_cmdline_tool.py | 24 |
8 files changed, 224 insertions, 36 deletions
diff --git a/doc/testing.txt b/doc/testing.txt index a50c95f..f690939 100644 --- a/doc/testing.txt +++ b/doc/testing.txt @@ -10,7 +10,7 @@ $ cd tests $ cmake . $ make -Windows: +Windows + MSVC: First, get a normal build working by following instructions at http://en.wikibooks.org/wiki/OpenSCAD_User_Manual/Building_on_Windows @@ -22,6 +22,10 @@ Then, from the QT command prompt: > cmake . > nmake -f Makefile +Cross compiling Linux->Win32: + +Please see openscad/tests/CMingw-cross-env.cmake for instructions. + B) Running tests $ ctest Runs tests enabled by default @@ -80,11 +84,7 @@ A pretty-printed index.html is in a subdir of tests/build/Testing/Temporary Expected results are found in tests/regression/* Actual results are found in tests/build/testname-output/* -3. Cross-compiling - -Cross-compiling of tests has not been automated nor tested - -4. Image-based tests takes a long time, they fail, and the log says 'return -11' +3. Image-based tests takes a long time, they fail, and the log says 'return -11' Imagemagick may have crashed while comparing the expected images to the test-run generated (actual) images. You can try using the alternate @@ -92,12 +92,12 @@ ImageMagick comparison method by by erasing CMakeCache, and re-running cmake with -DCOMPARATOR=ncc. This will enable the Normalized Cross Comparison method. -5. Testing images fails with 'morphology not found" for ImageMagick in the log +4. Testing images fails with 'morphology not found" for ImageMagick in the log Your version of imagemagick is old. Upgrade, or pass -DCOMPARATOR=old to cmake. The comparison will be of lowered reliability. -6. Other issues +5. Other issues The OpenSCAD User Manual has a section on buildling. Please check there for updates: diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index cdcc0c0..e2920d8 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -13,6 +13,9 @@ set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}") # Build debug build as default if(NOT CMAKE_BUILD_TYPE) set(CMAKE_BUILD_TYPE RelWithDebInfo) +endif() + +if(CMAKE_COMPILER_IS_GNUCXX) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-strict-aliasing") endif() @@ -24,11 +27,11 @@ endif() # Windows # -if(WIN32) +if(WIN32 AND MSVC) set(WIN32_STATIC_BUILD "True") endif() -if(WIN32_STATIC_BUILD) +if(WIN32_STATIC_BUILD AND MSVC) if(${CMAKE_BUILD_TYPE} STREQUAL "Debug") set(EMSG "\nTo build Win32 STATIC OpenSCAD please see doc/testing.txt") message(FATAL_ERROR ${EMSG}) @@ -36,7 +39,7 @@ if(WIN32_STATIC_BUILD) endif() # Disable warnings -if(WIN32) +if(WIN32 AND MSVC) # too long decorated names set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /wd4503") # int cast to bool in CGAL @@ -52,7 +55,7 @@ if(WIN32) endif() # Debugging - if you uncomment, use nmake -f Makefile > log.txt (the log is big) -if(WIN32) +if(WIN32 AND MSVC) # Linker debugging #set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -VERBOSE") @@ -60,15 +63,19 @@ if(WIN32) # you have to pass -DCMAKE_VERBOSE_MAKEFILE=ON to cmake when you run it. endif() +if(WIN32 AND CMAKE_COMPILER_IS_GNUCXX) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fpermissive -frounding-math") +endif() + # # Build test apps # function(inclusion user_set_path found_paths) - # This function exists as a wrapper for INCLUDE_DIRECTORIES - # to deal with systems in which some libraries are found - # in the system paths, (/usr) but others are found in customized - # paths set in environment variables (CGAL_DIR). + # If user_set_path indicates an env. variable was specifically + # set by the user, then found_paths become an include priority (prepend); + # otherwise found_paths are stuck on the end of the include flags (append). + # message(STATUS "inclusion ${user_set_path} ${found_paths}") # message(STATUS "inclusion ${${user_set_path}} ${${found_paths}}") set( inclusion_match 0 ) @@ -88,6 +95,10 @@ function(inclusion user_set_path found_paths) endfunction() # Boost +# +# FindBoost.cmake has been included from Cmake's GIT circa the end of 2011 +# because most existing installs of cmake had a buggy older version. +# # Update this if FindBoost.cmake gets out of sync with the current boost release # set(Boost_ADDITIONAL_VERSIONS "1.47.0" "1.46.0") @@ -132,8 +143,17 @@ endif(${CMAKE_SYSTEM_NAME} MATCHES "Darwin") set(CMAKE_INCLUDE_DIRECTORIES_BEFORE ON) find_package(OpenGL REQUIRED) -find_package(Qt4 COMPONENTS QtCore QtGui QtOpenGL REQUIRED) -include(${QT_USE_FILE}) + +if (MINGW_CROSS_ENV_DIR) + mingw_cross_env_find_qt() + mingw_cross_env_info() + include_directories( ${QT_INCLUDE_DIRS} ) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${QT_CFLAGS_OTHER}") +else() + find_package(Qt4 COMPONENTS QtCore QtGui QtOpenGL REQUIRED) + include(${QT_USE_FILE}) +endif() + set(CMAKE_INCLUDE_DIRECTORIES_BEFORE OFF) # Eigen2 @@ -256,11 +276,13 @@ inclusion(CGAL_DIR CGAL_INCLUDE_DIRS) # Imagemagick -find_package(ImageMagick COMPONENTS convert) -if (ImageMagick_convert_FOUND) - message(STATUS "ImageMagick convert executable found: " ${ImageMagick_convert_EXECUTABLE}) -else() - message(FATAL_ERROR "Couldn't find imagemagick 'convert' program") +if (NOT SKIP_IMAGEMAGICK) + find_package(ImageMagick COMPONENTS convert) + if (ImageMagick_convert_FOUND) + message(STATUS "ImageMagick convert executable found: " ${ImageMagick_convert_EXECUTABLE}) + else() + message(FATAL_ERROR "Couldn't find imagemagick 'convert' program") + endif() endif() # Internal includes @@ -348,6 +370,7 @@ set(OFFSCREEN_SOURCES system-gl.cc) add_library(tests-core STATIC ${CORE_SOURCES}) +target_link_libraries(tests-core ${OPENGL_LIBRARY}) add_library(tests-common STATIC ${COMMON_SOURCES}) target_link_libraries(tests-common tests-core) add_library(tests-cgal STATIC ${CGAL_SOURCES}) @@ -515,7 +538,10 @@ macro(add_cmdline_test TESTCMD TESTSUFFIX) set(CONFARG CONFIGURATIONS) set(CONFVAL ${FOUNDCONFIGS}) - add_test(NAME ${TEST_FULLNAME} ${CONFARG} ${CONFVAL} COMMAND ${PYTHON_EXECUTABLE} ${tests_SOURCE_DIR}/test_cmdline_tool.py --comparator=${COMPARATOR} -c ${ImageMagick_convert_EXECUTABLE} -s ${TESTSUFFIX} ${CMAKE_BINARY_DIR}/${TESTCMD} "${SCADFILE}") + if (MINGW_CROSS_ENV_DIR) + set( MINGW_CROSS_ARG "--mingw-cross-env" ) + endif() + add_test(NAME ${TEST_FULLNAME} ${CONFARG} ${CONFVAL} COMMAND ${PYTHON_EXECUTABLE} ${tests_SOURCE_DIR}/test_cmdline_tool.py ${MINGW_CROSS_ARG} --comparator=${COMPARATOR} -c ${ImageMagick_convert_EXECUTABLE} -s ${TESTSUFFIX} ${CMAKE_BINARY_DIR}/${TESTCMD} "${SCADFILE}") endif() endforeach() endmacro() @@ -525,6 +551,9 @@ enable_testing() # set up custom pretty printing of results set(INFOCMD "execute_process(COMMAND ${CMAKE_CURRENT_BINARY_DIR}/opencsgtest --info OUTPUT_FILE sysinfo.txt)") +if (MINGW_CROSS_ENV_DIR) + set(INFOCMD "execute_process(COMMAND wine ${CMAKE_CURRENT_BINARY_DIR}/opencsgtest --info OUTPUT_FILE sysinfo.txt)") +endif() set(PRETTYCMD "\"${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/test_pretty_print.py --builddir=${CMAKE_CURRENT_BINARY_DIR}\"") set(CTEST_CUSTOM_FILE ${CMAKE_CURRENT_BINARY_DIR}/CTestCustom.cmake) set(CTEST_CUSTOM_TXT "\n diff --git a/tests/CMingw-cross-env.cmake b/tests/CMingw-cross-env.cmake new file mode 100644 index 0000000..09ec1d1 --- /dev/null +++ b/tests/CMingw-cross-env.cmake @@ -0,0 +1,144 @@ +# +# CMake Toolchain file for cross compiling OpenSCAD tests linux->mingw-win32 +# -------------------------------------------------------------------------- +# +# Prerequisites: mingw-cross-env, ImageMagick 6.5.9.3 or newer, wine +# +# Usage: +# +# - follow Brad Pitcher's mingw-cross-env for OpenSCAD setup: +# http://en.wikibooks.org/wiki/OpenSCAD_User_Manual/Cross-compiling_for_Windows_on_Linux_or_Mac_OS_X +# - cross-compile openscad.exe, to verify your installation works properly. +# - cd openscad/tests && mkdir build-mingw32 && cd build-mingw32 +# - cmake .. -DCMAKE_TOOLCHAIN_FILE=CMingw-cross-env.cmake \ +# -DMINGW_CROSS_ENV_DIR=<where mingw-cross-env is installed> +# - make should proceed as normal. +# - now run 'ctest' on your *nix machine. +# The test .exe programs should run under Wine. +# +# See also: +# +# http://lists.gnu.org/archive/html/mingw-cross-env-list/2010-11/threads.html#00078 +# (thread "Qt with Cmake") +# http://lists.gnu.org/archive/html/mingw-cross-env-list/2011-01/threads.html#00012 +# (thread "Qt: pkg-config files?") +# http://mingw-cross-env.nongnu.org/#requirements +# http://www.vtk.org/Wiki/CMake_Cross_Compiling +# https://bitbucket.org/muellni/mingw-cross-env-cmake/src/2067fcf2d52e/src/cmake-1-toolchain-file.patch +# http://code.google.com/p/qtlobby/source/browse/trunk/toolchain-mingw.cmake +# http://gcc.gnu.org/onlinedocs/gcc-3.4.6/gcc/Link-Options.html +# Makefile.Release generated by qmake +# cmake's FindQt4.cmake & Qt4ConfigDependentSettings.cmake files +# mingw-cross-env's qmake.conf and *.prl files +# mingw-cross-env's pkg-config files in usr/i686-pc-mingw32/lib/pkgconfig +# http://www.vtk.org/Wiki/CMake:How_To_Find_Libraries +# + +# +# Notes: +# +# To debug the build process run "make VERBOSE=1". 'strace -f' is also useful. +# +# This file is actually called multiple times by cmake, so various 'if NOT set' +# guards are used to keep programs from running twice. +# +# The test will not currently run under win32 because the ctest harness +# is created by cmake on the machine that it is called on, not on the +# machine it is targeting. +# + +# +# Part 1. Find *nix-ImageMagick +# +# The tests run under Wine under *nix. Therefore we need to find the +# ImageMagick comparison program on the *nix machine. It must be +# searched before the 'cross-compile' environment is setup. +# + +if (NOT imagemagick_cross_set) + find_package(ImageMagick COMPONENTS convert REQUIRED) + message(STATUS "ImageMagick convert executable found: " ${ImageMagick_convert_EXECUTABLE}) + set( SKIP_IMAGEMAGICK TRUE ) + set( imagemagick_cross_set ) +endif() + +# +# Part 2. cross-compiler setup +# + +set(MINGW_CROSS_ENV_DIR $ENV{MINGW_CROSS_ENV_DIR}) + +set(BUILD_SHARED_LIBS OFF) +set(CMAKE_SYSTEM_NAME Windows) +set(MSYS 1) +set(CMAKE_FIND_ROOT_PATH ${MINGW_CROSS_ENV_DIR}/usr/i686-pc-mingw32) +set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) +set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) +set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) + +set(CMAKE_C_COMPILER ${MINGW_CROSS_ENV_DIR}/usr/bin/i686-pc-mingw32-gcc) +set(CMAKE_CXX_COMPILER ${MINGW_CROSS_ENV_DIR}/usr/bin/i686-pc-mingw32-g++) +set(QT_QMAKE_EXECUTABLE ${MINGW_CROSS_ENV_DIR}/usr/bin/i686-pc-mingw32-qmake) +set(PKG_CONFIG_EXECUTABLE ${MINGW_CROSS_ENV_DIR}/usr/bin/i686-pc-mingw32-pkg-config) +set(CMAKE_BUILD_TYPE RelWithDebInfo) + +# +# Part 3. library settings for mingw-cross-env +# + +set( Boost_USE_STATIC_LIBS ON ) +set( Boost_USE_MULTITHREADED ON ) +set( Boost_COMPILER "_win32" ) +# set( Boost_DEBUG TRUE ) # for debugging cmake's FindBoost, not boost itself + +set( OPENSCAD_LIBRARIES ${CMAKE_FIND_ROOT_PATH} ) +set( EIGEN2_DIR ${CMAKE_FIND_ROOT_PATH} ) +set( CGAL_DIR ${CMAKE_FIND_ROOT_PATH}/lib/CGAL ) +set( GLEW_DIR ${CMAKE_FIND_ROOT_PATH} ) + +# +# Qt4 +# +# To workaround problems with CMake's FindQt4.cmake when combined with +# mingw-cross-env (circa early 2012), we here instead use pkg-config. To +# workaround Cmake's insertion of -bdynamic, we stick 'static' on the +# end of QT_LIBRARIES +# + +set(QT_QMAKE_EXECUTABLE ${MINGW_CROSS_ENV_DIR}/usr/bin/i686-pc-mingw32-qmake) +set(QT_MOC_EXECUTABLE ${MINGW_CROSS_ENV_DIR}/usr/bin/i686-pc-mingw32-moc) +set(QT_UIC_EXECUTABLE ${MINGW_CROSS_ENV_DIR}/usr/bin/i686-pc-mingw32-uic) + +function(mingw_cross_env_find_qt) + # called from CMakeLists.txt + find_package( PkgConfig ) + pkg_check_modules( QTCORE QtCore ) + pkg_check_modules( QTGUI QtGui ) + pkg_check_modules( QTOPENGL QtOpenGL ) + + set(QT_INCLUDE_DIRS ${QTCORE_INCLUDE_DIRS} ${QTGUI_INCLUDE_DIRS} ${QTOPENGL_INCLUDE_DIRS}) + set(QT_CFLAGS_OTHER "${QTCORE_CFLAGS_OTHER} ${QTGUI_CFLAGS_OTHER} ${QTOPENGL_CFLAGS_OTHER}") + set(QT_LIBRARIES "${QTCORE_STATIC_LDFLAGS} ${QTGUI_STATIC_LDFLAGS} ${QTOPENGL_STATIC_LDFLAGS};-static") + + set(QT_INCLUDE_DIRS ${QT_INCLUDE_DIRS} PARENT_SCOPE) + set(QT_CFLAGS_OTHER ${QT_CFLAGS_OTHER} PARENT_SCOPE) + set(QT_LIBRARIES ${QT_LIBRARIES} PARENT_SCOPE) +endfunction() + +function(mingw_cross_env_info) + message(STATUS "QT INCLUDE_DIRS: ${QT_INCLUDE_DIRS}") + message(STATUS "QT LIBRARIES: ${QT_LIBRARIES}") + message(STATUS "QT_CFLAGS_OTHER: ${QT_CFLAGS_OTHER}") +endfunction() + +# +# Part 4. -D definitions +# + +if( NOT cross_defs_set ) + add_definitions( -DGLEW_STATIC ) # FindGLEW.cmake needs this + add_definitions( -DBOOST_STATIC ) + add_definitions( -DBOOST_THREAD_USE_LIB ) + add_definitions( -DUNICODE ) # because qmake does it + set(cross_defs_set 1) +endif() diff --git a/tests/FindGLEW.cmake b/tests/FindGLEW.cmake index fa3071f..286fae8 100644 --- a/tests/FindGLEW.cmake +++ b/tests/FindGLEW.cmake @@ -11,13 +11,17 @@ # http://openlibraries.org/browser/trunk/FindGLEW.cmake?rev=1383 -IF (WIN32) +IF (WIN32 AND MSVC) IF (WIN32_STATIC_BUILD) # passed from caller SET(GLEW_LIB_SEARCH_NAME glew32s.lib) # static, non-debug (Release) ELSE () SET(GLEW_LIB_SEARCH_NAME glew32.lib) # other. untested with OpenSCAD ENDIF() +ELSE () # GCC + SET(GLEW_LIB_SEARCH_NAME "libglew32s.a") +ENDIF () +IF (WIN32) FIND_PATH( GLEW_INCLUDE_PATH GL/glew.h $ENV{PROGRAMFILES}/GLEW/include ${PROJECT_SOURCE_DIR}/src/nvgl/glew/include diff --git a/tests/OffscreenContextWGL.cc b/tests/OffscreenContextWGL.cc index f36671c..75a7ed2 100644 --- a/tests/OffscreenContextWGL.cc +++ b/tests/OffscreenContextWGL.cc @@ -105,10 +105,10 @@ bool create_wgl_dummy_context(OffscreenContext &ctx) wc.style = CS_OWNDC; wc.lpfnWndProc = WndProc; wc.hInstance = inst; - wc.lpszClassName = "OpenSCAD"; + wc.lpszClassName = (LPCWSTR)"OpenSCAD"; RegisterClass( &wc ); - HWND window = CreateWindow( "OpenSCAD", "OpenSCAD", + HWND window = CreateWindow( (LPCWSTR)"OpenSCAD", (LPCWSTR)"OpenSCAD", WS_CAPTION | WS_POPUPWINDOW, //| WS_VISIBLE, 0, 0, ctx.width, ctx.height, NULL, NULL, inst, NULL ); diff --git a/tests/dumptest.cc b/tests/dumptest.cc index 22dd96c..f83a993 100644 --- a/tests/dumptest.cc +++ b/tests/dumptest.cc @@ -65,10 +65,9 @@ string dumptree(const Tree &tree, const AbstractNode &node) int main(int argc, char **argv) { -#ifdef WIN32 +#ifdef _MSC_VER _set_output_format(_TWO_DIGIT_EXPONENT); #endif - if (argc != 3) { fprintf(stderr, "Usage: %s <file.scad> <output.txt>\n", argv[0]); exit(1); diff --git a/tests/echotest.cc b/tests/echotest.cc index afa3d03..8f145b0 100644 --- a/tests/echotest.cc +++ b/tests/echotest.cc @@ -59,7 +59,7 @@ static void outfile_handler(const std::string &msg, void *userdata) { int main(int argc, char **argv) { -#ifdef WIN32 +#ifdef _MSC_VER _set_output_format(_TWO_DIGIT_EXPONENT); #endif diff --git a/tests/test_cmdline_tool.py b/tests/test_cmdline_tool.py index 4538984..f29acc0 100755 --- a/tests/test_cmdline_tool.py +++ b/tests/test_cmdline_tool.py @@ -61,7 +61,11 @@ def execute_and_redirect(cmd, params, outfile): else: return retval def get_normalized_text(filename): - text = open(filename).read() + try: + f = open(filename) + text = f.read() + except: + text = '' return text.strip("\r\n").replace("\r\n", "\n") + "\n" def compare_text(expected, actual): @@ -71,8 +75,9 @@ def compare_default(resultfilename): print >> sys.stderr, 'diff text compare: ' print >> sys.stderr, ' expected textfile: ', expectedfilename print >> sys.stderr, ' actual textfile: ', resultfilename - if not compare_text(expectedfilename, resultfilename): - execute_and_redirect("diff", [expectedfilename, resultfilename], sys.stderr) + if not compare_text(expectedfilename, resultfilename): + if resultfilename: + execute_and_redirect("diff", [expectedfilename, resultfilename], sys.stderr) return False return True @@ -136,8 +141,13 @@ def run_test(testname, cmd, args): outputname = os.path.normpath( outputname ) outfile = open(outputname, "wb") + try: - proc = subprocess.Popen([cmd] + args + [outputname], stdout=subprocess.PIPE, stderr=subprocess.PIPE) + if os.path.isfile(cmd+'.exe') and options.mingw_cross_env: + cmdline = ['wine']+[cmd+'.exe'] + args + [outputname] + else: + cmdline = [cmd] + args + [outputname] + proc = subprocess.Popen(cmdline, stdout=subprocess.PIPE, stderr=subprocess.PIPE) errtext = proc.communicate()[1] if errtext != None and len(errtext) > 0: print >> sys.stderr, "Error output: " + errtext @@ -166,11 +176,11 @@ def usage(): print >> sys.stderr, " -s, --suffix=<suffix> Write -expected and -actual files with the given suffix instead of .txt" print >> sys.stderr, " -t, --test=<name> Specify test name instead of deducting it from the argument" print >> sys.stderr, " -c, --convexec=<name> Path to ImageMagick 'convert' executable" - + print >> sys.stderr, " -x, --mingw-cross-env Mingw-cross-env cross compilation" if __name__ == '__main__': # Handle command-line arguments try: - opts, args = getopt.getopt(sys.argv[1:], "gs:c:t:m:", ["generate", "convexec=", "suffix=", "test=", "comparator="]) + opts, args = getopt.getopt(sys.argv[1:], "gs:c:t:m:x", ["generate", "convexec=", "suffix=", "test=", "comparator=", "mingw-cross-env"]) except getopt.GetoptError, err: usage() sys.exit(2) @@ -192,6 +202,8 @@ if __name__ == '__main__': options.convert_exec = os.path.normpath( a ) elif o in ("-m", "--comparator"): options.comparator = a + elif o in ("-x", "--mingw-cross-env"): + options.mingw_cross_env = True # <cmdline-tool> and <argument> if len(args) < 2: |