1 ###########################################################################
5 # Copyright (c) Kitware Inc.
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
11 # http://www.apache.org/licenses/LICENSE-2.0.txt
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.
19 ###########################################################################
23 # CTK/CMake/ctkMacroParseArguments.cmake
27 macro(ctkMacroBuildApp)
28 ctkMacroParseArguments(MY
29 "NAME;SRCS;MOC_SRCS;UI_FORMS;INCLUDE_DIRECTORIES;TARGET_LIBRARIES;RESOURCES"
34 # Keep parameter 'INCLUDE_DIRECTORIES' for backward compatiblity
37 if(NOT DEFINED MY_NAME)
38 message(FATAL_ERROR "NAME is mandatory")
41 # Make sure either the source or the binary directory associated with the application
42 # contains a file named ${MY_NAME}Main.cpp
43 set(expected_mainfile ${MY_NAME}Main.cpp)
44 if (NOT EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${expected_mainfile} AND
45 NOT EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${expected_mainfile}.in AND
46 NOT EXISTS ${CMAKE_CURRENT_BINARY_DIR}/${expected_mainfile})
47 message(FATAL_ERROR "Application directory: ${MY_NAME} should contain"
48 " a file named ${expected_mainfile} or ${expected_mainfile}.in")
52 set(proj_name ${MY_NAME})
54 # --------------------------------------------------------------------------
57 ${CMAKE_CURRENT_SOURCE_DIR}
58 ${CMAKE_CURRENT_BINARY_DIR}
61 # Add the include directories from the library dependencies
62 ctkFunctionGetIncludeDirs(my_includes ${proj_name})
64 include_directories(${my_includes})
66 # Add the library directories from the external project
67 ctkFunctionGetLibraryDirs(my_library_dirs ${proj_name})
73 if(CTK_QT_VERSION VERSION_LESS "5")
74 # Add Qt include dirs and defines
75 include(${QT_USE_FILE})
78 # Make sure variable are cleared
83 if (CTK_QT_VERSION VERSION_GREATER "4")
86 # this is a workaround for Visual Studio. The relative include paths in the generated
87 # moc files can get very long and can't be resolved by the MSVC compiler.
88 foreach(moc_src ${MY_MOC_SRCS})
89 QT5_WRAP_CPP(MY_MOC_CPP ${moc_src} OPTIONS -f${moc_src} OPTIONS -DHAVE_QT5)
92 QT5_WRAP_UI(MY_UI_CPP ${MY_UI_FORMS})
93 if(DEFINED MY_RESOURCES)
94 QT5_ADD_RESOURCES(MY_QRC_SRCS ${MY_RESOURCES})
99 # this is a workaround for Visual Studio. The relative include paths in the generated
100 # moc files can get very long and can't be resolved by the MSVC compiler.
101 foreach(moc_src ${MY_MOC_SRCS})
102 QT4_WRAP_CPP(MY_MOC_CPP ${moc_src} OPTIONS -f${moc_src})
105 QT4_WRAP_UI(MY_UI_CPP ${MY_UI_FORMS})
106 if(DEFINED MY_RESOURCES)
107 QT4_ADD_RESOURCES(MY_QRC_SRCS ${MY_RESOURCES})
111 source_group("Resources" FILES
116 source_group("Generated" FILES
123 add_executable(${proj_name}
130 # Set labels associated with the target.
131 set_target_properties(${proj_name} PROPERTIES LABELS ${proj_name})
134 install(TARGETS ${proj_name}
135 RUNTIME DESTINATION ${CTK_INSTALL_BIN_DIR} COMPONENT RuntimeApplications
139 ${MY_TARGET_LIBRARIES}
141 target_link_libraries(${proj_name} ${my_libs})
145 file(GLOB headers "${CMAKE_CURRENT_SOURCE_DIR}/*.h")
149 DESTINATION ${CTK_INSTALL_INCLUDE_DIR} COMPONENT Development