CMakeLists.txt 5.25 KB
Newer Older
Jan Möbius's avatar
Jan Möbius committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101
include (ACGCommon)

acg_get_version ()

# Disable Library installation when not building ACG on its own but as part of another project!
if ( ${PROJECT_NAME} MATCHES "OpenFlipper")
  set(ACG_NO_LIBRARY_INSTALL true)
endif()


acg_qt5 ()  

if (NOT QT5_FOUND)
  message(FATAL ERROR "Qt5 not found")
endif ()

acg_openmp ()

# check for OpenGL, GLEW and GLUT as our required dependencies
find_package (OpenGL)
if (NOT OPENGL_FOUND)
  message (FATAL_ERROR "OpengGL not found!")
endif ()

find_package (GLEW)
if (NOT GLEW_FOUND)
  message (FATAL_ERROR "GLEW not found!")
endif ()

find_package (GLUT)
if (NOT GLUT_FOUND)
  message (FATAL_ERROR "GLUT not found!")
endif ()

find_package (OpenMesh)
if (NOT OPENMESH_FOUND)
    message (FATAL_ERROR "OpenMesh not found!")
endif ()

set(INCLUDE_DIRS ${OPENMESH_INCLUDE_DIRS}
                 ${CMAKE_CURRENT_SOURCE_DIR}
                 ${CMAKE_CURRENT_SOURCE_DIR}/ShaderUtils
                 ${CMAKE_CURRENT_BINARY_DIR}
                 ${OPENGL_INCLUDE_DIR}
                 ${GLEW_INCLUDE_DIR}
                 ${GLUT_INCLUDE_DIR} )

set(ADDITIONAL_LINK_LIBRARIES "" )
set(ADDITIONAL_BUILD_DIRS "" )

find_package (QJson)
if (QJSON_FOUND)
    LIST(APPEND INCLUDE_DIRS ${QJSON_INCLUDE_DIR})
    LIST(APPEND ADDITIONAL_LINK_LIBRARIES ${QJSON_LIBRARY})
endif ()

# use Qwt6 for QT5
if (QT5_FOUND)
  find_package(Qwt6)

  if (QWT6_FOUND)
    set(INCLUDE_DIRS ${INCLUDE_DIRS} ${QWT6_INCLUDE_DIRS} )
    set(ADDITIONAL_LINK_LIBRARIES ${ADDITIONAL_LINK_LIBRARIES} ${QWT6_LIBRARIES})
    set(ADDITIONAL_BUILD_DIRS "QwtWidgets" )
  endif()

endif()

include_directories (
  ..
  ${INCLUDE_DIRS}
)

link_directories (
  ${GLEW_LIBRARY_DIR}
)

#===================================================================
# ACG Library setup
#===================================================================

# source code directories
set (directories
  .
  Geometry
  Config
  Geometry/Types
  Geometry/bsp
  GL
  IO
  Math
  QtWidgets
  Scenegraph
  QtScenegraph
  ShaderUtils
  Utils
  ${ADDITIONAL_BUILD_DIRS}
)

# generate dllexport macros on windows
if (WIN32)
102
  add_definitions(-DACGDLL -DFREEGLUT_LIB_PRAGMAS=0)
103
  remove_definitions(-DUSEACG)
Jan Möbius's avatar
Jan Möbius committed
104 105 106
endif ()

# collect all header,source and ui files
Jan Möbius's avatar
Jan Möbius committed
107 108 109 110 111 112
acg_append_files (headers  "*.hh" ${directories})
acg_append_files (sources  "*.cc" ${directories})
acg_append_files (ui-files "*.ui" ${directories})
acg_append_files (qrc      "*.qrc" ${directories} .)

source_group(TREE ${CMAKE_SOURCE_DIR} FILES ${sources} ${headers} ${ui-files} ${qrc}) 
Jan Möbius's avatar
Jan Möbius committed
113 114 115 116 117

# remove template cc files from source file list
acg_drop_templates (sources)

if (QT5_FOUND)
118
  acg_add_library (ACG SHARED ${sources} ${headers} ${qrc})
Jan Möbius's avatar
Jan Möbius committed
119 120 121 122 123 124 125 126 127 128 129 130 131 132
endif()

if ( NOT WIN32 )
  set_target_properties (ACG PROPERTIES VERSION ${ACG_VERSION_MAJOR}.${ACG_VERSION_MINOR}
                                      SOVERSION ${ACG_VERSION_MAJOR}.${ACG_VERSION_MINOR})
endif()

if (NOT ACG_PROJECT_MACOS_BUNDLE OR NOT APPLE)
  install (TARGETS ACG DESTINATION ${ACG_PROJECT_LIBDIR})
endif ()

# display results
acg_print_configure_header (ACG "ACG")

133 134 135 136 137 138 139 140 141 142
if ( NOT WIN32 )
  # Allow targets depending on ACG find the autogenerated header files
  target_include_directories( ACG PUBLIC
                               ${CMAKE_CURRENT_BINARY_DIR}/ACG_autogen/include )
else()
   # Allow targets depending on ACG find the autogenerated header files
  target_include_directories( ACG PUBLIC
                               $<$<CONFIG:Debug>:${CMAKE_CURRENT_BINARY_DIR}/ACG_autogen/include_Debug/>
                               $<$<CONFIG:Release>:${CMAKE_CURRENT_BINARY_DIR}/ACG_autogen/include_Release/> )
endif()
143

Jan Möbius's avatar
Jan Möbius committed
144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200
target_link_libraries ( ACG  ${OPENMESH_LIBRARIES}
                             ${QT_LIBRARIES}
                             ${OPENGL_LIBRARIES}
                             ${GLEW_LIBRARY}
                             ${GLUT_LIBRARIES}
                             ${ADDITIONAL_LINK_LIBRARIES} )

#===================================================================
# Setting up the unit tests
#===================================================================
find_package(GoogleTest)
if (GTEST_FOUND)


  if ( NOT DEFINED ACG_BUILD_UNIT_TESTS )
    set( ACG_BUILD_UNIT_TESTS false CACHE BOOL "Enable or disable unit tests on ACG library." )
  endif()

  if ( ACG_BUILD_UNIT_TESTS )

    enable_testing()

    file(GLOB_RECURSE TEST_SOURCES tests/*.cc)
    set(TESTED_SOURCES
          Algorithm/DBSCANT.cc
       )
    include_directories(${GTEST_INCLUDE_DIRS} ${OPENMESH_INCLUDE_DIR})
    link_directories ( ${GTEST_LIBRARY_DIR})

    if ( CMAKE_GENERATOR MATCHES "^Visual Studio 11.*" )
       add_definitions( /D _VARIADIC_MAX=10 )
    endif()
 
    add_executable (ACG_tests ${TEST_SOURCES})

    set(OUT_DIR ${CMAKE_CURRENT_BINARY_DIR})
    # run tests in build directory of OF
    if ( ${PROJECT_NAME} MATCHES "OpenFlipper" AND WIN32)
      set(OUT_DIR  ${CMAKE_BINARY_DIR}/Build)
    endif()

    set_target_properties(ACG_tests PROPERTIES
      COMPILE_FLAGS "-UNDEBUG"
      RUNTIME_OUTPUT_DIRECTORY ${OUT_DIR}
      RUNTIME_OUTPUT_DIRECTORY_RELEASE ${OUT_DIR}
      RUNTIME_OUTPUT_DIRECTORY_DEBUG ${OUT_DIR}
    )
  
    target_link_libraries(ACG_tests
          ${GTEST_LIBRARIES} ${OPENMESH_LIBRARIES} ACG
    )
  
    add_test(NAME AllTestsIn_ACG_tests COMMAND ${OUT_DIR}/ACG_tests)

  endif( ACG_BUILD_UNIT_TESTS )

endif(GTEST_FOUND)