From 26e58f7bf00ac9ddd7cff730393299d28030e62b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20M=C3=B6bius?= Date: Mon, 10 Oct 2011 14:34:24 +0000 Subject: [PATCH] Unittests for windows git-svn-id: http://www.openmesh.org/svnrepo/OpenMesh/trunk@427 fdac6126-5c0c-442c-9429-916003d36597 --- Doc/doxy.config.in | 3 ++- cmake/FindGoogleTest.cmake | 26 +++++++++++++++++------- src/Unittests/CMakeLists.txt | 38 ++++++++++++++++++++++++++++++------ 3 files changed, 53 insertions(+), 14 deletions(-) diff --git a/Doc/doxy.config.in b/Doc/doxy.config.in index 29d93264..23cf534e 100644 --- a/Doc/doxy.config.in +++ b/Doc/doxy.config.in @@ -599,7 +599,8 @@ RECURSIVE = YES EXCLUDE = @CMAKE_CURRENT_SOURCE_DIR@/Examples \ @CMAKE_CURRENT_SOURCE_DIR@/../src/OpenMesh/Tools/Test \ - @CMAKE_CURRENT_SOURCE_DIR@/../src/OpenMesh/Apps/Unsupported + @CMAKE_CURRENT_SOURCE_DIR@/../src/OpenMesh/Apps/Unsupported \ + @CMAKE_CURRENT_BINARY_DIR@ # The EXCLUDE_SYMLINKS tag can be used select whether or not files or # directories that are symbolic links (a Unix filesystem feature) are excluded diff --git a/cmake/FindGoogleTest.cmake b/cmake/FindGoogleTest.cmake index cddd992e..46da7757 100644 --- a/cmake/FindGoogleTest.cmake +++ b/cmake/FindGoogleTest.cmake @@ -40,17 +40,20 @@ else(GTEST_INCLUDE_DIRS AND GTEST_LIBRARIES AND GTEST_MAIN_LIBRARIES) PATHS ~/sw/gtest/include /opt/local/include - /usr/local/include) + /usr/local/include + "C:/libs/win32/gtest/include") find_library(_GTEST_LIBRARY gtest PATHS ~/sw/gtest/lib /opt/local/lib - /usr/local/lib) + /usr/local/lib + "C:/libs/win32/gtest/lib") find_library(_GTEST_MAIN_LIBRARY gtest_main PATHS ~/sw/gtest/lib /opt/local/lib - /usr/local/lib) + /usr/local/lib + "C:/libs/win32/gtest/lib") if ( _GTEST_LIBRARY ) get_filename_component(_GTEST_LIBRARY_DIR ${_GTEST_LIBRARY} PATH CACHE ) @@ -61,10 +64,19 @@ else(GTEST_INCLUDE_DIRS AND GTEST_LIBRARIES AND GTEST_MAIN_LIBRARIES) set(GTEST_FOUND true) set(GTEST_INCLUDE_DIRS ${_GTEST_INCLUDE_DIR} CACHE PATH "Include directories for Google Test framework") - set(GTEST_LIBRARIES ${_GTEST_LIBRARY} CACHE FILEPATH - "Libraries to link for Google Test framework") - set(GTEST_MAIN_LIBRARIES ${_GTEST_MAIN_LIBRARY} CACHE FILEPATH - "Libraries to link for Google Test automatic main() definition") + + if ( NOT WIN32 ) + set(GTEST_LIBRARIES ${_GTEST_LIBRARY} CACHE FILEPATH + "Libraries to link for Google Test framework") + set(GTEST_MAIN_LIBRARIES ${_GTEST_MAIN_LIBRARY} CACHE FILEPATH + "Libraries to link for Google Test automatic main() definition") + else() + set(GTEST_LIBRARIES "optimized;gtest;debug;gtestd" CACHE FILEPATH + "Libraries to link for Google Test framework") + set(GTEST_MAIN_LIBRARIES "optimized;gtest_main;debug;gtest_maind" CACHE FILEPATH + "Libraries to link for Google Test automatic main() definition") + endif() + set(GTEST_LIBRARY_DIR ${_GTEST_LIBRARY_DIR} CACHE FILEPATH "Library dir containing Google Test libraries") mark_as_advanced(GTEST_INCLUDE_DIRS GTEST_LIBRARIES GTEST_MAIN_LIBRARIES GTEST_LIBRARY_DIR ) diff --git a/src/Unittests/CMakeLists.txt b/src/Unittests/CMakeLists.txt index 61a87430..30e4112a 100644 --- a/src/Unittests/CMakeLists.txt +++ b/src/Unittests/CMakeLists.txt @@ -16,12 +16,38 @@ if(GTEST_FOUND) link_directories(${GTEST_LIBRARY_DIR} ) # Create new target named unittests_hexmeshing add_executable(unittests EXCLUDE_FROM_ALL unittests.cc) - # Link against all necessary libraries - target_link_libraries(unittests OpenMeshCore OpenMeshTools gtest gtest_main pthread) - # Set output directory to ${BINARY_DIR}/Unittests - set_target_properties(unittests PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/Unittests) - # Set compiler flags - set_target_properties(unittests PROPERTIES COMPILE_FLAGS "-g -pedantic -ansi -Wno-long-long") + + if ( NOT WIN32) + # Link against all necessary libraries + target_link_libraries(unittests OpenMeshCore OpenMeshTools ${GTEST_LIBRARIES} ${GTEST_MAIN_LIBRARIES} pthread) + + # Set output directory to ${BINARY_DIR}/Unittests + set_target_properties(unittests PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/Unittests) + + else() + # Link against all necessary libraries + target_link_libraries(unittests OpenMeshCore OpenMeshTools ${GTEST_LIBRARIES} ${GTEST_MAIN_LIBRARIES}) + endif() + + + + if ( NOT WIN32 ) + # Set compiler flags + set_target_properties(unittests PROPERTIES COMPILE_FLAGS "-g -pedantic -ansi -Wno-long-long") + else() + # Set compiler flags + set_target_properties(unittests PROPERTIES COMPILE_FLAGS "" ) + + # copy exe file to "Build" directory + # Visual studio will create this file in a subdirectory so we can't use + # RUNTIME_OUTPUT_DIRECTORY directly here + add_custom_command (TARGET unittests POST_BUILD + COMMAND ${CMAKE_COMMAND} -E + copy_if_different + ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}/unittests.exe + ${CMAKE_BINARY_DIR}/Unittests/unittests.exe) + endif() + acg_copy_after_build(unittests ${CMAKE_CURRENT_SOURCE_DIR}/TestFiles ${CMAKE_BINARY_DIR}/Unittests/) else(GTEST_FOUND)