CMakeLists.txt 4.58 KB
Newer Older
1 2 3 4 5 6 7
include (ACGCommon)

include_directories (
  ..
  ${CMAKE_CURRENT_SOURCE_DIR}
)

8 9 10
if ( NOT DEFINED OPENMESH_BUILD_UNIT_TESTS)
    set( OPENMESH_BUILD_UNIT_TESTS false CACHE BOOL "Enable or disable unit test builds in OpenMesh." )
endif()
11

12 13 14 15 16
if ( OPENMESH_BUILD_UNIT_TESTS )
  # Search for gtest headers and libraries
  find_package(GoogleTest)

  if(GTEST_FOUND)
17 18

    enable_testing()
19 20 21
   
    # Set correct include paths so that the compiler can find the headers
    include_directories(${GTEST_INCLUDE_DIRS})
Jan Möbius's avatar
Jan Möbius committed
22 23
    # set additional link directories
    link_directories(${GTEST_LIBRARY_DIR} )
24 25 26 27 28

    if ( CMAKE_GENERATOR MATCHES "^Visual Studio 11.*" ) 
      add_definitions( /D _VARIADIC_MAX=10 )
    endif()

29
    # Create new target named unittests_hexmeshing
30
    FILE(GLOB UNITTEST_SRC *.cc)
31 32
          # Create unittest executable
          acg_add_executable(unittests ${UNITTEST_SRC})
33 34
          acg_add_executable(unittests_customvec ${UNITTEST_SRC})
          target_compile_definitions(unittests_customvec PRIVATE TEST_CUSTOM_TRAITS)
35 36
 
          # For the unittest we don't want the install rpath as set by acg_add_executable 
37 38
          set_target_properties ( unittests PROPERTIES  BUILD_WITH_INSTALL_RPATH 0 )          
          set_target_properties ( unittests_customvec PROPERTIES  BUILD_WITH_INSTALL_RPATH 0 )
39

40 41 42
   # Set output directory to ${BINARY_DIR}/Unittests
    set (OUTPUT_DIR "${CMAKE_BINARY_DIR}/Unittests")
      set_target_properties(unittests PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${OUTPUT_DIR}) 
43
      set_target_properties(unittests_customvec PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${OUTPUT_DIR})
44 45 46
      foreach(CONFIG ${CMAKE_CONFIGURATION_TYPES})
        string(TOUPPER ${CONFIG} UPCONFIG)
        set_target_properties(unittests PROPERTIES RUNTIME_OUTPUT_DIRECTORY_${UPCONFIG} ${OUTPUT_DIR})
47
        set_target_properties(unittests_customvec PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${OUTPUT_DIR})
48 49
    endforeach()

Jan Möbius's avatar
Jan Möbius committed
50
	
Mike Kremer's avatar
Mike Kremer committed
51
	if ( NOT WIN32)
52 53
           # Link against all necessary libraries
           target_link_libraries(unittests OpenMeshCore OpenMeshTools ${GTEST_LIBRARIES} ${GTEST_MAIN_LIBRARIES} pthread)
54
           target_link_libraries(unittests_customvec OpenMeshCore OpenMeshTools ${GTEST_LIBRARIES} ${GTEST_MAIN_LIBRARIES} pthread)
Jan Möbius's avatar
Jan Möbius committed
55
	  
56
	  
Jan Möbius's avatar
Jan Möbius committed
57
	
58
       else()
59
	    # Link against all necessary libraries
Mike Kremer's avatar
Mike Kremer committed
60 61
		if ( OPENMESH_BUILD_SHARED )
			add_definitions( -DOPENMESHDLL )
62

Mike Kremer's avatar
Mike Kremer committed
63
		endif()
Jan Möbius's avatar
Jan Möbius committed
64
      target_link_libraries(unittests OpenMeshCore OpenMeshTools ${GTEST_LIBRARIES} ${GTEST_MAIN_LIBRARIES}) 
65
      target_link_libraries(unittests_customvec OpenMeshCore OpenMeshTools ${GTEST_LIBRARIES} ${GTEST_MAIN_LIBRARIES})
Mike Kremer's avatar
Mike Kremer committed
66
    endif()
Jan Möbius's avatar
Jan Möbius committed
67 68 69
	

    
70
	if ( NOT WIN32 )
71
	    # Set compiler flags
Martin Schultz's avatar
Martin Schultz committed
72
      set_target_properties(unittests PROPERTIES COMPILE_FLAGS "-g -pedantic -Wno-long-long")
73
      set_target_properties(unittests_customvec PROPERTIES COMPILE_FLAGS "-g -pedantic -Wno-long-long")
74
	else()
75
	    # Set compiler flags
Jan Möbius's avatar
Jan Möbius committed
76
      set_target_properties(unittests PROPERTIES COMPILE_FLAGS "" )
Christian Mattes's avatar
Christian Mattes committed
77
      set_target_properties(unittests_customvec PROPERTIES COMPILE_FLAGS "" )
78 79 80
    endif()
    
    if ( OPENMESH_BUILD_SHARED )
81
	
82 83 84 85 86 87 88 89 90
      #-------- copy dlls to unittests --------
      SET(OPENMESH_TARGETS "OpenMeshTools" "OpenMeshCore")
    
       foreach(TAR ${OPENMESH_TARGETS} )
         add_custom_command(TARGET unittests POST_BUILD 
                            COMMAND "${CMAKE_COMMAND}" -E copy 
                            "$<TARGET_FILE:${TAR}>"
                            "${CMAKE_BINARY_DIR}/Unittests/$<TARGET_FILE_NAME:${TAR}>" 
                            COMMENT "Copying OpenMesh targets to unittests directory")
91 92 93 94 95
         add_custom_command(TARGET unittests_customvec POST_BUILD
                            COMMAND "${CMAKE_COMMAND}" -E copy
                            "$<TARGET_FILE:${TAR}>"
                            "${CMAKE_BINARY_DIR}/Unittests/$<TARGET_FILE_NAME:${TAR}>"
                            COMMENT "Copying OpenMesh targets to unittests directory")
96 97
       endforeach(TAR)
     endif()
Jan Möbius's avatar
Jan Möbius committed
98
	
99
    acg_copy_after_build(unittests ${CMAKE_CURRENT_SOURCE_DIR}/TestFiles ${CMAKE_BINARY_DIR}/Unittests/)
100
    acg_copy_after_build(unittests_customvec ${CMAKE_CURRENT_SOURCE_DIR}/TestFiles ${CMAKE_BINARY_DIR}/Unittests/)
101

102
    add_test(NAME AllTestsIn_OpenMesh_tests WORKING_DIRECTORY "${CMAKE_BINARY_DIR}/Unittests" COMMAND "${CMAKE_BINARY_DIR}/Unittests/unittests")
103
    add_test(NAME AllTestsIn_OpenMesh_tests_with_minimal_vector WORKING_DIRECTORY "${CMAKE_BINARY_DIR}/Unittests" COMMAND "${CMAKE_BINARY_DIR}/Unittests/unittests_customvec")
104

105
  else(GTEST_FOUND)
106
      message(STATUS "Google testing framework was not found, unittests disabled.")
107 108
  endif(GTEST_FOUND)
endif()