CMakeLists.txt 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276
  1. #cmake_minimum_required(VERSION 2.8.6) #version 2.8.6 at least required because of command set(CMAKE_AUTOMOC TRUE) for qt moc-ing (see below)
  2. cmake_minimum_required(VERSION 2.8.6)
  3. project (NICELibrary)
  4. include(CheckSymbolExists)
  5. include(CheckIncludeFiles)
  6. set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/")
  7. include(cmake/NiceModules.cmake REQUIRED)
  8. # The version number.
  9. set(NICELibrary_VERSION_MAJOR 1)
  10. set(NICELibrary_VERSION_MINOR 2)
  11. set(NICE_VERSION ${NICELibrary_VERSION_MAJOR}.${NICELibrary_VERSION_MINOR})
  12. NICE_OPTION(NICE_BUILD_DEBUG "NICE Debug Build for debugging" OFF )
  13. if(NICE_BUILD_DEBUG)
  14. message(STATUS "NICE debug build enabled")
  15. set (CMAKE_BUILD_TYPE Debug)
  16. else()
  17. set (CMAKE_BUILD_TYPE Release)
  18. endif()
  19. NICE_OPTION(CMAKE_VERBOSE "Verbose mode" OFF )
  20. if(CMAKE_VERBOSE)
  21. set(CMAKE_VERBOSE_MAKEFILE 1)
  22. endif()
  23. set(CMAKE_INSTALL_PREFIX ${PROJECT_BINARY_DIR})
  24. set(NICE_SOURCEFILES_FIND_GLOBALLYRECURSIVE ON CACHE STRING "Scan a sublibraries directory for source files instead of using an explicit src file list")
  25. NICE_OPTION(WITH_MEX "Build with MEX support" ON)
  26. if(WITH_MEX)
  27. INCLUDE_DIRECTORIES($ENV{MATLAB}/extern/include)
  28. FIND_LIBRARY(MEX_LIBMX mx PATHS $ENV{MATLAB}/bin/$ENV{Arch})
  29. FIND_LIBRARY(MEX_LIBMEX mex PATHS $ENV{MATLAB}/bin/$ENV{Arch})
  30. FIND_LIBRARY(MEX_LIBMAT mat PATHS $ENV{MATLAB}/bin/$ENV{Arch})
  31. SET(MEX_LIBRARIES ${MEX_LIBMX} ${MEX_LIBMEX} ${MEX_LIBMAT})
  32. MESSAGE(STATUS "Found mex libraries at ${MEX_LIBRARIES}")
  33. endif()
  34. NICE_OPTION(WITH_BOOST "Build with Boost support" OFF)
  35. if(WITH_BOOST)
  36. set(Boost_USE_STATIC_LIBS ON)
  37. FIND_PACKAGE(Boost COMPONENTS date_time filesystem)
  38. IF (Boost_FOUND)
  39. message(STATUS "boost-incl-dir: ${Boost_INCLUDE_DIRS}")
  40. INCLUDE_DIRECTORIES(${Boost_INCLUDE_DIRS})
  41. ADD_DEFINITIONS( "-DNICE_BOOST_FOUND" )
  42. ADD_DEFINITIONS( "-DNICE_USELIB_BOOST" )
  43. ENDIF()
  44. endif()
  45. FIND_PACKAGE(CppUnit)
  46. IF (CPPUNIT_FOUND)
  47. message(STATUS "CppUnit-dir: ${CPPUNIT_INCLUDE_DIR}")
  48. INCLUDE_DIRECTORIES(${CPPUNIT_INCLUDE_DIR})
  49. ADD_DEFINITIONS( "-DNICE_USELIB_CPPUNIT" )
  50. ADD_DEFINITIONS( "-DCPPUNIT_USE_TYPEINFO_NAME") #converting test class name into test name
  51. else()
  52. #set(CPPUNIT_INCLUDE_DIR "/usr/include/") #can be found in /usr/include/cppunit
  53. # ADD_DEFINITIONS( "-DNICE_USELIB_CPPUNIT" )
  54. message(STATUS "CppUnit not found")
  55. ENDIF()
  56. NICE_OPTION(WITH_DBV_LIBRARIES "Build with DBV extern librares" OFF)
  57. if(WITH_DBV_LIBRARIES)
  58. set(NICE_DBV_LIBRARIES_DIR "/home/dbv/3rdparty64-gcc43/")
  59. if(EXISTS "${NICE_DBV_LIBRARIES_DIR}")
  60. message(STATUS "using DBV extern librares in ${NICE_DBV_LIBRARIES_DIR}")
  61. NICE_OPTION(WITH_IPP "Build with Intel IPP support" ON)
  62. if(WITH_IPP)
  63. set(ENV{IPPROOT} "${NICE_DBV_LIBRARIES_DIR}ipp53/")
  64. include("cmake/NiceFindIPP.cmake")
  65. if(IPP_FOUND)
  66. #message(STATUS "ipp link dir: ${IPP_LIBRARY_DIRS}")
  67. #message(STATUS "ipp link libs: ${IPP_LIBRARIES}")
  68. ADD_DEFINITIONS( "-DNICE_USELIB_IPP=5" )
  69. ADD_DEFINITIONS( "-lpthread" )
  70. INCLUDE_DIRECTORIES(${IPP_INCLUDE_DIRS})
  71. else()
  72. message(STATUS "IPP library not found")
  73. endif()
  74. endif()
  75. NICE_OPTION(WITH_LINAL "Build with dbv LinAl support" OFF)
  76. if(WITH_LINAL)
  77. FIND_PACKAGE(LinAl)
  78. if(LINAL_FOUND)
  79. ADD_DEFINITIONS( "-DNICE_USELIB_LINAL" )
  80. #ADD_DEFINITIONS("-lgfortran")
  81. INCLUDE_DIRECTORIES(${LINAL_INCLUDE_DIR})
  82. #message(STATUS "linal link libs: ${LINAL_LIBRARIES}")
  83. message(STATUS "Using LinAl include dir: ${LINAL_INCLUDE_DIR}")
  84. endif()
  85. endif()
  86. else()
  87. message( SEND_ERROR "trying to use DBV extern library dir, but couldn't be found ${NICE_DBV_LIBRARIES_DIR}. Switch off DBV Usage to continue.") #unsetting dbv libraries path
  88. unset(WITH_DBV_LIBRARIES) #unsetting, since dbv dir not found
  89. endif()
  90. endif()
  91. NICE_OPTION(WITH_OPENMP "Build with OpenMP support" ON)
  92. if(WITH_OPENMP)
  93. find_package(OpenMP)
  94. if (OPENMP_FOUND)
  95. set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}")
  96. set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
  97. ADD_DEFINITIONS( "-DNICE_USELIB_OPENMP")
  98. endif()
  99. endif()
  100. NICE_OPTION(WITH_PNG "Build with libPNG support" OFF)
  101. if(WITH_PNG)
  102. find_package(PNG)
  103. if (PNG_FOUND)
  104. INCLUDE_DIRECTORIES(${PNG_INCLUDE_DIRS})
  105. ADD_DEFINITIONS( "-DNICE_USELIB_PNG")
  106. endif()
  107. endif()
  108. NICE_OPTION(WITH_MATIO "Build with Matio and HDF5 support" OFF)
  109. if(WITH_MATIO)
  110. find_package(HDF5)
  111. if(HDF5_FOUND)
  112. message(STATUS "HDF5-dir: ${HDF5_INCLUDE_DIR}")
  113. endif()
  114. find_package(MATIO)
  115. if(MATIO_FOUND)
  116. message(STATUS "Matio-dir: ${MATIO_INCLUDE_DIRS}")
  117. ADD_DEFINITIONS( "-DNICE_USELIB_MATIO")
  118. INCLUDE_DIRECTORIES(${MATIO_INCLUDE_DIRS})
  119. endif()
  120. endif()
  121. NICE_OPTION(WITH_IMAGEMAGICK "Build with ImageMagick++" OFF)
  122. if(WITH_IMAGEMAGICK)
  123. find_package(ImageMagick COMPONENTS Magick++ MagickCore)
  124. if(ImageMagick_FOUND)
  125. message(STATUS "imagemagick found: ${ImageMagick_LIBRARIES}")
  126. ADD_DEFINITIONS( "-DNICE_USELIB_LIBMAGICK")
  127. INCLUDE_DIRECTORIES(${ImageMagick_INCLUDE_DIRS})
  128. else()
  129. message(STATUS "imagemagick not found")
  130. endif()
  131. endif()
  132. NICE_OPTION(WITH_QT "Build with Qt" ON)
  133. if(WITH_QT)
  134. FIND_PACKAGE(Qt4 REQUIRED)# COMPONENTS QtOpenGl)
  135. SET(QT_USE_QTOPENGL TRUE)
  136. SET(QT_USE_QTXML TRUE)
  137. if(QT_FOUND)
  138. set(CMAKE_AUTOMOC TRUE) #see doc: http://blogs.kde.org/2011/11/01/cool-new-stuff-cmake-286-automoc
  139. INCLUDE(${QT_USE_FILE})
  140. ADD_DEFINITIONS(${QT_DEFINITIONS})
  141. ADD_DEFINITIONS( "-DNICE_USELIB_QT")
  142. endif()
  143. endif()
  144. NICE_OPTION(WITH_OPENGL "Build with OpenGL" ON)
  145. if(WITH_OPENGL)
  146. find_package(OpenGL)
  147. if(OPENGL_FOUND)
  148. message(STATUS "OPENGL found")
  149. include_directories( ${OPENGL_INCLUDE_DIRS} )
  150. ADD_DEFINITIONS( "-DNICE_USELIB_OPENGL")
  151. endif()
  152. #try using GLUT
  153. if(WIN32)
  154. message(STATUS "find GLUT for win32")
  155. set(GLUT_INCLUDE_DIR "C:/Libraries/freeglut-MSVC-2.8.0-1.mp/freeglut/include/")# , where to find GL/glut.h, etc.
  156. set(GLUT_ROOT_PATH "C:/Libraries/freeglut-MSVC-2.8.0-1.mp/freeglut/") # GLUT_LIBRARIES
  157. set(tmp_OPENGL_LIBRARY_DIR "${OPENGL_LIBRARY_DIR}") #temporarily store opengl_lib path
  158. set(OPENGL_LIBRARY_DIR "${GLUT_ROOT_PATH}lib")
  159. find_package(GLUT)
  160. if(GLUT_FOUND)
  161. message(STATUS "GLUT found")
  162. include_directories( ${GLUT_INCLUDE_DIR} )
  163. ADD_DEFINITIONS( -DNICE_USELIB_GLUT)
  164. #ADD_DEFINITIONS(-DBUILD_VTI -DFREEGLUT_STATIC) with static seems not to work
  165. endif()
  166. set(OPENGL_LIBRARY_DIR "${tmp_OPENGL_LIBRARY_DIR}") #reset opengl lib path
  167. else()
  168. find_package(GLUT)
  169. if(GLUT_FOUND)
  170. message(STATUS "GLUT found")
  171. include_directories( ${GLUT_INCLUDE_DIR} )
  172. ADD_DEFINITIONS(-DNICE_USELIB_GLUT)
  173. endif()
  174. endif()
  175. endif()
  176. if(NOT WIN32)
  177. #check for available regex stuff
  178. CHECK_INCLUDE_FILES(regex.h HAVE_REGEX_H)
  179. if(HAVE_REGEX_H)
  180. ADD_DEFINITIONS(-DNICE_USELIB_REGEX) #regular expressions are available per default under linux
  181. message(STATUS "Regex found")
  182. endif()
  183. endif()
  184. if(MSVC)
  185. #enable solution folders
  186. SET_PROPERTY(GLOBAL PROPERTY USE_FOLDERS ON)
  187. SET_PROPERTY(GLOBAL PROPERTY AUTOMOC_FOLDER automoc) #in future (>cmake1.8.11 this might separate the automoc projects into a separate solution folder)
  188. #in Visual Studio avoid overwriting of std::max with macro definition max() in WinDef.h (http://support.microsoft.com/kb/143208/de)
  189. ADD_DEFINITIONS("-DNOMINMAX")
  190. endif()
  191. NICE_OPTION(BUILD_UNITTESTS "Build all unit tests" ON IF CPPUNIT_FOUND)
  192. #if(CPPUNIT_FOUND)
  193. # set(BUILD_UNITTESTS ON)
  194. #else()
  195. # set(BUILD_UNITTESTS OFF)
  196. #endif()
  197. if( BUILD_UNITTESTS)
  198. enable_testing()
  199. include(CTest)
  200. endif()
  201. NICE_OPTION(BUILD_PROGRAMS "Build all programs" ON)
  202. set(OPENCV_LIB_INSTALL_PATH lib)
  203. INCLUDE_DIRECTORIES(".")
  204. INCLUDE_DIRECTORIES(core)
  205. set(the_module "nice")
  206. set(NICE_CURR_DIR "${CMAKE_CURRENT_SOURCE_DIR}")
  207. SUBDIRLIST(__listSubDirs "${NICE_CURR_DIR}")
  208. set(__listSubLibs "")
  209. foreach(_curSubdir ${__listSubDirs})
  210. nice_get_real_path(__modpath "${NICE_CURR_DIR}/${_curSubdir}/")
  211. if(EXISTS "${__modpath}/CMakeLists.txt")
  212. #ADD_SUBDIRECTORY(${__modpath})
  213. LIST(APPEND __listSubLibs ${_curSubdir})
  214. NICE_OPTION(BUILD_LIB_${_curSubdir} "Build library ${_curSubdir}" ON)
  215. endif()
  216. endforeach()
  217. foreach(_curSublib ${__listSubLibs})
  218. if(BUILD_LIB_${_curSublib})
  219. nice_get_real_path(__modpath "${NICE_CURR_DIR}/${_curSublib}/")
  220. ADD_SUBDIRECTORY(${__modpath})
  221. endif()
  222. endforeach()
  223. # doxygen support
  224. #FIND_PROGRAM(DOXYGEN_EXECUTABLE "doxygen")
  225. ##############################################################################################
  226. configure_file(cmake/templates/NICELibraryConfigVersion.cmake.in "${PROJECT_BINARY_DIR}/NICELibraryConfigVersion.cmake" @ONLY)
  227. ##############################################################################################
  228. include (InstallRequiredSystemLibraries) # This module will include any runtime libraries that are needed by the project for the current platform
  229. SET(CPACK_GENERATOR "RPM")
  230. SET(CPACK_DEBIAN_PACKAGE_MAINTAINER "Johannes R.") #required
  231. SET(CPACK_PACKAGE_NAME "NICE New Image Library")
  232. SET(CPACK_PACKAGE_VENDOR "Computer Vision Group Jena, University of Jena")
  233. INCLUDE(CPack)