-
Notifications
You must be signed in to change notification settings - Fork 33
/
Copy pathctkMacroBuildLib.cmake
131 lines (116 loc) · 3.6 KB
/
ctkMacroBuildLib.cmake
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
###########################################################################
#
# Library: CTK
#
# Copyright (c) 2010 Kitware Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.commontk.org/LICENSE
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
###########################################################################
include(GenerateExportHeader)
macro(ctkMacroBuildLib)
set(prefix ${PROJECT_NAME})
if(prefix STREQUAL "")
message(SEND_ERROR "prefix should NOT be empty !")
endif()
set(options)
set(oneValueArgs NAME LIBRARY_TYPE LABEL)
set(multiValueArgs
SRCS
MOC_SRCS
UI_FORMS
INCLUDE_DIRECTORIES
INSTALL_INCLUDE_DIRECTORIES
TARGET_LIBRARIES
RESOURCES
)
cmake_parse_arguments(${prefix} "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
# Sanity checks
if(NOT DEFINED ${prefix}_NAME)
message(SEND_ERROR "NAME is mandatory")
endif()
if(NOT DEFINED ${prefix}_LIBRARY_TYPE)
set(${prefix}_LIBRARY_TYPE "SHARED")
endif()
if(NOT DEFINED ${prefix}_LABEL)
set(${prefix}_LABEL ${${prefix}_NAME})
endif()
# Define library name
set(lib_name ${${prefix}_NAME})
# --------------------------------------------------------------------------
# Make sure variable are cleared
set(${prefix}_MOC_CXX)
set(${prefix}_UI_CXX)
set(${prefix}_QRC_SRCS)
# Wrap
QT4_WRAP_CPP(${prefix}_MOC_CXX ${${prefix}_MOC_SRCS})
QT4_WRAP_UI(${prefix}_UI_CXX ${${prefix}_UI_FORMS})
if(DEFINED ${prefix}_RESOURCES)
QT4_ADD_RESOURCES(${prefix}_QRC_SRCS ${${prefix}_RESOURCES})
endif()
source_group("Resources" FILES
${${prefix}_RESOURCES}
${${prefix}_UI_FORMS}
)
source_group("Generated" FILES
${${prefix}_QRC_SRCS}
${${prefix}_MOC_CXX}
${${prefix}_UI_CXX}
)
add_library(${lib_name} ${${prefix}_LIBRARY_TYPE}
${${prefix}_SRCS}
${${prefix}_MOC_CXX}
${${prefix}_UI_CXX}
${${prefix}_QRC_SRCS}
)
# Set labels associated with the target.
set_target_properties(${lib_name} PROPERTIES LABELS ${${prefix}_LABEL})
# Apply user-defined properties to the library target.
if(CTK_LIBRARY_PROPERTIES AND ${prefix}_LIBRARY_TYPE STREQUAL "SHARED")
set_target_properties(${lib_name} PROPERTIES ${CTK_LIBRARY_PROPERTIES})
endif()
set(my_libs
${${prefix}_TARGET_LIBRARIES}
)
target_link_libraries(${lib_name} PUBLIC
${my_libs}
)
foreach(_include_dir IN LISTS ${prefix}_INCLUDE_DIRECTORIES)
target_include_directories(${lib_name} PUBLIC
$<BUILD_INTERFACE:${_include_dir}>
)
endforeach()
foreach(_include_dir IN LISTS ${prefix}_INSTALL_INCLUDE_DIRECTORIES)
target_include_directories(${lib_name} PUBLIC
$<INSTALL_INTERFACE:${_include_dir}>
)
endforeach()
# Export header
generate_export_header(${lib_name}
BASE_NAME ${lib_name}
EXPORT_FILE_NAME ${lib_name}Export.h
)
set(dynamicHeaders
${CMAKE_CURRENT_BINARY_DIR}/${lib_name}Export.h
)
# Install headers
if(CTKAppLauncher_INSTALL_LauncherLibrary)
file(GLOB headers "${CMAKE_CURRENT_SOURCE_DIR}/*.h")
install(
FILES
${headers}
${dynamicHeaders}
DESTINATION ${CTK_INSTALL_INCLUDE_DIR} COMPONENT Development
)
endif()
endmacro()