1# Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved. 2# 3# This program is free software; you can redistribute it and/or modify 4# it under the terms of the GNU General Public License as published by 5# the Free Software Foundation; version 2 of the License. 6# 7# This program is distributed in the hope that it will be useful, 8# but WITHOUT ANY WARRANTY; without even the implied warranty of 9# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10# GNU General Public License for more details. 11# 12# You should have received a copy of the GNU General Public License 13# along with this program; if not, write to the Free Software 14# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1335 USA 15 16# Add executable plus some additional MySQL specific stuff 17# Usage (same as for standard CMake's ADD_EXECUTABLE) 18# 19# MYSQL_ADD_EXECUTABLE(target source1...sourceN) 20# 21# MySQL specifics: 22# - instruct CPack to install executable under ${CMAKE_INSTALL_PREFIX}/bin directory 23# On Windows : 24# - add version resource 25# - instruct CPack to do autenticode signing if SIGNCODE is set 26 27INCLUDE(CMakeParseArguments) 28 29FUNCTION (MYSQL_ADD_EXECUTABLE) 30 # Pass-through arguments for ADD_EXECUTABLE 31 CMAKE_PARSE_ARGUMENTS(ARG 32 "WIN32;MACOSX_BUNDLE;EXCLUDE_FROM_ALL" 33 "DESTINATION;COMPONENT" 34 "" 35 ${ARGN} 36 ) 37 LIST(GET ARG_UNPARSED_ARGUMENTS 0 target) 38 LIST(REMOVE_AT ARG_UNPARSED_ARGUMENTS 0) 39 40 SET(sources ${ARG_UNPARSED_ARGUMENTS}) 41 ADD_VERSION_INFO(${target} EXECUTABLE sources) 42 43 IF(MSVC) 44 # Add compatibility manifest, to fix GetVersionEx on Windows 8.1 and later 45 IF (CMAKE_VERSION VERSION_GREATER 3.3) 46 SET(sources ${sources} ${PROJECT_SOURCE_DIR}/cmake/win_compatibility.manifest) 47 ENDIF() 48 ENDIF() 49 50 IF (ARG_WIN32) 51 SET(WIN32 WIN32) 52 ELSE() 53 UNSET(WIN32) 54 ENDIF() 55 IF (ARG_MACOSX_BUNDLE) 56 SET(MACOSX_BUNDLE MACOSX_BUNDLE) 57 ELSE() 58 UNSET(MACOSX_BUNDLE) 59 ENDIF() 60 IF (ARG_EXCLUDE_FROM_ALL) 61 SET(EXCLUDE_FROM_ALL EXCLUDE_FROM_ALL) 62 ELSE() 63 UNSET(EXCLUDE_FROM_ALL) 64 ENDIF() 65 66 ADD_EXECUTABLE(${target} ${WIN32} ${MACOSX_BUNDLE} ${EXCLUDE_FROM_ALL} ${sources}) 67 68 # tell CPack where to install 69 IF(NOT ARG_EXCLUDE_FROM_ALL) 70 IF(NOT ARG_DESTINATION) 71 SET(ARG_DESTINATION ${INSTALL_BINDIR}) 72 ENDIF() 73 IF(ARG_COMPONENT) 74 SET(COMP ${ARG_COMPONENT}) 75 ELSEIF(MYSQL_INSTALL_COMPONENT) 76 SET(COMP ${MYSQL_INSTALL_COMPONENT}) 77 ELSE() 78 SET(COMP Client) 79 ENDIF() 80 IF (COMP MATCHES ${SKIP_COMPONENTS}) 81 RETURN() 82 ENDIF() 83 84 IF (WITH_STRIPPED_CLIENT AND NOT target STREQUAL mariadbd) 85 INSTALL(CODE "SET(CMAKE_INSTALL_DO_STRIP 1)" COMPONENT ${COMP}) 86 SET(reset_strip ON) 87 ENDIF() 88 89 MYSQL_INSTALL_TARGETS(${target} DESTINATION ${ARG_DESTINATION} COMPONENT ${COMP}) 90 91 IF (reset_strip) 92 INSTALL(CODE "SET(CMAKE_INSTALL_DO_STRIP 0)" COMPONENT ${COMP}) 93 ENDIF() 94 ENDIF() 95 96 # create MySQL named "legacy links" 97 GET_SYMLINK(${target} link) 98 IF(link) 99 IF(UNIX) 100 ADD_CUSTOM_COMMAND(TARGET ${target} POST_BUILD 101 COMMAND ${CMAKE_COMMAND} -E create_symlink 102 ${target} ${link} 103 COMMENT "Creating ${link} link" 104 WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}) 105 INSTALL(PROGRAMS 106 ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}/${link} 107 DESTINATION 108 ${ARG_DESTINATION} 109 COMPONENT ${COMP}) 110 ELSE() 111 # Windows note: 112 # Here, hardlinks are used, because cmake can't install symlinks. 113 # In packages, there are won't be links, just copies. 114 SET(link ${link}.exe) 115 ADD_CUSTOM_COMMAND(TARGET ${target} POST_BUILD 116 COMMAND cmake -E remove -f ${link} 117 COMMAND mklink /H ${link} $<TARGET_FILE_NAME:${target}> 118 COMMENT "Creating ${link} link" 119 WORKING_DIRECTORY $<TARGET_FILE_DIR:${target}>) 120 INSTALL(PROGRAMS $<TARGET_FILE_DIR:${target}>/${link} DESTINATION ${ARG_DESTINATION} COMPONENT ${COMP}) 121 ENDIF() 122 ENDIF() 123ENDFUNCTION() 124