CMakeLists.txt 4.71 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
if ( OPENMESH_BUILD_UNIT_TESTS )
  # Search for gtest headers and libraries
14
  find_package(GTest)
15 16

  if(GTEST_FOUND)
17 18

    enable_testing()
19
   
20 21
    find_package(EIGEN3)

22
    # Set correct include paths so that the compiler can find the headers
Jan Möbius's avatar
Jan Möbius committed
23 24 25
    include_directories(${GTEST_INCLUDE_DIRS} )


Jan Möbius's avatar
Jan Möbius committed
26 27
    # set additional link directories
    link_directories(${GTEST_LIBRARY_DIR} )
28

29 30
    
    if (EIGEN3_FOUND)
Jan Möbius's avatar
Jan Möbius committed
31 32
      add_definitions( -DENABLE_EIGEN3_TEST ) 
      include_directories(${EIGEN3_INCLUDE_DIR})
33 34
    endif()

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

39
    # Create new target named unittests_hexmeshing
40
    FILE(GLOB UNITTEST_SRC *.cc)
41 42 43 44
    # Create unittest executable
    acg_add_executable(unittests ${UNITTEST_SRC})
    acg_add_executable(unittests_customvec ${UNITTEST_SRC})
    target_compile_definitions(unittests_customvec PRIVATE TEST_CUSTOM_TRAITS)
45
 
46 47 48
    # For the unittest we don't want the install rpath as set by acg_add_executable 
    set_target_properties ( unittests PROPERTIES  BUILD_WITH_INSTALL_RPATH 0 )          
    set_target_properties ( unittests_customvec PROPERTIES  BUILD_WITH_INSTALL_RPATH 0 )
49

50 51 52
   # Set output directory to ${BINARY_DIR}/Unittests
    set (OUTPUT_DIR "${CMAKE_BINARY_DIR}/Unittests")
      set_target_properties(unittests PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${OUTPUT_DIR}) 
53
      set_target_properties(unittests_customvec PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${OUTPUT_DIR})
54 55 56
      foreach(CONFIG ${CMAKE_CONFIGURATION_TYPES})
        string(TOUPPER ${CONFIG} UPCONFIG)
        set_target_properties(unittests PROPERTIES RUNTIME_OUTPUT_DIRECTORY_${UPCONFIG} ${OUTPUT_DIR})
57
        set_target_properties(unittests_customvec PROPERTIES RUNTIME_OUTPUT_DIRECTORY_${UPCONFIG} ${OUTPUT_DIR})
58 59
    endforeach()

Jan Möbius's avatar
Jan Möbius committed
60
	
Mike Kremer's avatar
Mike Kremer committed
61
	if ( NOT WIN32)
62 63
           # Link against all necessary libraries
           target_link_libraries(unittests OpenMeshCore OpenMeshTools ${GTEST_LIBRARIES} ${GTEST_MAIN_LIBRARIES} pthread)
64
           target_link_libraries(unittests_customvec OpenMeshCore OpenMeshTools ${GTEST_LIBRARIES} ${GTEST_MAIN_LIBRARIES} pthread)
Jan Möbius's avatar
Jan Möbius committed
65
	  
66
	  
Jan Möbius's avatar
Jan Möbius committed
67
	
68
       else()
69
	    # Link against all necessary libraries
Mike Kremer's avatar
Mike Kremer committed
70 71
		if ( OPENMESH_BUILD_SHARED )
			add_definitions( -DOPENMESHDLL )
72

Mike Kremer's avatar
Mike Kremer committed
73
		endif()
Jan Möbius's avatar
Jan Möbius committed
74
      target_link_libraries(unittests OpenMeshCore OpenMeshTools ${GTEST_LIBRARIES} ${GTEST_MAIN_LIBRARIES}) 
75
      target_link_libraries(unittests_customvec OpenMeshCore OpenMeshTools ${GTEST_LIBRARIES} ${GTEST_MAIN_LIBRARIES})
Mike Kremer's avatar
Mike Kremer committed
76
    endif()
Jan Möbius's avatar
Jan Möbius committed
77 78 79
	

    
80
	if ( NOT WIN32 )
81
	    # Set compiler flags
Martin Schultz's avatar
Martin Schultz committed
82
      set_target_properties(unittests PROPERTIES COMPILE_FLAGS "-g -pedantic -Wno-long-long")
83
      set_target_properties(unittests_customvec PROPERTIES COMPILE_FLAGS "-g -pedantic -Wno-long-long")
84
	else()
85
	    # Set compiler flags
Jan Möbius's avatar
Jan Möbius committed
86
      set_target_properties(unittests PROPERTIES COMPILE_FLAGS "" )
Christian Mattes's avatar
Christian Mattes committed
87
      set_target_properties(unittests_customvec PROPERTIES COMPILE_FLAGS "" )
88 89 90
    endif()
    
    if ( OPENMESH_BUILD_SHARED )
91
	
92 93 94 95 96 97 98 99 100
      #-------- 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")
101 102 103 104 105
         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")
106 107
       endforeach(TAR)
     endif()
Jan Möbius's avatar
Jan Möbius committed
108
	
109
    acg_copy_after_build(unittests ${CMAKE_CURRENT_SOURCE_DIR}/TestFiles ${CMAKE_BINARY_DIR}/Unittests/)
110
    acg_copy_after_build(unittests_customvec ${CMAKE_CURRENT_SOURCE_DIR}/TestFiles ${CMAKE_BINARY_DIR}/Unittests/)
111

112
    add_test(NAME AllTestsIn_OpenMesh_tests WORKING_DIRECTORY "${CMAKE_BINARY_DIR}/Unittests" COMMAND "${CMAKE_BINARY_DIR}/Unittests/unittests")
113
    add_test(NAME AllTestsIn_OpenMesh_tests_with_minimal_vector WORKING_DIRECTORY "${CMAKE_BINARY_DIR}/Unittests" COMMAND "${CMAKE_BINARY_DIR}/Unittests/unittests_customvec")
114

115
  else(GTEST_FOUND)
116
      message(STATUS "Google testing framework was not found, unittests disabled.")
117 118
  endif(GTEST_FOUND)
endif()