ctkMacroBuildApp.cmake 4.2 KB

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