|
| 1 | +# Copyright Siemens AG, 2014 |
| 2 | +# Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. |
| 3 | +# and Contributors. |
| 4 | +# |
| 5 | +# SPDX-License-Identifier: BSL-1.0 |
| 6 | +# |
| 7 | +# Collection of common functionality for Poco CMake |
| 8 | + |
| 9 | +# Find the Microsoft mc.exe message compiler |
| 10 | +# |
| 11 | +# CMAKE_MC_COMPILER - where to find mc.exe |
| 12 | +if (WIN32) |
| 13 | + # cmake has CMAKE_RC_COMPILER, but no message compiler |
| 14 | + if ("${CMAKE_GENERATOR}" MATCHES "Visual Studio") |
| 15 | + # this path is only present for 2008+, but we currently require PATH to |
| 16 | + # be set up anyway |
| 17 | + get_filename_component(sdk_dir "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Microsoft SDKs\\Windows;CurrentInstallFolder]" REALPATH) |
| 18 | + get_filename_component(kit_dir "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows Kits\\Installed Roots;KitsRoot]" REALPATH) |
| 19 | + if (X64) |
| 20 | + set(sdk_bindir "${sdk_dir}/bin/x64") |
| 21 | + set(kit_bindir "${kit_dir}/bin/x64") |
| 22 | + else (X64) |
| 23 | + set(sdk_bindir "${sdk_dir}/bin") |
| 24 | + set(kit_bindir "${kit_dir}/bin/x86") |
| 25 | + endif (X64) |
| 26 | + endif () |
| 27 | + find_program(CMAKE_MC_COMPILER mc.exe HINTS "${sdk_bindir}" "${kit_bindir}" |
| 28 | + DOC "path to message compiler") |
| 29 | + if (NOT CMAKE_MC_COMPILER) |
| 30 | + message(FATAL_ERROR "message compiler not found: required to build") |
| 31 | + endif (NOT CMAKE_MC_COMPILER) |
| 32 | + message(STATUS "Found message compiler: ${CMAKE_MC_COMPILER}") |
| 33 | + mark_as_advanced(CMAKE_MC_COMPILER) |
| 34 | +endif(WIN32) |
| 35 | + |
| 36 | +#=============================================================================== |
| 37 | +# Macros for Source file management |
| 38 | +# |
| 39 | +# POCO_SOURCES_PLAT - Adds a list of files to the sources of a components |
| 40 | +# Usage: POCO_SOURCES_PLAT( out name platform sources) |
| 41 | +# INPUT: |
| 42 | +# out the variable the sources are added to |
| 43 | +# name: the name of the components |
| 44 | +# platform: the platform this sources are for (ON = All, OFF = None, WIN32, UNIX ...) |
| 45 | +# sources: a list of files to add to ${out} |
| 46 | +# Example: POCO_SOURCES_PLAT( SRCS Foundation ON src/Foundation.cpp ) |
| 47 | +# |
| 48 | +# POCO_SOURCES - Like POCO_SOURCES_PLAT with platform = ON (Built on all platforms) |
| 49 | +# Usage: POCO_SOURCES( out name sources) |
| 50 | +# Example: POCO_SOURCES( SRCS Foundation src/Foundation.cpp) |
| 51 | +# |
| 52 | +# POCO_SOURCES_AUTO - Like POCO_SOURCES but the name is read from the file header // Package: X |
| 53 | +# Usage: POCO_SOURCES_AUTO( out sources) |
| 54 | +# Example: POCO_SOURCES_AUTO( SRCS src/Foundation.cpp) |
| 55 | +# |
| 56 | +# POCO_SOURCES_AUTO_PLAT - Like POCO_SOURCES_PLAT but the name is read from the file header // Package: X |
| 57 | +# Usage: POCO_SOURCES_AUTO_PLAT(out platform sources) |
| 58 | +# Example: POCO_SOURCES_AUTO_PLAT( SRCS WIN32 src/Foundation.cpp) |
| 59 | +# |
| 60 | +# |
| 61 | +# POCO_HEADERS - Adds a list of files to the headers of a components |
| 62 | +# Usage: POCO_HEADERS( out name headers) |
| 63 | +# INPUT: |
| 64 | +# out the variable the headers are added to |
| 65 | +# name: the name of the components |
| 66 | +# headers: a list of files to add to HDRSt |
| 67 | +# Example: POCO_HEADERS( HDRS Foundation include/Poco/Foundation.h ) |
| 68 | +# |
| 69 | +# POCO_HEADERS_AUTO - Like POCO_HEADERS but the name is read from the file header // Package: X |
| 70 | +# Usage: POCO_HEADERS_AUTO( out headers) |
| 71 | +# Example: POCO_HEADERS_AUTO( HDRS src/Foundation.cpp) |
| 72 | +# |
| 73 | +# |
| 74 | +# POCO_MESSAGES - Adds a list of files to the messages of a components |
| 75 | +# and adds the generated headers to the header list of the component. |
| 76 | +# On platforms other then Windows this does nothing |
| 77 | +# Usage: POCO_MESSAGES( out name messages) |
| 78 | +# INPUT: |
| 79 | +# out the variable the message and the resulting headers are added to |
| 80 | +# name: the name of the components |
| 81 | +# messages: a list of files to add to MSGS |
| 82 | +# Example: POCO_MESSAGES( HDRS Foundation include/Poco/Foundation.mc ) |
| 83 | +# |
| 84 | + |
| 85 | + |
| 86 | +macro(POCO_SOURCES_PLAT out name platform) |
| 87 | + source_group("${name}\\Source Files" FILES ${ARGN}) |
| 88 | + list(APPEND ${out} ${ARGN}) |
| 89 | + if(NOT ${platform}) |
| 90 | + set_source_files_properties(${ARGN} PROPERTIES HEADER_FILE_ONLY TRUE) |
| 91 | + endif() |
| 92 | +endmacro() |
| 93 | + |
| 94 | +macro(POCO_SOURCES out name) |
| 95 | + POCO_SOURCES_PLAT( ${out} ${name} ON ${ARGN}) |
| 96 | +endmacro() |
| 97 | + |
| 98 | +macro(POCO_SOURCES_AUTO out) |
| 99 | + POCO_SOURCES_AUTO_PLAT( ${out} ON ${ARGN}) |
| 100 | +endmacro() |
| 101 | + |
| 102 | +macro(POCO_SOURCES_AUTO_PLAT out platform) |
| 103 | + foreach( f ${ARGN}) |
| 104 | + |
| 105 | + get_filename_component(fname ${f} NAME) |
| 106 | + |
| 107 | + # Read the package name from the source file |
| 108 | + file(STRINGS ${f} package REGEX "// Package: (.*)") |
| 109 | + if(package) |
| 110 | + string(REGEX REPLACE ".*: (.*)" "\\1" name ${package}) |
| 111 | + |
| 112 | + # Files of the Form X_UNIX.cpp are treated as headers |
| 113 | + if(${fname} MATCHES ".*_.*\\..*") |
| 114 | + #message(STATUS "Platform: ${name} ${f} ${platform}") |
| 115 | + POCO_SOURCES_PLAT( ${out} ${name} OFF ${f}) |
| 116 | + else() |
| 117 | + #message(STATUS "Source: ${name} ${f} ${platform}") |
| 118 | + POCO_SOURCES_PLAT( ${out} ${name} ${platform} ${f}) |
| 119 | + endif() |
| 120 | + else() |
| 121 | + #message(STATUS "Source: Unknown ${f} ${platform}") |
| 122 | + POCO_SOURCES_PLAT( ${out} Unknown ${platform} ${f}) |
| 123 | + endif() |
| 124 | + endforeach() |
| 125 | +endmacro() |
| 126 | + |
| 127 | + |
| 128 | +macro(POCO_HEADERS_AUTO out) |
| 129 | + foreach( f ${ARGN}) |
| 130 | + |
| 131 | + get_filename_component(fname ${f} NAME) |
| 132 | + |
| 133 | + # Read the package name from the source file |
| 134 | + file(STRINGS ${f} package REGEX "// Package: (.*)") |
| 135 | + if(package) |
| 136 | + string(REGEX REPLACE ".*: (.*)" "\\1" name ${package}) |
| 137 | + #message(STATUS "Header: ${name} ${f}") |
| 138 | + POCO_HEADERS( ${out} ${name} ${f}) |
| 139 | + else() |
| 140 | + #message(STATUS "Header: Unknown ${f}") |
| 141 | + POCO_HEADERS( ${out} Unknown ${f}) |
| 142 | + endif() |
| 143 | + endforeach() |
| 144 | +endmacro() |
| 145 | + |
| 146 | +macro(POCO_HEADERS out name) |
| 147 | + set_source_files_properties(${ARGN} PROPERTIES HEADER_FILE_ONLY TRUE) |
| 148 | + source_group("${name}\\Header Files" FILES ${ARGN}) |
| 149 | + list(APPEND ${out} ${ARGN}) |
| 150 | +endmacro() |
| 151 | + |
| 152 | + |
| 153 | +macro(POCO_MESSAGES out name) |
| 154 | + if (WIN32) |
| 155 | + foreach(msg ${ARGN}) |
| 156 | + get_filename_component(msg_name ${msg} NAME) |
| 157 | + get_filename_component(msg_path ${msg} ABSOLUTE) |
| 158 | + string(REPLACE ".mc" ".h" hdr ${msg_name}) |
| 159 | + set_source_files_properties(${hdr} PROPERTIES GENERATED TRUE) |
| 160 | + add_custom_command( |
| 161 | + OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${hdr} |
| 162 | + DEPENDS ${msg} |
| 163 | + COMMAND ${CMAKE_MC_COMPILER} |
| 164 | + ARGS |
| 165 | + -h ${CMAKE_CURRENT_BINARY_DIR} |
| 166 | + -r ${CMAKE_CURRENT_BINARY_DIR} |
| 167 | + ${msg_path} |
| 168 | + VERBATIM # recommended: p260 |
| 169 | + ) |
| 170 | + |
| 171 | + # Add the generated file to the include directory |
| 172 | + include_directories(${CMAKE_CURRENT_BINARY_DIR}) |
| 173 | + |
| 174 | + # Add the generated headers to POCO_HEADERS of the component |
| 175 | + POCO_HEADERS( ${out} ${name} ${CMAKE_CURRENT_BINARY_DIR}/${hdr}) |
| 176 | + |
| 177 | + endforeach() |
| 178 | + |
| 179 | + set_source_files_properties(${ARGN} PROPERTIES HEADER_FILE_ONLY TRUE) |
| 180 | + source_group("${name}\\Message Files" FILES ${ARGN}) |
| 181 | + list(APPEND ${out} ${ARGN}) |
| 182 | + |
| 183 | + endif (WIN32) |
| 184 | +endmacro() |
0 commit comments