ctkMacroBuildApp.cmake 3.4 KB

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