summaryrefslogtreecommitdiff
path: root/cmake/make_dist.cmake.in
blob: 1b347e418360824ccc83cbc31735a7a118c8a6a4 (plain)
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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
# Copyright (c) 2009, 2011, Oracle and/or its affiliates. All rights reserved.
# 
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 2 of the License.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA 

# Make source distribution
# If bzr is present, run bzr export.
# Otherwise, just run cpack with source configuration.

SET(CMAKE_SOURCE_DIR "@CMAKE_SOURCE_DIR@")
SET(CMAKE_BINARY_DIR "@CMAKE_BINARY_DIR@")
SET(CPACK_SOURCE_PACKAGE_FILE_NAME "@CPACK_SOURCE_PACKAGE_FILE_NAME@")
SET(CMAKE_CPACK_COMMAND  "@CMAKE_CPACK_COMMAND@")
SET(CMAKE_COMMAND  "@CMAKE_COMMAND@")
SET(BZR_EXECUTABLE "@BZR_EXECUTABLE@")
SET(GTAR_EXECUTABLE "@GTAR_EXECUTABLE@")
SET(TAR_EXECUTABLE "@TAR_EXECUTABLE@")
SET(CMAKE_GENERATOR "@CMAKE_GENERATOR@")
SET(CMAKE_MAKE_PROGRAM "@CMAKE_MAKE_PROGRAM@")
SET(CMAKE_SYSTEM_NAME "@CMAKE_SYSTEM_NAME@")
SET(PLUGIN_REPOS "@PLUGIN_REPOS@")

SET(VERSION "@VERSION@")

SET(MYSQL_DOCS_LOCATION "@MYSQL_DOCS_LOCATION@")


SET(PACKAGE_DIR  ${CMAKE_BINARY_DIR}/${CPACK_SOURCE_PACKAGE_FILE_NAME})

FILE(REMOVE_RECURSE ${PACKAGE_DIR})
FILE(REMOVE ${PACKAGE_DIR}.tar.gz )

IF(BZR_EXECUTABLE)
  MESSAGE(STATUS "Running bzr export")
  EXECUTE_PROCESS(
    COMMAND "${BZR_EXECUTABLE}" export 
    ${PACKAGE_DIR}
    WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
    RESULT_VARIABLE RESULT
  )

  IF(NOT RESULT EQUAL 0)
   SET(BZR_EXECUTABLE)
  ENDIF()
ENDIF()

IF(BZR_EXECUTABLE)
  FOREACH(REPO ${PLUGIN_REPOS})
    GET_FILENAME_COMPONENT(PLUGIN_NAME ${REPO} NAME)
    SET(DEST ${PACKAGE_DIR}/plugin/${PLUGIN_NAME})
    MESSAGE(STATUS "Running bzr export for plugin/${PLUGIN_NAME}")
    EXECUTE_PROCESS(
      COMMAND "${BZR_EXECUTABLE}" export ${DEST}
      WORKING_DIRECTORY ${REPO}
      RESULT_VARIABLE RESULT
    )
    IF(NOT RESULT EQUAL 0)
      MESSAGE(STATUS "bzr export failed")
    ENDIF()
  ENDFOREACH()
ENDIF()

IF(NOT BZR_EXECUTABLE)
  MESSAGE(STATUS "bzr not found or source dir is not a repo, use CPack")
  
  IF(CMAKE_SOURCE_DIR STREQUAL CMAKE_BINARY_DIR)
    # In-source build is the worst option, we have to cleanup source tree.

    # Save bison output first.
    CONFIGURE_FILE(${CMAKE_BINARY_DIR}/sql/sql_yacc.cc
       ${CMAKE_BINARY_DIR}/sql_yacc.cc COPY_ONLY)
    CONFIGURE_FILE(${CMAKE_BINARY_DIR}/sql/sql_yacc.h 
       ${CMAKE_BINARY_DIR}/sql_yacc.h COPY_ONLY)

    IF(CMAKE_GENERATOR MATCHES "Makefiles")
    # make clean
    EXECUTE_PROCESS(
      COMMAND ${CMAKE_MAKE_PROGRAM} clean 
      WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
    )
    ENDIF()
    
    # Restore bison output
    CONFIGURE_FILE(${CMAKE_BINARY_DIR}/sql_yacc.cc
       ${CMAKE_BINARY_DIR}/sql/sql_yacc.cc COPY_ONLY)
    CONFIGURE_FILE(${CMAKE_BINARY_DIR}/sql_yacc.h 
       ${CMAKE_BINARY_DIR}/sql/sql_yacc.h COPY_ONLY)
    FILE(REMOVE ${CMAKE_BINARY_DIR}/sql_yacc.cc)
    FILE(REMOVE ${CMAKE_BINARY_DIR}/sql_yacc.h)
  ENDIF()

  EXECUTE_PROCESS(
    COMMAND ${CMAKE_CPACK_COMMAND} -G TGZ --config ./CPackSourceConfig.cmake 
    ${CMAKE_BINARY_DIR}/CPackSourceConfig.cmake

    WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
  )
  EXECUTE_PROCESS(
  COMMAND ${CMAKE_COMMAND} -E tar xzf 
    ${CPACK_SOURCE_PACKAGE_FILE_NAME}.tar.gz 
    ${PACK_SOURCE_PACKAGE_FILE_NAME} 
    WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
  )
ENDIF()

# Copy bison output
CONFIGURE_FILE(${CMAKE_BINARY_DIR}/sql/sql_yacc.h 
   ${PACKAGE_DIR}/sql/sql_yacc.h COPYONLY)
CONFIGURE_FILE(${CMAKE_BINARY_DIR}/sql/sql_yacc.cc
   ${PACKAGE_DIR}/sql/sql_yacc.cc COPYONLY)

# Copy spec files
SET(SPECFILENAME "mysql.${VERSION}.spec")
IF("${VERSION}" MATCHES "-ndb-")
  STRING(REGEX REPLACE "^.*-ndb-" "" NDBVERSION "${VERSION}")
  SET(SPECFILENAME "mysql-cluster-${NDBVERSION}.spec")
ENDIF()
CONFIGURE_FILE(${CMAKE_BINARY_DIR}/support-files/${SPECFILENAME}
   ${PACKAGE_DIR}/support-files/${SPECFILENAME} COPYONLY)

# Add documentation, if user has specified where to find them
IF(MYSQL_DOCS_LOCATION)
  MESSAGE("Copying documentation files from " ${MYSQL_DOCS_LOCATION})
  EXECUTE_PROCESS(COMMAND ${CMAKE_COMMAND} -E copy_directory "${MYSQL_DOCS_LOCATION}" "${PACKAGE_DIR}")
ENDIF()

# Ensure there is an "INFO_SRC" file.
INCLUDE(${CMAKE_BINARY_DIR}/info_macros.cmake)
IF(NOT EXISTS ${PACKAGE_DIR}/Docs/INFO_SRC)
  CREATE_INFO_SRC(${PACKAGE_DIR}/Docs)
ENDIF()

# In case we used CPack, it could have copied some
# extra files that are not usable on different machines.
FILE(REMOVE ${PACKAGE_DIR}/CMakeCache.txt)

# When packing source, prefer gnu tar  to "cmake -P tar"
# cmake does not preserve timestamps.gnuwin32 tar is broken, cygwin is ok

IF(CMAKE_SYSTEM_NAME MATCHES "Windows")
  IF (EXISTS C:/cygwin/bin/tar.exe)
    SET(TAR_EXECUTABLE C:/cygwin/bin/tar.exe)
  ENDIF()
ENDIF()

IF(GTAR_EXECUTABLE)
  SET(GNUTAR ${GTAR_EXECUTABLE})
ELSEIF(TAR_EXECUTABLE)
  EXECUTE_PROCESS(
    COMMAND "${TAR_EXECUTABLE}" --version
    RESULT_VARIABLE RESULT OUTPUT_VARIABLE OUT ERROR_VARIABLE ERR
  )
  IF(RESULT EQUAL 0 AND OUT MATCHES "GNU")
    SET(GNUTAR ${TAR_EXECUTABLE})
  ENDIF()
ENDIF()

SET($ENV{GZIP} "--best")

IF(GNUTAR)
  SET(PACK_COMMAND 
  ${GNUTAR} cfz 
  ${CPACK_SOURCE_PACKAGE_FILE_NAME}.tar.gz 
  ${CPACK_SOURCE_PACKAGE_FILE_NAME}
  )
ELSE()
  SET(PACK_COMMAND ${CMAKE_COMMAND} -E tar cfz
  ${CPACK_SOURCE_PACKAGE_FILE_NAME}.tar.gz 
  ${CPACK_SOURCE_PACKAGE_FILE_NAME}
)
ENDIF()

MESSAGE(STATUS "Creating source package")

EXECUTE_PROCESS( 
  COMMAND ${PACK_COMMAND}
)
MESSAGE(STATUS "Source package ${PACKAGE_DIR}.tar.gz created")