| 1 |
# LuaDist CMake utility library. |
| 2 |
# Provides sane project defaults and macros common to LuaDist CMake builds. |
| 3 |
# |
| 4 |
# Copyright (C) 2007-2012 LuaDist. |
| 5 |
# by David Manura, Peter Drahoš |
| 6 |
# Redistribution and use of this file is allowed according to the terms of the MIT license. |
| 7 |
# For details see the COPYRIGHT file distributed with LuaDist. |
| 8 |
# Please note that the package source code is licensed under its own license. |
| 9 |
|
| 10 |
## Extract information from dist.info |
| 11 |
if ( NOT EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/dist.info ) |
| 12 |
message ( FATAL_ERROR |
| 13 |
"Missing dist.info file (${CMAKE_CURRENT_SOURCE_DIR}/dist.info)." ) |
| 14 |
endif () |
| 15 |
file ( READ ${CMAKE_CURRENT_SOURCE_DIR}/dist.info DIST_INFO ) |
| 16 |
if ( "${DIST_INFO}" STREQUAL "" ) |
| 17 |
message ( FATAL_ERROR "Failed to load dist.info." ) |
| 18 |
endif () |
| 19 |
# Reads field `name` from dist.info string `DIST_INFO` into variable `var`. |
| 20 |
macro ( _parse_dist_field name var ) |
| 21 |
string ( REGEX REPLACE ".*${name}[ \t]?=[ \t]?[\"']([^\"']+)[\"'].*" "\\1" |
| 22 |
${var} "${DIST_INFO}" ) |
| 23 |
if ( ${var} STREQUAL DIST_INFO ) |
| 24 |
message ( FATAL_ERROR "Failed to extract \"${var}\" from dist.info" ) |
| 25 |
endif () |
| 26 |
endmacro () |
| 27 |
# |
| 28 |
_parse_dist_field ( name DIST_NAME ) |
| 29 |
_parse_dist_field ( version DIST_VERSION ) |
| 30 |
_parse_dist_field ( license DIST_LICENSE ) |
| 31 |
_parse_dist_field ( author DIST_AUTHOR ) |
| 32 |
_parse_dist_field ( maintainer DIST_MAINTAINER ) |
| 33 |
_parse_dist_field ( url DIST_URL ) |
| 34 |
_parse_dist_field ( desc DIST_DESC ) |
| 35 |
message ( "DIST_NAME: ${DIST_NAME}") |
| 36 |
message ( "DIST_VERSION: ${DIST_VERSION}") |
| 37 |
message ( "DIST_LICENSE: ${DIST_LICENSE}") |
| 38 |
message ( "DIST_AUTHOR: ${DIST_AUTHOR}") |
| 39 |
message ( "DIST_MAINTAINER: ${DIST_MAINTAINER}") |
| 40 |
message ( "DIST_URL: ${DIST_URL}") |
| 41 |
message ( "DIST_DESC: ${DIST_DESC}") |
| 42 |
string ( REGEX REPLACE ".*depends[ \t]?=[ \t]?[\"']([^\"']+)[\"'].*" "\\1" |
| 43 |
DIST_DEPENDS ${DIST_INFO} ) |
| 44 |
if ( DIST_DEPENDS STREQUAL DIST_INFO ) |
| 45 |
set ( DIST_DEPENDS "" ) |
| 46 |
endif () |
| 47 |
message ( "DIST_DEPENDS: ${DIST_DEPENDS}") |
| 48 |
## 2DO: Parse DIST_DEPENDS and try to install Dependencies with automatically using externalproject_add |
| 49 |
|
| 50 |
|
| 51 |
## INSTALL DEFAULTS (Relative to CMAKE_INSTALL_PREFIX) |
| 52 |
# Primary paths |
| 53 |
set ( INSTALL_BIN bin CACHE PATH "Where to install binaries to." ) |
| 54 |
set ( INSTALL_LIB lib CACHE PATH "Where to install libraries to." ) |
| 55 |
set ( INSTALL_INC include CACHE PATH "Where to install headers to." ) |
| 56 |
set ( INSTALL_ETC etc CACHE PATH "Where to store configuration files" ) |
| 57 |
set ( INSTALL_SHARE share CACHE PATH "Directory for shared data." ) |
| 58 |
|
| 59 |
# Secondary paths |
| 60 |
option ( INSTALL_VERSION |
| 61 |
"Install runtime libraries and executables with version information." OFF) |
| 62 |
set ( INSTALL_DATA ${INSTALL_SHARE}/${DIST_NAME} CACHE PATH |
| 63 |
"Directory the package can store documentation, tests or other data in.") |
| 64 |
set ( INSTALL_DOC ${INSTALL_DATA}/doc CACHE PATH |
| 65 |
"Recommended directory to install documentation into.") |
| 66 |
set ( INSTALL_EXAMPLE ${INSTALL_DATA}/example CACHE PATH |
| 67 |
"Recommended directory to install examples into.") |
| 68 |
set ( INSTALL_TEST ${INSTALL_DATA}/test CACHE PATH |
| 69 |
"Recommended directory to install tests into.") |
| 70 |
set ( INSTALL_FOO ${INSTALL_DATA}/etc CACHE PATH |
| 71 |
"Where to install additional files") |
| 72 |
|
| 73 |
# Tweaks and other defaults |
| 74 |
# Setting CMAKE to use loose block and search for find modules in source directory |
| 75 |
set ( CMAKE_ALLOW_LOOSE_LOOP_CONSTRUCTS true ) |
| 76 |
set ( CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake" ${CMAKE_MODULE_PATH} ) |
| 77 |
option ( BUILD_SHARED_LIBS "Build shared libraries" ON ) |
| 78 |
|
| 79 |
# In MSVC, prevent warnings that can occur when using standard libraries. |
| 80 |
if ( MSVC ) |
| 81 |
add_definitions ( -D_CRT_SECURE_NO_WARNINGS ) |
| 82 |
endif () |
| 83 |
|
| 84 |
## MACROS |
| 85 |
# Parser macro |
| 86 |
macro ( parse_arguments prefix arg_names option_names) |
| 87 |
set ( DEFAULT_ARGS ) |
| 88 |
foreach ( arg_name ${arg_names} ) |
| 89 |
set ( ${prefix}_${arg_name} ) |
| 90 |
endforeach () |
| 91 |
foreach ( option ${option_names} ) |
| 92 |
set ( ${prefix}_${option} FALSE ) |
| 93 |
endforeach () |
| 94 |
|
| 95 |
set ( current_arg_name DEFAULT_ARGS ) |
| 96 |
set ( current_arg_list ) |
| 97 |
foreach ( arg ${ARGN} ) |
| 98 |
set ( larg_names ${arg_names} ) |
| 99 |
list ( FIND larg_names "${arg}" is_arg_name ) |
| 100 |
if ( is_arg_name GREATER -1 ) |
| 101 |
set ( ${prefix}_${current_arg_name} ${current_arg_list} ) |
| 102 |
set ( current_arg_name ${arg} ) |
| 103 |
set ( current_arg_list ) |
| 104 |
else () |
| 105 |
set ( loption_names ${option_names} ) |
| 106 |
list ( FIND loption_names "${arg}" is_option ) |
| 107 |
if ( is_option GREATER -1 ) |
| 108 |
set ( ${prefix}_${arg} TRUE ) |
| 109 |
else () |
| 110 |
set ( current_arg_list ${current_arg_list} ${arg} ) |
| 111 |
endif () |
| 112 |
endif () |
| 113 |
endforeach () |
| 114 |
set ( ${prefix}_${current_arg_name} ${current_arg_list} ) |
| 115 |
endmacro () |
| 116 |
|
| 117 |
|
| 118 |
# install_executable ( executable_targets ) |
| 119 |
# Installs any executables generated using "add_executable". |
| 120 |
# USE: install_executable ( lua ) |
| 121 |
# NOTE: subdirectories are NOT supported |
| 122 |
set ( CPACK_COMPONENT_RUNTIME_DISPLAY_NAME "${DIST_NAME} Runtime" ) |
| 123 |
set ( CPACK_COMPONENT_RUNTIME_DESCRIPTION |
| 124 |
"Executables and runtime libraries. Installed into ${INSTALL_BIN}." ) |
| 125 |
macro ( install_executable ) |
| 126 |
foreach ( _file ${ARGN} ) |
| 127 |
if ( INSTALL_VERSION ) |
| 128 |
set_target_properties ( ${_file} PROPERTIES VERSION ${DIST_VERSION} |
| 129 |
SOVERSION ${DIST_VERSION} ) |
| 130 |
endif () |
| 131 |
install ( TARGETS ${_file} RUNTIME DESTINATION ${INSTALL_BIN} |
| 132 |
COMPONENT Runtime ) |
| 133 |
endforeach() |
| 134 |
endmacro () |
| 135 |
|
| 136 |
# install_library ( library_targets ) |
| 137 |
# Installs any libraries generated using "add_library" into apropriate places. |
| 138 |
# USE: install_library ( libexpat ) |
| 139 |
# NOTE: subdirectories are NOT supported |
| 140 |
set ( CPACK_COMPONENT_LIBRARY_DISPLAY_NAME "${DIST_NAME} Development Libraries" ) |
| 141 |
set ( CPACK_COMPONENT_LIBRARY_DESCRIPTION |
| 142 |
"Static and import libraries needed for development. Installed into ${INSTALL_LIB} or ${INSTALL_BIN}." ) |
| 143 |
macro ( install_library ) |
| 144 |
foreach ( _file ${ARGN} ) |
| 145 |
if ( INSTALL_VERSION ) |
| 146 |
set_target_properties ( ${_file} PROPERTIES VERSION ${DIST_VERSION} |
| 147 |
SOVERSION ${DIST_VERSION} ) |
| 148 |
endif () |
| 149 |
install ( TARGETS ${_file} |
| 150 |
RUNTIME DESTINATION ${INSTALL_BIN} COMPONENT Runtime |
| 151 |
LIBRARY DESTINATION ${INSTALL_LIB} COMPONENT Runtime |
| 152 |
ARCHIVE DESTINATION ${INSTALL_LIB} COMPONENT Library ) |
| 153 |
endforeach() |
| 154 |
endmacro () |
| 155 |
|
| 156 |
# helper function for various install_* functions, for PATTERN/REGEX args. |
| 157 |
macro ( _complete_install_args ) |
| 158 |
if ( NOT("${_ARG_PATTERN}" STREQUAL "") ) |
| 159 |
set ( _ARG_PATTERN PATTERN ${_ARG_PATTERN} ) |
| 160 |
endif () |
| 161 |
if ( NOT("${_ARG_REGEX}" STREQUAL "") ) |
| 162 |
set ( _ARG_REGEX REGEX ${_ARG_REGEX} ) |
| 163 |
endif () |
| 164 |
endmacro () |
| 165 |
|
| 166 |
# install_header ( files/directories [INTO destination] ) |
| 167 |
# Install a directories or files into header destination. |
| 168 |
# USE: install_header ( lua.h luaconf.h ) or install_header ( GL ) |
| 169 |
# USE: install_header ( mylib.h INTO mylib ) |
| 170 |
# For directories, supports optional PATTERN/REGEX arguments like install(). |
| 171 |
set ( CPACK_COMPONENT_HEADER_DISPLAY_NAME "${DIST_NAME} Development Headers" ) |
| 172 |
set ( CPACK_COMPONENT_HEADER_DESCRIPTION |
| 173 |
"Headers needed for development. Installed into ${INSTALL_INC}." ) |
| 174 |
macro ( install_header ) |
| 175 |
parse_arguments ( _ARG "INTO;PATTERN;REGEX" "" ${ARGN} ) |
| 176 |
_complete_install_args() |
| 177 |
foreach ( _file ${_ARG_DEFAULT_ARGS} ) |
| 178 |
if ( IS_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/${_file}" ) |
| 179 |
install ( DIRECTORY ${_file} DESTINATION ${INSTALL_INC}/${_ARG_INTO} |
| 180 |
COMPONENT Header ${_ARG_PATTERN} ${_ARG_REGEX} ) |
| 181 |
else () |
| 182 |
install ( FILES ${_file} DESTINATION ${INSTALL_INC}/${_ARG_INTO} |
| 183 |
COMPONENT Header ) |
| 184 |
endif () |
| 185 |
endforeach() |
| 186 |
endmacro () |
| 187 |
|
| 188 |
# install_data ( files/directories [INTO destination] ) |
| 189 |
# This installs additional data files or directories. |
| 190 |
# USE: install_data ( extra data.dat ) |
| 191 |
# USE: install_data ( image1.png image2.png INTO images ) |
| 192 |
# For directories, supports optional PATTERN/REGEX arguments like install(). |
| 193 |
set ( CPACK_COMPONENT_DATA_DISPLAY_NAME "${DIST_NAME} Data" ) |
| 194 |
set ( CPACK_COMPONENT_DATA_DESCRIPTION |
| 195 |
"Application data. Installed into ${INSTALL_DATA}." ) |
| 196 |
macro ( install_data ) |
| 197 |
parse_arguments ( _ARG "INTO;PATTERN;REGEX" "" ${ARGN} ) |
| 198 |
_complete_install_args() |
| 199 |
foreach ( _file ${_ARG_DEFAULT_ARGS} ) |
| 200 |
if ( IS_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/${_file}" ) |
| 201 |
install ( DIRECTORY ${_file} |
| 202 |
DESTINATION ${INSTALL_DATA}/${_ARG_INTO} |
| 203 |
COMPONENT Data ${_ARG_PATTERN} ${_ARG_REGEX} ) |
| 204 |
else () |
| 205 |
install ( FILES ${_file} DESTINATION ${INSTALL_DATA}/${_ARG_INTO} |
| 206 |
COMPONENT Data ) |
| 207 |
endif () |
| 208 |
endforeach() |
| 209 |
endmacro () |
| 210 |
|
| 211 |
# INSTALL_DOC ( files/directories [INTO destination] ) |
| 212 |
# This installs documentation content |
| 213 |
# USE: install_doc ( doc/ doc.pdf ) |
| 214 |
# USE: install_doc ( index.html INTO html ) |
| 215 |
# For directories, supports optional PATTERN/REGEX arguments like install(). |
| 216 |
set ( CPACK_COMPONENT_DOCUMENTATION_DISPLAY_NAME "${DIST_NAME} Documentation" ) |
| 217 |
set ( CPACK_COMPONENT_DOCUMENTATION_DESCRIPTION |
| 218 |
"Application documentation. Installed into ${INSTALL_DOC}." ) |
| 219 |
macro ( install_doc ) |
| 220 |
parse_arguments ( _ARG "INTO;PATTERN;REGEX" "" ${ARGN} ) |
| 221 |
_complete_install_args() |
| 222 |
foreach ( _file ${_ARG_DEFAULT_ARGS} ) |
| 223 |
if ( IS_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/${_file}" ) |
| 224 |
install ( DIRECTORY ${_file} DESTINATION ${INSTALL_DOC}/${_ARG_INTO} |
| 225 |
COMPONENT Documentation ${_ARG_PATTERN} ${_ARG_REGEX} ) |
| 226 |
else () |
| 227 |
install ( FILES ${_file} DESTINATION ${INSTALL_DOC}/${_ARG_INTO} |
| 228 |
COMPONENT Documentation ) |
| 229 |
endif () |
| 230 |
endforeach() |
| 231 |
endmacro () |
| 232 |
|
| 233 |
# install_example ( files/directories [INTO destination] ) |
| 234 |
# This installs additional examples |
| 235 |
# USE: install_example ( examples/ exampleA ) |
| 236 |
# USE: install_example ( super_example super_data INTO super) |
| 237 |
# For directories, supports optional PATTERN/REGEX argument like install(). |
| 238 |
set ( CPACK_COMPONENT_EXAMPLE_DISPLAY_NAME "${DIST_NAME} Examples" ) |
| 239 |
set ( CPACK_COMPONENT_EXAMPLE_DESCRIPTION |
| 240 |
"Examples and their associated data. Installed into ${INSTALL_EXAMPLE}." ) |
| 241 |
macro ( install_example ) |
| 242 |
parse_arguments ( _ARG "INTO;PATTERN;REGEX" "" ${ARGN} ) |
| 243 |
_complete_install_args() |
| 244 |
foreach ( _file ${_ARG_DEFAULT_ARGS} ) |
| 245 |
if ( IS_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/${_file}" ) |
| 246 |
install ( DIRECTORY ${_file} DESTINATION ${INSTALL_EXAMPLE}/${_ARG_INTO} |
| 247 |
COMPONENT Example ${_ARG_PATTERN} ${_ARG_REGEX} ) |
| 248 |
else () |
| 249 |
install ( FILES ${_file} DESTINATION ${INSTALL_EXAMPLE}/${_ARG_INTO} |
| 250 |
COMPONENT Example ) |
| 251 |
endif () |
| 252 |
endforeach() |
| 253 |
endmacro () |
| 254 |
|
| 255 |
# install_test ( files/directories [INTO destination] ) |
| 256 |
# This installs tests and test files, DOES NOT EXECUTE TESTS |
| 257 |
# USE: install_test ( my_test data.sql ) |
| 258 |
# USE: install_test ( feature_x_test INTO x ) |
| 259 |
# For directories, supports optional PATTERN/REGEX argument like install(). |
| 260 |
set ( CPACK_COMPONENT_TEST_DISPLAY_NAME "${DIST_NAME} Tests" ) |
| 261 |
set ( CPACK_COMPONENT_TEST_DESCRIPTION |
| 262 |
"Tests and associated data. Installed into ${INSTALL_TEST}." ) |
| 263 |
macro ( install_test ) |
| 264 |
parse_arguments ( _ARG "INTO;PATTERN;REGEX" "" ${ARGN} ) |
| 265 |
_complete_install_args() |
| 266 |
foreach ( _file ${_ARG_DEFAULT_ARGS} ) |
| 267 |
if ( IS_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/${_file}" ) |
| 268 |
install ( DIRECTORY ${_file} DESTINATION ${INSTALL_TEST}/${_ARG_INTO} |
| 269 |
COMPONENT Test ${_ARG_PATTERN} ${_ARG_REGEX} ) |
| 270 |
else () |
| 271 |
install ( FILES ${_file} DESTINATION ${INSTALL_TEST}/${_ARG_INTO} |
| 272 |
COMPONENT Test ) |
| 273 |
endif () |
| 274 |
endforeach() |
| 275 |
endmacro () |
| 276 |
|
| 277 |
# install_foo ( files/directories [INTO destination] ) |
| 278 |
# This installs optional or otherwise unneeded content |
| 279 |
# USE: install_foo ( etc/ example.doc ) |
| 280 |
# USE: install_foo ( icon.png logo.png INTO icons) |
| 281 |
# For directories, supports optional PATTERN/REGEX argument like install(). |
| 282 |
set ( CPACK_COMPONENT_OTHER_DISPLAY_NAME "${DIST_NAME} Unspecified Content" ) |
| 283 |
set ( CPACK_COMPONENT_OTHER_DESCRIPTION |
| 284 |
"Other unspecified content. Installed into ${INSTALL_FOO}." ) |
| 285 |
macro ( install_foo ) |
| 286 |
parse_arguments ( _ARG "INTO;PATTERN;REGEX" "" ${ARGN} ) |
| 287 |
_complete_install_args() |
| 288 |
foreach ( _file ${_ARG_DEFAULT_ARGS} ) |
| 289 |
if ( IS_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/${_file}" ) |
| 290 |
install ( DIRECTORY ${_file} DESTINATION ${INSTALL_FOO}/${_ARG_INTO} |
| 291 |
COMPONENT Other ${_ARG_PATTERN} ${_ARG_REGEX} ) |
| 292 |
else () |
| 293 |
install ( FILES ${_file} DESTINATION ${INSTALL_FOO}/${_ARG_INTO} |
| 294 |
COMPONENT Other ) |
| 295 |
endif () |
| 296 |
endforeach() |
| 297 |
endmacro () |
| 298 |
|
| 299 |
## CTest defaults |
| 300 |
|
| 301 |
## CPack defaults |
| 302 |
set ( CPACK_GENERATOR "ZIP" ) |
| 303 |
set ( CPACK_STRIP_FILES TRUE ) |
| 304 |
set ( CPACK_PACKAGE_NAME "${DIST_NAME}" ) |
| 305 |
set ( CPACK_PACKAGE_VERSION "${DIST_VERSION}") |
| 306 |
set ( CPACK_PACKAGE_VENDOR "LuaDist" ) |
| 307 |
set ( CPACK_COMPONENTS_ALL Runtime Library Header Data Documentation Example Other ) |
| 308 |
include ( CPack ) |