CMakeLists.txt 2.97 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
    # Create new target named unittests_hexmeshing
25
    add_executable(unittests unittests.cc)
Jan Möbius's avatar
Jan Möbius committed
26
	
Mike Kremer's avatar
Mike Kremer committed
27
	if ( NOT WIN32)
Jan Möbius's avatar
Jan Möbius committed
28 29 30
      # Link against all necessary libraries
      target_link_libraries(unittests OpenMeshCore OpenMeshTools ${GTEST_LIBRARIES} ${GTEST_MAIN_LIBRARIES} pthread)
	  
31
	    # Set output directory to ${BINARY_DIR}/Unittests
Jan Möbius's avatar
Jan Möbius committed
32 33 34
      set_target_properties(unittests PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/Unittests)
	
    else()
35
	    # Link against all necessary libraries
Mike Kremer's avatar
Mike Kremer committed
36 37 38
		if ( OPENMESH_BUILD_SHARED )
			#!!!! Experimental Feature!!!
			add_definitions( -DOPENMESHDLL )
39

Mike Kremer's avatar
Mike Kremer committed
40
		endif()
Jan Möbius's avatar
Jan Möbius committed
41
      target_link_libraries(unittests OpenMeshCore OpenMeshTools ${GTEST_LIBRARIES} ${GTEST_MAIN_LIBRARIES}) 
Mike Kremer's avatar
Mike Kremer committed
42
    endif()
Jan Möbius's avatar
Jan Möbius committed
43 44 45
	

    
46
	if ( NOT WIN32 )
47
	    # Set compiler flags
Jan Möbius's avatar
Jan Möbius committed
48
      set_target_properties(unittests PROPERTIES COMPILE_FLAGS "-g -pedantic -ansi -Wno-long-long")
49
	else()
50
	    # Set compiler flags
Jan Möbius's avatar
Jan Möbius committed
51 52
      set_target_properties(unittests PROPERTIES COMPILE_FLAGS "" )

53
	  #-------- copy exe file to "Build" directory --------
Jan Möbius's avatar
Jan Möbius committed
54 55 56 57 58 59 60
      # 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)
61 62 63 64

    endif()
    
    if ( OPENMESH_BUILD_SHARED )
65
	
66 67 68 69 70 71 72 73 74 75 76
      #-------- 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
77
	
78 79
    acg_copy_after_build(unittests ${CMAKE_CURRENT_SOURCE_DIR}/TestFiles ${CMAKE_BINARY_DIR}/Unittests/)

80 81
    add_test(NAME AllTestsIn_OpenMesh_tests WORKING_DIRECTORY "${CMAKE_BINARY_DIR}/Unittests" COMMAND "${CMAKE_BINARY_DIR}/Unittests/unittests")

82 83 84 85
  else(GTEST_FOUND)
      message("Google testing framework was not found!")
  endif(GTEST_FOUND)
endif()