ctkMacroBuildApp.cmake 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. ###########################################################################
  2. #
  3. # Library: CTK
  4. #
  5. # Copyright (c) Kitware Inc.
  6. #
  7. # Licensed under the Apache License, Version 2.0 (the "License");
  8. # you may not use this file except in compliance with the License.
  9. # You may obtain a copy of the License at
  10. #
  11. # http://www.commontk.org/LICENSE
  12. #
  13. # Unless required by applicable law or agreed to in writing, software
  14. # distributed under the License is distributed on an "AS IS" BASIS,
  15. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  16. # See the License for the specific language governing permissions and
  17. # limitations under the License.
  18. #
  19. ###########################################################################
  20. #
  21. # Depends on:
  22. # CTK/CMake/ctkMacroParseArguments.cmake
  23. #
  24. MACRO(ctkMacroBuildApp)
  25. ctkMacroParseArguments(MY
  26. "NAME;SRCS;MOC_SRCS;UI_FORMS;INCLUDE_DIRECTORIES;TARGET_LIBRARIES;RESOURCES"
  27. ""
  28. ${ARGN}
  29. )
  30. # Sanity checks
  31. IF(NOT DEFINED MY_NAME)
  32. MESSAGE(SEND_ERROR "NAME is mandatory")
  33. ENDIF()
  34. # IF(NOT DEFINED MY_EXPORT_DIRECTIVE)
  35. # MESSAGE(SEND_ERROR "EXPORT_DIRECTIVE is mandatory")
  36. # ENDIF()
  37. # IF(NOT DEFINED MY_LIBRARY_TYPE)
  38. # SET(MY_LIBRARY_TYPE "SHARED")
  39. # ENDIF()
  40. # Make sure either the source or the binary directory associated with the application
  41. # contains a file named ${MY_NAME}Main.cpp
  42. set(expected_mainfile ${MY_NAME}Main.cpp)
  43. if (NOT EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${expected_mainfile} AND
  44. NOT EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${expected_mainfile}.in AND
  45. NOT EXISTS ${CMAKE_CURRENT_BINARY_DIR}/${expected_mainfile})
  46. MESSAGE(FATAL_ERROR "Application directory: ${MY_NAME} should contain"
  47. " a file named ${expected_mainfile} or ${expected_mainfile}.in")
  48. endif()
  49. # Define library name
  50. SET(proj_name ${MY_NAME})
  51. # --------------------------------------------------------------------------
  52. # Include dirs
  53. SET(my_includes
  54. ${CMAKE_CURRENT_SOURCE_DIR}
  55. ${CMAKE_CURRENT_BINARY_DIR}
  56. ${MY_INCLUDE_DIRECTORIES}
  57. )
  58. # Add the include directories from the library dependencies
  59. # The variable ${lib_name}_DEPENDENCIES is set in the
  60. # macro ctkMacroValidateBuildOptions
  61. SET(ctk_deps )
  62. SET(ext_deps )
  63. ctkMacroGetAllCTKTargetLibraries("${${proj_name}_DEPENDENCIES}" ctk_deps)
  64. ctkMacroGetAllNonCTKTargetLibraries("${${proj_name}_DEPENDENCIES}" ext_deps)
  65. FOREACH(dep ${ctk_deps})
  66. LIST(APPEND my_includes
  67. ${${dep}_SOURCE_DIR}
  68. ${${dep}_BINARY_DIR}
  69. )
  70. ENDFOREACH()
  71. FOREACH(dep ${ext_deps})
  72. STRING(REPLACE "^" ";" _include_dirs "${${dep}_INCLUDE_DIRS}")
  73. LIST(APPEND my_includes ${_include_dirs})
  74. ENDFOREACH()
  75. LIST(REMOVE_DUPLICATES my_includes)
  76. INCLUDE_DIRECTORIES(${my_includes})
  77. # SET(MY_LIBRARY_EXPORT_DIRECTIVE ${MY_EXPORT_DIRECTIVE})
  78. # SET(MY_EXPORT_HEADER_PREFIX ${MY_NAME})
  79. # SET(MY_LIBNAME ${lib_name})
  80. # CONFIGURE_FILE(
  81. # ${CTK_SOURCE_DIR}/Libs/CTKExport.h.in
  82. # ${CMAKE_CURRENT_BINARY_DIR}/${MY_EXPORT_HEADER_PREFIX}Export.h
  83. # )
  84. # SET(dynamicHeaders
  85. # "${dynamicHeaders};${CMAKE_CURRENT_BINARY_DIR}/${MY_EXPORT_HEADER_PREFIX}Export.h")
  86. # Make sure variable are cleared
  87. SET(MY_UI_CXX)
  88. SET(MY_MOC_CXX)
  89. SET(MY_QRC_SRCS)
  90. # Wrap
  91. QT4_WRAP_CPP(MY_MOC_CXX ${MY_MOC_SRCS})
  92. QT4_WRAP_UI(MY_UI_CXX ${MY_UI_FORMS})
  93. IF(DEFINED MY_RESOURCES)
  94. QT4_ADD_RESOURCES(MY_QRC_SRCS ${MY_RESOURCES})
  95. ENDIF()
  96. SOURCE_GROUP("Resources" FILES
  97. ${MY_RESOURCES}
  98. ${MY_UI_FORMS}
  99. )
  100. SOURCE_GROUP("Generated" FILES
  101. ${MY_QRC_SRCS}
  102. ${MY_MOC_CXX}
  103. ${MY_UI_CXX}
  104. )
  105. # Create executable
  106. ADD_EXECUTABLE(${proj_name}
  107. ${MY_SRCS}
  108. ${MY_MOC_CXX}
  109. ${MY_UI_CXX}
  110. ${MY_QRC_SRCS}
  111. )
  112. # ADD_LIBRARY(${lib_name} ${MY_LIBRARY_TYPE}
  113. # ${MY_SRCS}
  114. # ${MY_MOC_CXX}
  115. # ${MY_UI_CXX}
  116. # ${MY_QRC_SRCS}
  117. # )
  118. # Set labels associated with the target.
  119. SET_TARGET_PROPERTIES(${proj_name} PROPERTIES LABELS ${proj_name})
  120. # Install rules
  121. IF(CTK_BUILD_SHARED_LIBS)
  122. INSTALL(TARGETS ${proj_name}
  123. RUNTIME DESTINATION ${CTK_INSTALL_BIN_DIR} COMPONENT Runtime
  124. LIBRARY DESTINATION ${CTK_INSTALL_LIB_DIR} COMPONENT Runtime
  125. ARCHIVE DESTINATION ${CTK_INSTALL_LIB_DIR} COMPONENT Development)
  126. ENDIF()
  127. SET(my_libs
  128. ${MY_TARGET_LIBRARIES}
  129. )
  130. TARGET_LINK_LIBRARIES(${proj_name} ${my_libs})
  131. # Update CTK_BASE_LIBRARIES
  132. # SET(CTK_BASE_LIBRARIES ${my_libs} ${lib_name} CACHE INTERNAL "CTK base libraries" FORCE)
  133. # Install headers
  134. FILE(GLOB headers "${CMAKE_CURRENT_SOURCE_DIR}/*.h")
  135. INSTALL(FILES
  136. ${headers}
  137. ${dynamicHeaders}
  138. DESTINATION ${CTK_INSTALL_INCLUDE_DIR} COMPONENT Development
  139. )
  140. ENDMACRO()