Project

General

Profile

Support Request #2240 » ADTFMacros.cmake

hidden, 2018-04-16 14:51

 
1
################################################################################
2
#
3
# ADTF CMake macros file
4
#
5
# Copyright © Audi Electronics Venture GmbH. All rights reserved.
6
#
7
################################################################################
8
#
9
# TODO Description 
10
#
11
################################################################################
12

    
13
################################################################################
14
## \page page_cmake_commands
15
# <hr>
16
# <b>adtf_add_post_build_install(\<name\>)</b>
17
#
18
# This command works only on windows with MSVC.
19
# It's automatically used by each adtf examples build target (executable, filter,
20
# service, ...) using the macros (adtf_add_executable,
21
# adtf_add_filter, ...).
22
# Cmake adds a post build event to each target, which will be executed directly after build AND
23
# installs the target binary. Different from the standard CMake install target,
24
# this will NOT include subdirectories.
25
#
26
# Arguments:
27
# \li \<name\>:
28
# The name of the target.
29
################################################################################
30
macro(adtf_add_post_build_install NAME)
31
    if(MSVC)
32
        add_custom_command(TARGET ${NAME} POST_BUILD COMMAND ${CMAKE_COMMAND} -DCMAKE_INSTALL_CONFIG_NAME=${CMAKE_CFG_INTDIR} -DCMAKE_INSTALL_LOCAL_ONLY=true -P cmake_install.cmake)
33
    else(MSVC)
34
        add_custom_command(TARGET ${NAME} POST_BUILD COMMAND ${CMAKE_COMMAND} -DCMAKE_INSTALL_CONFIG_NAME=${CMAKE_BUILD_TYPE} -DCMAKE_INSTALL_LOCAL_ONLY=true -P cmake_install.cmake)
35
    endif(MSVC)
36
endmacro(adtf_add_post_build_install NAME)
37

    
38
################################################################################
39
## \page page_cmake_commands
40
# <hr>
41
# <b>adtf_add_plugin(\<name\> \<source1\> ... \<sourceN\>)</b>
42
#
43
# This command adds a new ADTF plugin target (a adtfplugin).
44
#
45
# Arguments:
46
# \li \<name\>:
47
# The name of the target
48
# \li \<sourceX\>:
49
# The source files of the target.
50
################################################################################
51
macro(adtf_add_plugin NAME)   
52
    add_library(${NAME} MODULE ${ARGN})
53
    set_target_properties(${NAME}
54
        PROPERTIES
55
        SUFFIX ".adtfplugin"
56
    )
57
    if(UNIX)
58
        set_target_properties(${NAME}
59
            PROPERTIES
60
            PREFIX ""
61
        )
62
    endif(UNIX)
63
    adtf_add_post_build_install(${NAME})
64
endmacro(adtf_add_plugin NAME)
65

    
66
################################################################################
67
## \page page_cmake_commands
68
# <hr>
69
# <b>adtf_add_filter(\<name\> \<source1\> ... \<sourceN\>)</b>
70
#
71
# This command adds a new ADTF filter target (a adtfplugin file that contains filter 
72
# modules) and execute an install directly after build.
73
#
74
# Arguments:
75
# \li \<name\>:
76
# The name of the target
77
# \li \<sourceX\>:
78
# The source files of the target.
79
################################################################################
80
macro(adtf_add_filter NAME)
81
    adtf_add_plugin(${NAME} ${ARGN})
82
    target_link_libraries(${NAME} PUBLIC adtf::filtersdk)
83
endmacro(adtf_add_filter NAME)
84

    
85
################################################################################
86
## \page page_cmake_commands
87
# <hr>
88
# <b>adtf_add_streaming_service(\<name\> \<source1\> ... \<sourceN\>)</b>
89
#
90
# This command adds a new ADTF streaming service target (a adtfplugin file that contains streaming service 
91
# modules) and execute an install directly after build.
92
#
93
# Arguments:
94
# \li \<name\>:
95
# The name of the target
96
# \li \<sourceX\>:
97
# The source files of the target.
98
################################################################################
99
macro(adtf_add_streaming_service NAME)
100
    adtf_add_plugin(${NAME} ${ARGN})
101
    target_link_libraries(${NAME} PUBLIC adtf::systemsdk)
102
endmacro(adtf_add_streaming_service NAME)
103

    
104
################################################################################
105
## \page page_cmake_commands
106
# <hr>
107
# <b>adtf_add_system_service(\<name\> \<source1\> ... \<sourceN\>)</b>
108
#
109
# This command adds a new ADTF system service target (a adtfplugin file that contains a 
110
# system service module) and execute an install directly after build.
111
#
112
# Arguments:
113
# \li \<name\>:
114
# The name of the target
115
# \li \<sourceX\>:
116
# The source files of the target.
117
################################################################################
118
macro(adtf_add_system_service NAME)
119
    adtf_add_plugin(${NAME} ${ARGN})    
120
    target_link_libraries(${NAME} PUBLIC adtf::systemsdk)
121
endmacro(adtf_add_system_service NAME)
122

    
123
################################################################################
124
## \page page_cmake_commands
125
# <hr>
126
# <b>adtf_add_executable(\<name\> \<source1\> ... \<sourceN\>)</b>
127
#
128
# This command adds a new ADTF service target (a adtfplugin file and a 
129
# exe file) and execute an install directly after build.
130
#
131
# Arguments:
132
# \li \<name\>:
133
# The name of the target
134
# \li \<sourceX\>:
135
# The source files of the target.
136
################################################################################
137
macro(adtf_add_executable NAME)
138
    add_executable(${NAME} ${ARGN})
139
    adtf_add_post_build_install(${NAME})
140
endmacro(adtf_add_executable NAME)
141

    
142
################################################################################
143
## \page page_cmake_commands
144
# <hr>
145
# <b>adtf_install_target(\<target\> \<directory\>)</b>
146
#
147
# This command installs a target to the given location during
148
# installation.
149
#
150
# Arguments:
151
# \li \<target\>:
152
# The name of the target that should be installed.
153
# \li \<directory\>:
154
# The directory where the target should be installed to.
155
################################################################################
156
macro(adtf_install_target TARGET DIRECTORY)
157
    install(TARGETS ${TARGET} DESTINATION ${DIRECTORY}/debug CONFIGURATIONS Debug)
158
    install(TARGETS ${TARGET} DESTINATION ${DIRECTORY} CONFIGURATIONS Release RelWithDebInfo)
159
    if(WIN32)
160
        get_target_property(NAME ${TARGET} OUTPUT_NAME)
161
        if(NOT NAME)
162
            set(NAME ${TARGET})
163
        endif(NOT NAME)
164
        if(MSVC_IDE)
165
            set(PDB_FULL_PATH_DEBUG ${CMAKE_CURRENT_BINARY_DIR}/${${TARGET}_BUILD_NAME_}/Debug/${NAME}.pdb)
166
            install(FILES ${PDB_FULL_PATH_DEBUG} DESTINATION ${DIRECTORY}/debug CONFIGURATIONS Debug)
167
            set(PDB_FULL_PATH_RELWITHDEBINFO ${CMAKE_CURRENT_BINARY_DIR}/${${TARGET}_BUILD_NAME_}/RelWithDebInfo/${NAME}.pdb)
168
            install(FILES ${PDB_FULL_PATH_RELWITHDEBINFO} DESTINATION ${DIRECTORY} CONFIGURATIONS RelWithDebInfo)
169
        elseif()
170
            set(PDB_FULL_PATH ${CMAKE_CURRENT_BINARY_DIR}/${${TARGET}_BUILD_NAME_}/${NAME}.pdb)
171
            install(FILES ${PDB_FULL_PATH} DESTINATION ${DIRECTORY}/debug CONFIGURATIONS Debug)
172
            install(FILES ${PDB_FULL_PATH} DESTINATION ${DIRECTORY} CONFIGURATIONS RelWithDebInfo)
173
        endif()
174
    endif(WIN32)
175
endmacro(adtf_install_target TARGET DIRECTORY)
176

    
177
################################################################################
178
## \page page_cmake_commands
179
# <hr>
180
# <b>adtf_install_plugin(\<target\> \<directory\>)</b>
181
#
182
# This command installs a filter or service module to the given location during
183
# installation. 
184
#
185
# Arguments:
186
# \li \<target\>:
187
# The name of the target that should be installed.
188
# \li \<directory\>:
189
# The directory where the target should be installed to.
190
################################################################################
191
macro(adtf_install_plugin TARGET DIRECTORY)
192
    adtf_install_target(${TARGET} ${DIRECTORY} ${ARGN})
193
endmacro(adtf_install_plugin TARGET DIRECTORY)
194

    
195
################################################################################
196
## \page page_cmake_commands
197
# <hr>
198
# <b>adtf_install_plugin(\<target\> \<directory\>)</b>
199
#
200
# This command installs a filter or service module to the given location during
201
# installation. 
202
#
203
# Arguments:
204
# \li \<target\>:
205
# The name of the target that should be installed.
206
# \li \<directory\>:
207
# The directory where the target should be installed to.
208
################################################################################
209
macro(adtf_install_filter TARGET DIRECTORY)
210
    adtf_install_plugin(${TARGET} ${DIRECTORY} ${ARGN})
211
endmacro(adtf_install_filter TARGET DIRECTORY)
212

    
213
################################################################################
214
## \page page_cmake_commands
215
# <hr>
216
# <b>adtf_install_plugin(\<target\> \<directory\>)</b>
217
#
218
# This command installs a filter or service module to the given location during
219
# installation. 
220
#
221
# Arguments:
222
# \li \<target\>:
223
# The name of the target that should be installed.
224
# \li \<directory\>:
225
# The directory where the target should be installed to.
226
################################################################################
227
macro(adtf_install_service TARGET DIRECTORY)
228
     adtf_install_plugin(${TARGET} ${DIRECTORY} ${ARGN})
229
endmacro(adtf_install_service TARGET DIRECTORY)
230

    
231
################################################################################
232
## \page page_cmake_commands
233
# <hr>
234
# <b>adtf_install_program(\<target\> \<directory\>)</b>
235
#
236
# This command installs an executable to the given location during
237
# installation.
238
#
239
# Arguments:
240
# \li \<target\>:
241
# The name of the target that should be installed.
242
# \li \<directory\>:
243
# The directory where the target should be installed to.
244
################################################################################
245
macro(adtf_install_program TARGET DIRECTORY)
246
    adtf_install_target(${TARGET} ${DIRECTORY} ${ARGN})
247
endmacro(adtf_install_program TARGET DIRECTORY)
248

    
249
################################################################################
250
## \page page_cmake_commands
251
# <hr>
252
# <b>adtf_dev_add_qt_project_user_file(\<target_name\> \<exe_name\> \<working_dir_relative_debug\> 
253
#   \<working_dir_relative_release\>)</b>
254
#
255
# This command ...
256
#
257
# Arguments:
258
# \li \<target_name\>:
259
# The name of the poject file without extension. In most cases the
260
# TARGET_NAME
261
# \li \<exe_name\>:
262
# The name of the executable file without extension.
263
# \li \<working_dir_relative_debug\>:
264
# The directory to the debug executable file relative to ADTF_INSTALL_DIR. 
265
# Example: "bin/debug"
266
# \li \<working_dir_relative_release\>:
267
# The directory to the relwithdebinfo executable file relative to
268
# ADTF_INSTALL_DIR. Example: "bin"
269
################################################################################
270
function(adtf_dev_add_qt_project_user_file TARGET_NAME EXE_NAME
271
    WORKING_DIR_RELATIVE_DEBUG WORKING_DIR_RELATIVE_RELEASE) 
272

    
273
    if(NOT ADTF_INSTALL_DIR)
274
        message(SEND_ERROR "ADTF_INSTALL_DIR not set")
275
        RETURN()
276
    endif(NOT ADTF_INSTALL_DIR)
277
        
278
    set(COMMAND_DEBUG "${ADTF_INSTALL_DIR}/${WORKING_DIR_RELATIVE_DEBUG}/${EXE_NAME}.exe")
279
    set(WORKING_DIR_DEBUG "${ADTF_INSTALL_DIR}/${WORKING_DIR_RELATIVE_DEBUG}/")
280
    set(COMMAND_RELEASE "${ADTF_INSTALL_DIR}/${WORKING_DIR_RELATIVE_RELEASE}/${EXE_NAME}.exe")
281
    set(WORKING_DIR_RELEASE "${ADTF_INSTALL_DIR}/${WORKING_DIR_RELATIVE_RELEASE}/")
282
    
283
    vs_add_project_user_file("${TARGET_NAME}"
284
        "${COMMAND_DEBUG}"   " " "${WORKING_DIR_DEBUG}"   " "
285
        "${COMMAND_RELEASE}" " " "${WORKING_DIR_RELEASE}" " ")
286
endfunction()
287

    
288
################################################################################
289
## \page page_cmake_commands
290
# <hr>
291
# <b>vs_add_project_user_file(\<name\>
292
#   \<command_debug\> \<command_arguments_debug\> \<working_directory_debug\> 
293
#   \<environment_debug\> \<command_release\> \<command_arguments_release\> 
294
#   \<working_directory_release\> \<environment_release\> )</b>
295
#
296
# This command generates a *.vcxproj.user file and sets command, command 
297
# arguments and environment für build type "Debug" and "RelWithDebInfo"
298
#
299
################################################################################
300
function(vs_add_project_user_file NAME COMMAND_DEBUG COMMAND_ARGUMENTS_DEBUG 
301
    WORKING_DIRECTORY_DEBUG ENVIRONMENT_DEBUG COMMAND_RELEASE 
302
    COMMAND_ARGUMENTS_RELEASE WORKING_DIRECTORY_RELEASE ENVIRONMENT_RELEASE) 
303

    
304
    if(NOT MSVC_IDE)
305
        RETURN()
306
    endif(NOT MSVC_IDE)
307
    
308
    if(${NAME} STREQUAL "")
309
        message(SEND_ERROR "NAME not set")
310
        RETURN()
311
    endif(${NAME} STREQUAL "")
312
        
313
    # configure_file() ignores macro parameters. Therefore it is necessary to 
314
    # "reset" them - even if there ist no quot in.
315
    string(REPLACE "\"" "&quot;" COMMAND_DEBUG           ${COMMAND_DEBUG})
316
    string(REPLACE "\"" "&quot;" COMMAND_ARGUMENTS_DEBUG ${COMMAND_ARGUMENTS_DEBUG})
317
    string(REPLACE "\"" "&quot;" WORKING_DIRECTORY_DEBUG ${WORKING_DIRECTORY_DEBUG})
318
    string(REPLACE "\"" "&quot;" ENVIRONMENT_DEBUG       ${ENVIRONMENT_DEBUG})
319
    string(REPLACE "\"" "&quot;" COMMAND_RELEASE           ${COMMAND_RELEASE})
320
    string(REPLACE "\"" "&quot;" COMMAND_ARGUMENTS_RELEASE ${COMMAND_ARGUMENTS_RELEASE})
321
    string(REPLACE "\"" "&quot;" WORKING_DIRECTORY_RELEASE ${WORKING_DIRECTORY_RELEASE})
322
    string(REPLACE "\"" "&quot;" ENVIRONMENT_RELEASE       ${ENVIRONMENT_RELEASE})
323
        
324
    set(USER_FILENAME ${CMAKE_CURRENT_BINARY_DIR}/${NAME}.vcxproj.user)
325
       
326
    configure_file(${CMAKE_SOURCE_DIR}/bin/template.vcxproj.user.in ${USER_FILENAME} @ONLY)
327
endfunction()
328

    
329
################################################################################
330
## \page page_cmake_commands
331
# <hr>
332
# <b>adtf_find_sdl()</b>
333
#
334
# This command enables the use of SDL within ADTF. 
335
################################################################################
336
macro(adtf_find_sdl)
337
    find_package(SDL 1.2.11)
338

    
339
    if(SDL_FOUND)
340
        # On Windows platform SDL.dll must be installed with SDL dependent examples
341
        if(MSVC)
342
            set(SDL_DLL CACHE FILEPATH "SDL.dll will be installed with SDL dependent examples")
343
            if(NOT SDL_DLL)
344
                message(FATAL_ERROR "You need to set SDL_DLL in order to install SDL dependent examples")
345
            endif()
346
        endif()
347
    endif()
348
endmacro(adtf_find_sdl)
349

    
350
################################################################################
351
#
352
# This function ensures the creation of a plugindescription file for the given target by calling
353
# the PluginDescriptionGenerator as part of the build.
354
#
355
# Input Parameters:
356
#
357
# TARGET: The name of the target to generate the description for. This must be a ADTF plugin.
358
# PLUGIN_SUBDIR: The sub-directory of the given plugin within ADTF e.g. "examples/bin".
359
# MERGE_DESCRIPTION (optional): Path to an existing .plugindescription file which will be merged into the generated file.
360
# DEPENDENT_PLUGINS (optional): List of plugins which the given target depends on at runtime.
361
#
362
################################################################################
363
function(adtf_create_plugindescription)
364

    
365
    cmake_parse_arguments(PDGEN "" "TARGET;MERGE_DESCRIPTION;PLUGIN_SUBDIR" "DEPENDENT_PLUGINS" ${ARGN})
366

    
367
    if (NOT PDGEN_TARGET)
368
        message(FATAL_ERROR "Missing argument 'TARGET'.")
369
    endif()
370
    if (NOT TARGET ${PDGEN_TARGET})
371
        message(FATAL_ERROR "Unknown Target '${PDGEN_TARGET}'.")
372
    endif()
373
    if (NOT PDGEN_PLUGIN_SUBDIR)
374
        message(FATAL_ERROR "Missing argument 'PLUGIN_SUBDIR'. It should specify the directory of the plugin binary relative to CMAKE_INSTALL_PREFIX.")
375
    endif()
376
    if (PDGEN_MERGE_DESCRIPTION)
377
        if (NOT EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${PDGEN_MERGE_DESCRIPTION})
378
            message(FATAL_ERROR "The plugin description file '${CMAKE_CURRENT_SOURCE_DIR}/${PDGEN_MERGE_DESCRIPTION}' does not seem to exist.")
379
        endif()
380
    endif()
381

    
382
    if (WIN32)
383
        set(EXE_SUFFIX .exe)
384
    endif()
385

    
386
    # Check if we're building ADTF or a client project (e.g. a toolbox).
387
    if (TARGET adtf_plugin_description_generator)
388
        set(IS_ADTF_CORE_BUILD TRUE)
389
    endif()
390

    
391
    # Set the path to the PDG executable accordingly.
392
    if (IS_ADTF_CORE_BUILD)
393
        set (PDGEN_ADTF_INSTALL_DIR ${CMAKE_INSTALL_PREFIX})
394
    else()
395
        set (PDGEN_ADTF_INSTALL_DIR ${ADTF_DIR})
396
    endif()
397
    set(PLUGINDESCRIPTION_GENERATOR "${PDGEN_ADTF_INSTALL_DIR}/bin/$<$<CONFIG:Debug>:debug/>adtf_plugin_description_generator${EXE_SUFFIX}")
398
    
399
    set(OUTPUT_PLUGINDESCRIPTION "${CMAKE_INSTALL_PREFIX}/${PDGEN_PLUGIN_SUBDIR}/$<$<CONFIG:Debug>:debug/>${PDGEN_TARGET}.plugindescription")
400
    
401
    if (DEFINED PDGEN_MERGE_DESCRIPTION)
402
        # Obtain the absolute path to the given .plugindescription file
403
        get_filename_component(MERGE_DESCRIPTION_PATH "${PDGEN_MERGE_DESCRIPTION}"
404
                       REALPATH BASE_DIR "${CMAKE_CURRENT_SOURCE_DIR}")
405
        set(MERGE_ARG "-merge=${MERGE_DESCRIPTION_PATH}")
406
    else()
407
        set(MERGE_ARG "")
408
    endif()
409

    
410
    # Set up build time dependencies to dependent targets.
411
    # If a dependency has a dedicated target for generating its plugindescription we use that one instead.
412
    if (DEFINED PDGEN_DEPENDENT_PLUGINS)
413
        foreach(DEPENDENT_PLUGIN IN LISTS ${PDGEN_DEPENDENT_PLUGINS})
414
            if (NOT TARGET ${DEPENDENT_PLUGIN})
415
                message(FATAL_ERROR "The dependent target ${DEPENDENT_PLUGIN} does not seem to exist.")
416
            endif()
417
            if (TARGET ${DEPENDENT_PLUGIN}_pdgen)
418
                add_dependencies(${PDGEN_TARGET} ${DEPENDENT_PLUGIN}_pdgen)
419
            else()
420
                add_dependencies(${PDGEN_TARGET} ${DEPENDENT_PLUGIN})
421
            endif()
422
        endforeach()
423
    endif()
424
    
425
    # Define a target <plugin_name>_pdgen which exectues the PluginDescriptionGenerator.
426
    add_custom_target(${PDGEN_TARGET}_pdgen ALL
427
        COMMAND
428
            ${PLUGINDESCRIPTION_GENERATOR}
429
            -plugin=$<TARGET_FILE:${PDGEN_TARGET}>
430
            -output=${OUTPUT_PLUGINDESCRIPTION}
431
            ${MERGE_ARG}
432
        COMMENT
433
            "Generating Plugin Description for Target ${PDGEN_TARGET}: ${PLUGINDESCRIPTION_GENERATOR} -plugin=$<TARGET_FILE:${PDGEN_TARGET}> -output=${OUTPUT_PLUGINDESCRIPTION} ${MERGE_ARG}"
434
        DEPENDS
435
            ${PDGEN_TARGET}
436
        SOURCES
437
            "${MERGE_DESCRIPTION_PATH}"
438
    )
439
    
440
    if (IS_ADTF_CORE_BUILD)
441
        add_dependencies(${PDGEN_TARGET}_pdgen adtf_plugin_description_generator)
442
    endif()
443

    
444
    # Put the generated target in the same IDE folder as the plugin's target.
445
    get_target_property(PLUGIN_IDE_FOLDER ${PDGEN_TARGET} FOLDER)
446
    if(PLUGIN_IDE_FOLDER)
447
        set_target_properties(${PDGEN_TARGET}_pdgen PROPERTIES FOLDER ${PLUGIN_IDE_FOLDER})
448
    endif()
449

    
450
endfunction(adtf_create_plugindescription)
451

    
452

    
453

    
454
################################################################################
455
## \page disable_msvc_warning
456
# <hr>
457
#
458
# This function disables a specific warning, <WARNING_NO_AS_STR>, for a specific target, 
459
# <TARGET_TO_DISABLE_>.
460
# Disabling takes only place for MSVC.
461
################################################################################
462
function(disable_msvc_warning TARGET_TO_DISABLE_ WARNING_NO_AS_STR)
463
    if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
464
        set(DISBALE_WARNING_PREFIX "/wd")
465
        string(CONCAT DISABLE_WARNING_STR ${DISBALE_WARNING_PREFIX} ${WARNING_NO_AS_STR})
466
        target_compile_options(${TARGET_TO_DISABLE_} PRIVATE ${DISABLE_WARNING_STR})
467
    endif()
468
endfunction(disable_msvc_warning)
    (1-1/1)