ctkMacroBuildApp.cmake 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. ###########################################################################
  2. #
  3. # Library: CTK
  4. #
  5. # Copyright (c) 2010 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 contains"
  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. ${CTK_BASE_INCLUDE_DIRS}
  55. ${CMAKE_CURRENT_SOURCE_DIR}
  56. ${CMAKE_CURRENT_BINARY_DIR}
  57. ${MY_INCLUDE_DIRECTORIES}
  58. )
  59. SET(CTK_BASE_INCLUDE_DIRS ${my_includes} CACHE INTERNAL "CTK includes" FORCE)
  60. INCLUDE_DIRECTORIES(${CTK_BASE_INCLUDE_DIRS})
  61. # SET(MY_LIBRARY_EXPORT_DIRECTIVE ${MY_EXPORT_DIRECTIVE})
  62. # SET(MY_EXPORT_HEADER_PREFIX ${MY_NAME})
  63. # SET(MY_LIBNAME ${lib_name})
  64. # CONFIGURE_FILE(
  65. # ${CTK_SOURCE_DIR}/Libs/CTKExport.h.in
  66. # ${CMAKE_CURRENT_BINARY_DIR}/${MY_EXPORT_HEADER_PREFIX}Export.h
  67. # )
  68. # SET(dynamicHeaders
  69. # "${dynamicHeaders};${CMAKE_CURRENT_BINARY_DIR}/${MY_EXPORT_HEADER_PREFIX}Export.h")
  70. # Make sure variable are cleared
  71. SET(MY_UI_CXX)
  72. SET(MY_MOC_CXX)
  73. SET(MY_QRC_SRCS)
  74. # Wrap
  75. QT4_WRAP_CPP(MY_MOC_CXX ${MY_MOC_SRCS})
  76. QT4_WRAP_UI(MY_UI_CXX ${MY_UI_FORMS})
  77. IF(DEFINED MY_RESOURCES)
  78. QT4_ADD_RESOURCES(MY_QRC_SRCS ${MY_RESOURCES})
  79. ENDIF()
  80. SOURCE_GROUP("Resources" FILES
  81. ${MY_RESOURCES}
  82. ${MY_UI_FORMS}
  83. )
  84. SOURCE_GROUP("Generated" FILES
  85. ${MY_QRC_SRCS}
  86. ${MY_MOC_CXX}
  87. ${MY_UI_CXX}
  88. )
  89. # Create executable
  90. ADD_EXECUTABLE(${proj_name}
  91. ${MY_SRCS}
  92. ${MY_MOC_CXX}
  93. ${MY_UI_CXX}
  94. ${MY_QRC_SRCS}
  95. )
  96. # ADD_LIBRARY(${lib_name} ${MY_LIBRARY_TYPE}
  97. # ${MY_SRCS}
  98. # ${MY_MOC_CXX}
  99. # ${MY_UI_CXX}
  100. # ${MY_QRC_SRCS}
  101. # )
  102. # Set labels associated with the target.
  103. SET_TARGET_PROPERTIES(${proj_name} PROPERTIES LABELS ${proj_name})
  104. # Install rules
  105. IF(CTK_BUILD_SHARED_LIBS)
  106. INSTALL(TARGETS ${proj_name}
  107. RUNTIME DESTINATION ${CTK_INSTALL_BIN_DIR} COMPONENT Runtime
  108. LIBRARY DESTINATION ${CTK_INSTALL_LIB_DIR} COMPONENT Runtime
  109. ARCHIVE DESTINATION ${CTK_INSTALL_LIB_DIR} COMPONENT Development)
  110. ENDIF()
  111. SET(my_libs
  112. ${MY_TARGET_LIBRARIES}
  113. )
  114. TARGET_LINK_LIBRARIES(${proj_name} ${my_libs})
  115. # Update CTK_BASE_LIBRARIES
  116. # SET(CTK_BASE_LIBRARIES ${my_libs} ${lib_name} CACHE INTERNAL "CTK base libraries" FORCE)
  117. # Install headers
  118. FILE(GLOB headers "${CMAKE_CURRENT_SOURCE_DIR}/*.h")
  119. INSTALL(FILES
  120. ${headers}
  121. ${dynamicHeaders}
  122. DESTINATION ${CTK_INSTALL_INCLUDE_DIR} COMPONENT Development
  123. )
  124. ENDMACRO()