CMakeLists.txt 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  1. CMAKE_MINIMUM_REQUIRED(VERSION 2.8)
  2. FOREACH(policy CMP0003)
  3. IF(POLICY ${policy})
  4. CMAKE_POLICY(SET ${policy} NEW)
  5. ENDIF()
  6. ENDFOREACH()
  7. PROJECT(CTK)
  8. # Default to shared library
  9. SET(CTK_LIBRARY_MODE "SHARED")
  10. SET(CTK_BUILD_SHARED_LIBS TRUE)
  11. #-----------------------------------------------------------------------------
  12. # Output directories.
  13. #
  14. IF(NOT LIBRARY_OUTPUT_PATH)
  15. SET(LIBRARY_OUTPUT_PATH ${CTK_BINARY_DIR}/bin CACHE INTERNAL "Single output directory for building all libraries.")
  16. ENDIF(NOT LIBRARY_OUTPUT_PATH)
  17. IF(NOT EXECUTABLE_OUTPUT_PATH)
  18. SET(EXECUTABLE_OUTPUT_PATH ${CTK_BINARY_DIR}/bin CACHE INTERNAL "Single output directory for building all executables.")
  19. ENDIF(NOT EXECUTABLE_OUTPUT_PATH)
  20. SET(CTK_LIBRARY_PATH ${LIBRARY_OUTPUT_PATH}/${CMAKE_CFG_INTDIR})
  21. SET(CTK_EXECUTABLE_PATH ${EXECUTABLE_OUTPUT_PATH}/${CMAKE_CFG_INTDIR})
  22. #-----------------------------------------------------------------------------
  23. # Install directories, used for install rules.
  24. #
  25. SET(CTK_INSTALL_BIN_DIR "bin")
  26. SET(CTK_INSTALL_LIB_DIR "lib")
  27. SET(CTK_INSTALL_INCLUDE_DIR "include")
  28. SET(CTK_INSTALL_DOC_DIR "doc")
  29. #-----------------------------------------------------------------------------
  30. # Update CMake module path
  31. # Note: FindXXX.cmake script specific to utility should be copied into Utilities/CMake
  32. #
  33. SET(CMAKE_MODULE_PATH
  34. "${CMAKE_CURRENT_SOURCE_DIR}/Utilities/CMake"
  35. "${CMAKE_CURRENT_SOURCE_DIR}/CMake"
  36. ${CMAKE_MODULE_PATH})
  37. #-----------------------------------------------------------------------------
  38. # Clear CTK_BASE_INCLUDE_DIRS and CTK_BASE_LIBRARIES
  39. #
  40. SET(CTK_BASE_LIBRARIES CACHE INTERNAL "CTK libraries" FORCE)
  41. SET(CTK_BASE_INCLUDE_DIRS CACHE INTERNAL "CTK includes" FORCE)
  42. #-----------------------------------------------------------------------------
  43. # CMake Macro(s)
  44. #
  45. INCLUDE(CMake/ctkMacroParseArguments.cmake)
  46. INCLUDE(CMake/ctkMacroBuildQtLib.cmake)
  47. INCLUDE(CMake/ctkMacroBuildQtPlugin.cmake)
  48. INCLUDE(CMake/ctkMacroBuildQtApp.cmake)
  49. INCLUDE(CMake/ctkMacroSetupQt.cmake)
  50. INCLUDE(CMake/ctkMacroGetTargetLibraries.cmake)
  51. INCLUDE(CMake/ctkMacroAddCtkLibraryOptions.cmake)
  52. #-----------------------------------------------------------------------------
  53. # Patch program
  54. #
  55. FIND_PROGRAM(CTK_PATCH_EXECUTABLE patch
  56. "C:/Program Files/GnuWin32/bin"
  57. "C:/Program Files (x86)/GnuWin32/bin")
  58. MARK_AS_ADVANCED(CTK_PATCH_EXECUTABLE)
  59. #-----------------------------------------------------------------------------
  60. # Testing
  61. #
  62. OPTION(BUILD_TESTING "Test the project" ON)
  63. IF(BUILD_TESTING)
  64. ENABLE_TESTING()
  65. INCLUDE(CTest)
  66. SET(CXX_TEST_PATH ${EXECUTABLE_OUTPUT_PATH})
  67. MARK_AS_ADVANCED(TCL_TCLSH DART_ROOT)
  68. # Setup file for setting custom ctest vars
  69. CONFIGURE_FILE(
  70. CMake/CTestCustom.cmake.in
  71. ${CMAKE_CURRENT_BINARY_DIR}/CTestCustom.cmake
  72. @ONLY
  73. )
  74. # Configuration for the CMake-generated test driver
  75. SET(CMAKE_TESTDRIVER_EXTRA_INCLUDES "#include <stdexcept>")
  76. SET(CMAKE_TESTDRIVER_BEFORE_TESTMAIN "
  77. try
  78. {")
  79. SET(CMAKE_TESTDRIVER_AFTER_TESTMAIN " }
  80. catch( std::exception & excp )
  81. {
  82. fprintf(stderr,\"%s\\n\",excp.what());
  83. return EXIT_FAILURE;
  84. }
  85. catch( ... )
  86. {
  87. printf(\"Exception caught in the test driver\\n\");
  88. return EXIT_FAILURE;
  89. }
  90. ")
  91. ENDIF()
  92. #-----------------------------------------------------------------------------
  93. # QT
  94. #
  95. ctkMacroSetupQt()
  96. # Update CTK_BASE_LIBRARIES with QT libraries
  97. IF(QT4_FOUND)
  98. SET(CTK_BASE_LIBRARIES ${CTK_BASE_LIBRARIES} ${QT_LIBRARIES} CACHE INTERNAL "CTK libraries" FORCE)
  99. ENDIF()
  100. #-----------------------------------------------------------------------------
  101. # CTK Libraries
  102. #
  103. SET(ctk_libs
  104. Core
  105. Widgets
  106. DICOM/Core
  107. DICOM/Widgets
  108. )
  109. #-----------------------------------------------------------------------------
  110. # CTK Plugins
  111. #
  112. SET(ctk_plugins
  113. org.commontk.cli
  114. )
  115. #-----------------------------------------------------------------------------
  116. # CTK Applications
  117. #
  118. SET(ctk_applications
  119. ctkDICOM
  120. ctkDICOMIndexer
  121. )
  122. #-----------------------------------------------------------------------------
  123. # To make options show up in both CTK-SuperBuild and CTK regular build, let's add them
  124. # before the SuperBuild script is included
  125. #
  126. # Let's mark as advanced some default properties
  127. MARK_AS_ADVANCED(CMAKE_INSTALL_PREFIX)
  128. MARK_AS_ADVANCED(DART_TESTING_TIMEOUT)
  129. # KWStyle
  130. OPTION(CTK_USE_KWSTYLE "Enable sourcecode-based style tests." OFF)
  131. #MARK_AS_ADVANCED(CTK_USE_KWSTYLE)
  132. # Build options associated with CTK libraries
  133. # Note also that if
  134. # the file Libs/<DIR>/<LIBNAME>/ctk_library_options.cmake exists and look like:
  135. #
  136. # SET(ctk_library_options
  137. # OPT1:OFF
  138. # OPT2:ON
  139. # )
  140. #
  141. # In addition to 'CTK_LIB_Visualization/XIP' option, the following ones
  142. # will also be available in CMake configure menu:
  143. # CTK_LIB_<DIR>/<LIBNAME>_OPT1 (set to OFF)
  144. # CTK_LIB_<DIR>/<LIBNAME>_OPT2 (set to ON)
  145. #
  146. FOREACH(lib ${ctk_libs})
  147. OPTION(CTK_LIB_${lib} "Enable ${lib} Library." ON)
  148. ctkMacroAddCtkLibraryOptions(${lib})
  149. ENDFOREACH()
  150. # Build options associated with CTK plugins
  151. FOREACH(plugin ${ctk_plugins})
  152. OPTION(CTK_PLUGIN_${plugin} "Build ${plugin} Plugin." ON)
  153. ENDFOREACH()
  154. # Build options associated with CTK applications
  155. FOREACH(app ${ctk_applications})
  156. OPTION(CTK_APP_${app} "Build ${app} Application." ON)
  157. ENDFOREACH()
  158. #-----------------------------------------------------------------------------
  159. # Superbuild is used by default
  160. #
  161. OPTION(CTK_SUPERBUILD "Build CTK and the projects it depends on via SuperBuild.cmake." ON)
  162. MARK_AS_ADVANCED(CTK_SUPERBUILD)
  163. IF(CTK_SUPERBUILD)
  164. INCLUDE("${CMAKE_CURRENT_SOURCE_DIR}/SuperBuild.cmake")
  165. RETURN()
  166. ENDIF()
  167. #-----------------------------------------------------------------------------
  168. # Add CTK library subdirectories
  169. #
  170. FOREACH(lib ${ctk_libs})
  171. IF (CTK_LIB_${lib})
  172. ADD_SUBDIRECTORY(Libs/${lib})
  173. ENDIF()
  174. ENDFOREACH()
  175. #-----------------------------------------------------------------------------
  176. # Add CTK plugin subdirectories
  177. #
  178. FOREACH(plugin ${ctk_plugins})
  179. IF (CTK_PLUGIN_${plugin})
  180. ADD_SUBDIRECTORY(Plugins/${plugin})
  181. ENDIF()
  182. ENDFOREACH()
  183. #-----------------------------------------------------------------------------
  184. # Add CTK application subdirectories
  185. #
  186. FOREACH(app ${ctk_applications})
  187. IF (CTK_APP_${app})
  188. ADD_SUBDIRECTORY(Applications/${app})
  189. ENDIF()
  190. ENDFOREACH()
  191. #-----------------------------------------------------------------------------
  192. # Add general purpose subdirectories
  193. #
  194. ADD_SUBDIRECTORY(Testing)
  195. ADD_SUBDIRECTORY(Examples)
  196. #-----------------------------------------------------------------------------
  197. # Style Checking configuration
  198. #
  199. INCLUDE(Utilities/KWStyle/KWStyle.cmake)