comparison Resources/Orthanc/CMake/AutoGeneratedCode.cmake @ 36:fd58eb5749ed

CMake simplification using DownloadOrthancFramework.cmake
author Sebastien Jodogne <s.jodogne@gmail.com>
date Mon, 06 Jul 2020 17:37:30 +0200
parents
children 1b6af7a317bf
comparison
equal deleted inserted replaced
35:77f4e165e535 36:fd58eb5749ed
1 set(EMBED_RESOURCES_PYTHON "${CMAKE_CURRENT_LIST_DIR}/../EmbedResources.py"
2 CACHE INTERNAL "Path to the EmbedResources.py script from Orthanc")
3 set(AUTOGENERATED_DIR "${CMAKE_CURRENT_BINARY_DIR}/AUTOGENERATED")
4 set(AUTOGENERATED_SOURCES)
5
6 file(MAKE_DIRECTORY ${AUTOGENERATED_DIR})
7 include_directories(${AUTOGENERATED_DIR})
8
9 macro(EmbedResources)
10 # Convert a semicolon separated list to a whitespace separated string
11 set(SCRIPT_OPTIONS)
12 set(SCRIPT_ARGUMENTS)
13 set(DEPENDENCIES)
14 set(IS_PATH_NAME false)
15
16 set(TARGET_BASE "${AUTOGENERATED_DIR}/EmbeddedResources")
17
18 # Loop over the arguments of the function
19 foreach(arg ${ARGN})
20 # Extract the first character of the argument
21 string(SUBSTRING "${arg}" 0 1 FIRST_CHAR)
22 if (${FIRST_CHAR} STREQUAL "-")
23 # If the argument starts with a dash "-", this is an option to
24 # EmbedResources.py
25 if (${arg} MATCHES "--target=.*")
26 # Does the argument starts with "--target="?
27 string(SUBSTRING "${arg}" 9 -1 TARGET) # 9 is the length of "--target="
28 set(TARGET_BASE "${AUTOGENERATED_DIR}/${TARGET}")
29 else()
30 list(APPEND SCRIPT_OPTIONS ${arg})
31 endif()
32 else()
33 if (${IS_PATH_NAME})
34 list(APPEND SCRIPT_ARGUMENTS "${arg}")
35 list(APPEND DEPENDENCIES "${arg}")
36 set(IS_PATH_NAME false)
37 else()
38 list(APPEND SCRIPT_ARGUMENTS "${arg}")
39 set(IS_PATH_NAME true)
40 endif()
41 endif()
42 endforeach()
43
44 add_custom_command(
45 OUTPUT
46 "${TARGET_BASE}.h"
47 "${TARGET_BASE}.cpp"
48 COMMAND ${PYTHON_EXECUTABLE} ${EMBED_RESOURCES_PYTHON}
49 ${SCRIPT_OPTIONS} "${TARGET_BASE}" ${SCRIPT_ARGUMENTS}
50 DEPENDS
51 ${EMBED_RESOURCES_PYTHON}
52 ${DEPENDENCIES}
53 )
54
55 list(APPEND AUTOGENERATED_SOURCES
56 "${TARGET_BASE}.cpp"
57 )
58 endmacro()