CMakeLists.txt 3.08 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
33
34
35
36
          # Create unittest executable
          acg_add_executable(unittests ${UNITTEST_SRC})
 
          # 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 )

37
38
39
40
41
42
43
44
   # Set output directory to ${BINARY_DIR}/Unittests
    set (OUTPUT_DIR "${CMAKE_BINARY_DIR}/Unittests")
      set_target_properties(unittests PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${OUTPUT_DIR}) 
      foreach(CONFIG ${CMAKE_CONFIGURATION_TYPES})
        string(TOUPPER ${CONFIG} UPCONFIG)
        set_target_properties(unittests PROPERTIES RUNTIME_OUTPUT_DIRECTORY_${UPCONFIG} ${OUTPUT_DIR})
    endforeach()

Jan Möbius's avatar
Jan Möbius committed
45
	
Mike Kremer's avatar
Mike Kremer committed
46
	if ( NOT WIN32)
47
48
           # Link against all necessary libraries
           target_link_libraries(unittests OpenMeshCore OpenMeshTools ${GTEST_LIBRARIES} ${GTEST_MAIN_LIBRARIES} pthread)
Jan Möbius's avatar
Jan Möbius committed
49
	  
50
	  
Jan Möbius's avatar
Jan Möbius committed
51
	
52
       else()
53
	    # Link against all necessary libraries
Mike Kremer's avatar
Mike Kremer committed
54
55
		if ( OPENMESH_BUILD_SHARED )
			add_definitions( -DOPENMESHDLL )
Mike Kremer's avatar
Mike Kremer committed
56

Mike Kremer's avatar
Mike Kremer committed
57
		endif()
Jan Möbius's avatar
Jan Möbius committed
58
      target_link_libraries(unittests OpenMeshCore OpenMeshTools ${GTEST_LIBRARIES} ${GTEST_MAIN_LIBRARIES}) 
Mike Kremer's avatar
Mike Kremer committed
59
    endif()
Jan Möbius's avatar
Jan Möbius committed
60
61
62
	

    
63
	if ( NOT WIN32 )
64
	    # Set compiler flags
Martin Schultz's avatar
Martin Schultz committed
65
      set_target_properties(unittests PROPERTIES COMPILE_FLAGS "-g -pedantic -Wno-long-long")
66
	else()
67
	    # Set compiler flags
Jan Möbius's avatar
Jan Möbius committed
68
69
      set_target_properties(unittests PROPERTIES COMPILE_FLAGS "" )

70
71
72
    endif()
    
    if ( OPENMESH_BUILD_SHARED )
Mike Kremer's avatar
Mike Kremer committed
73
	
74
75
76
77
78
79
80
81
82
83
84
      #-------- 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")
       endforeach(TAR)
     endif()
Jan Möbius's avatar
Jan Möbius committed
85
	
86
87
    acg_copy_after_build(unittests ${CMAKE_CURRENT_SOURCE_DIR}/TestFiles ${CMAKE_BINARY_DIR}/Unittests/)

88
89
    add_test(NAME AllTestsIn_OpenMesh_tests WORKING_DIRECTORY "${CMAKE_BINARY_DIR}/Unittests" COMMAND "${CMAKE_BINARY_DIR}/Unittests/unittests")

90
  else(GTEST_FOUND)
91
      message(STATUS "Google testing framework was not found, unittests disabled.")
92
93
  endif(GTEST_FOUND)
endif()