ctkMacroBuildApp.cmake 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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. # Make sure either the source or the binary directory associated with the application
  35. # contains a file named ${MY_NAME}Main.cpp
  36. set(expected_mainfile ${MY_NAME}Main.cpp)
  37. if (NOT EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${expected_mainfile} AND
  38. NOT EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${expected_mainfile}.in AND
  39. NOT EXISTS ${CMAKE_CURRENT_BINARY_DIR}/${expected_mainfile})
  40. MESSAGE(FATAL_ERROR "Application directory: ${MY_NAME} should contain"
  41. " a file named ${expected_mainfile} or ${expected_mainfile}.in")
  42. endif()
  43. # Define library name
  44. SET(proj_name ${MY_NAME})
  45. # --------------------------------------------------------------------------
  46. # Include dirs
  47. SET(my_includes
  48. ${CMAKE_CURRENT_SOURCE_DIR}
  49. ${CMAKE_CURRENT_BINARY_DIR}
  50. ${MY_INCLUDE_DIRECTORIES}
  51. )
  52. # Add the include directories from the library dependencies
  53. ctkFunctionGetIncludeDirs(my_includes ${proj_name})
  54. INCLUDE_DIRECTORIES(${my_includes})
  55. # Add the library directories from the external project
  56. ctkFunctionGetLibraryDirs(my_library_dirs ${proj_name})
  57. LINK_DIRECTORIES(
  58. ${my_library_dirs}
  59. )
  60. # Make sure variable are cleared
  61. SET(MY_UI_CPP)
  62. SET(MY_MOC_CPP)
  63. SET(MY_QRC_SRCS)
  64. # Wrap
  65. QT4_WRAP_CPP(MY_MOC_CPP ${MY_MOC_SRCS})
  66. QT4_WRAP_UI(MY_UI_CPP ${MY_UI_FORMS})
  67. IF(DEFINED MY_RESOURCES)
  68. QT4_ADD_RESOURCES(MY_QRC_SRCS ${MY_RESOURCES})
  69. ENDIF()
  70. SOURCE_GROUP("Resources" FILES
  71. ${MY_RESOURCES}
  72. ${MY_UI_FORMS}
  73. )
  74. SOURCE_GROUP("Generated" FILES
  75. ${MY_QRC_SRCS}
  76. ${MY_MOC_CPP}
  77. ${MY_UI_CPP}
  78. )
  79. # Create executable
  80. ADD_EXECUTABLE(${proj_name}
  81. ${MY_SRCS}
  82. ${MY_MOC_CPP}
  83. ${MY_UI_CPP}
  84. ${MY_QRC_SRCS}
  85. )
  86. # Set labels associated with the target.
  87. SET_TARGET_PROPERTIES(${proj_name} PROPERTIES LABELS ${proj_name})
  88. # Install rules
  89. INSTALL(TARGETS ${proj_name}
  90. RUNTIME DESTINATION ${CTK_INSTALL_BIN_DIR} COMPONENT Runtime
  91. LIBRARY DESTINATION ${CTK_INSTALL_LIB_DIR} COMPONENT Runtime
  92. ARCHIVE DESTINATION ${CTK_INSTALL_LIB_DIR} COMPONENT Development)
  93. SET(my_libs
  94. ${MY_TARGET_LIBRARIES}
  95. )
  96. TARGET_LINK_LIBRARIES(${proj_name} ${my_libs})
  97. # Install headers
  98. FILE(GLOB headers "${CMAKE_CURRENT_SOURCE_DIR}/*.h")
  99. INSTALL(FILES
  100. ${headers}
  101. ${dynamicHeaders}
  102. DESTINATION ${CTK_INSTALL_INCLUDE_DIR} COMPONENT Development
  103. )
  104. ENDMACRO()