aboutsummaryrefslogtreecommitdiff
path: root/cmake
diff options
context:
space:
mode:
Diffstat (limited to 'cmake')
-rw-r--r--cmake/FindLua.cmake127
-rw-r--r--cmake/dist.cmake321
-rw-r--r--cmake/lua.cmake309
3 files changed, 757 insertions, 0 deletions
diff --git a/cmake/FindLua.cmake b/cmake/FindLua.cmake
new file mode 100644
index 0000000..6991b4a
--- /dev/null
+++ b/cmake/FindLua.cmake
@@ -0,0 +1,127 @@
1# Locate Lua library
2# This module defines
3# LUA_EXECUTABLE, if found
4# LUA_FOUND, if false, do not try to link to Lua
5# LUA_LIBRARIES
6# LUA_INCLUDE_DIR, where to find lua.h
7# LUA_VERSION_STRING, the version of Lua found (since CMake 2.8.8)
8#
9# Note that the expected include convention is
10# #include "lua.h"
11# and not
12# #include <lua/lua.h>
13# This is because, the lua location is not standardized and may exist
14# in locations other than lua/
15
16#=============================================================================
17# Copyright 2007-2009 Kitware, Inc.
18# Modified to support Lua 5.2 by LuaDist 2012
19#
20# Distributed under the OSI-approved BSD License (the "License");
21# see accompanying file Copyright.txt for details.
22#
23# This software is distributed WITHOUT ANY WARRANTY; without even the
24# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
25# See the License for more information.
26#=============================================================================
27# (To distribute this file outside of CMake, substitute the full
28# License text for the above reference.)
29#
30# The required version of Lua can be specified using the
31# standard syntax, e.g. FIND_PACKAGE(Lua 5.1)
32# Otherwise the module will search for any available Lua implementation
33
34# Always search for non-versioned lua first (recommended)
35SET(_POSSIBLE_LUA_INCLUDE include include/lua)
36SET(_POSSIBLE_LUA_EXECUTABLE lua)
37SET(_POSSIBLE_LUA_LIBRARY lua)
38
39# Determine possible naming suffixes (there is no standard for this)
40IF(Lua_FIND_VERSION_MAJOR AND Lua_FIND_VERSION_MINOR)
41 SET(_POSSIBLE_SUFFIXES "${Lua_FIND_VERSION_MAJOR}${Lua_FIND_VERSION_MINOR}" "${Lua_FIND_VERSION_MAJOR}.${Lua_FIND_VERSION_MINOR}" "-${Lua_FIND_VERSION_MAJOR}.${Lua_FIND_VERSION_MINOR}")
42ELSE(Lua_FIND_VERSION_MAJOR AND Lua_FIND_VERSION_MINOR)
43 SET(_POSSIBLE_SUFFIXES "52" "5.2" "-5.2" "51" "5.1" "-5.1")
44ENDIF(Lua_FIND_VERSION_MAJOR AND Lua_FIND_VERSION_MINOR)
45
46# Set up possible search names and locations
47FOREACH(_SUFFIX ${_POSSIBLE_SUFFIXES})
48 LIST(APPEND _POSSIBLE_LUA_INCLUDE "include/lua${_SUFFIX}")
49 LIST(APPEND _POSSIBLE_LUA_EXECUTABLE "lua${_SUFFIX}")
50 LIST(APPEND _POSSIBLE_LUA_LIBRARY "lua${_SUFFIX}")
51ENDFOREACH(_SUFFIX)
52
53# Find the lua executable
54FIND_PROGRAM(LUA_EXECUTABLE
55 NAMES ${_POSSIBLE_LUA_EXECUTABLE}
56)
57
58# Find the lua header
59FIND_PATH(LUA_INCLUDE_DIR lua.h
60 HINTS
61 $ENV{LUA_DIR}
62 PATH_SUFFIXES ${_POSSIBLE_LUA_INCLUDE}
63 PATHS
64 ~/Library/Frameworks
65 /Library/Frameworks
66 /usr/local
67 /usr
68 /sw # Fink
69 /opt/local # DarwinPorts
70 /opt/csw # Blastwave
71 /opt
72)
73
74# Find the lua library
75FIND_LIBRARY(LUA_LIBRARY
76 NAMES ${_POSSIBLE_LUA_LIBRARY}
77 HINTS
78 $ENV{LUA_DIR}
79 PATH_SUFFIXES lib64 lib
80 PATHS
81 ~/Library/Frameworks
82 /Library/Frameworks
83 /usr/local
84 /usr
85 /sw
86 /opt/local
87 /opt/csw
88 /opt
89)
90
91IF(LUA_LIBRARY)
92 # include the math library for Unix
93 IF(UNIX AND NOT APPLE)
94 FIND_LIBRARY(LUA_MATH_LIBRARY m)
95 SET( LUA_LIBRARIES "${LUA_LIBRARY};${LUA_MATH_LIBRARY}" CACHE STRING "Lua Libraries")
96 # For Windows and Mac, don't need to explicitly include the math library
97 ELSE(UNIX AND NOT APPLE)
98 SET( LUA_LIBRARIES "${LUA_LIBRARY}" CACHE STRING "Lua Libraries")
99 ENDIF(UNIX AND NOT APPLE)
100ENDIF(LUA_LIBRARY)
101
102# Determine Lua version
103IF(LUA_INCLUDE_DIR AND EXISTS "${LUA_INCLUDE_DIR}/lua.h")
104 FILE(STRINGS "${LUA_INCLUDE_DIR}/lua.h" lua_version_str REGEX "^#define[ \t]+LUA_RELEASE[ \t]+\"Lua .+\"")
105
106 STRING(REGEX REPLACE "^#define[ \t]+LUA_RELEASE[ \t]+\"Lua ([^\"]+)\".*" "\\1" LUA_VERSION_STRING "${lua_version_str}")
107 UNSET(lua_version_str)
108ENDIF()
109
110# Lua 5.2
111IF(NOT LUA_VERSION_STRING)
112 FILE(STRINGS "${LUA_INCLUDE_DIR}/lua.h" lua_version_str REGEX "^#define LUA_VERSION_[A-Z]+[ \t]+\"[0-9]+\"")
113 STRING(REGEX REPLACE ".*#define LUA_VERSION_MAJOR[ \t]+\"([0-9]+)\".*" "\\1" LUA_VERSION_MAJOR ${lua_version_str})
114 STRING(REGEX REPLACE ".*#define LUA_VERSION_MINOR[ \t]+\"([0-9]+)\".*" "\\1" LUA_VERSION_MINOR ${lua_version_str})
115 STRING(REGEX REPLACE ".*#define LUA_VERSION_RELEASE[ \t]+\"([0-9]+)\".*" "\\1" LUA_VERSION_RELEASE ${lua_version_str})
116 SET(LUA_VERSION_STRING ${LUA_VERSION_MAJOR}.${LUA_VERSION_MINOR}.${LUA_VERSION_RELEASE})
117ENDIF()
118
119INCLUDE(FindPackageHandleStandardArgs)
120# handle the QUIETLY and REQUIRED arguments and set LUA_FOUND to TRUE if
121# all listed variables are TRUE
122FIND_PACKAGE_HANDLE_STANDARD_ARGS(Lua
123 REQUIRED_VARS LUA_LIBRARIES LUA_INCLUDE_DIR
124 VERSION_VAR LUA_VERSION_STRING)
125
126MARK_AS_ADVANCED(LUA_INCLUDE_DIR LUA_LIBRARIES LUA_LIBRARY LUA_MATH_LIBRARY LUA_EXECUTABLE)
127
diff --git a/cmake/dist.cmake b/cmake/dist.cmake
new file mode 100644
index 0000000..310ef94
--- /dev/null
+++ b/cmake/dist.cmake
@@ -0,0 +1,321 @@
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
11if ( NOT EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/dist.info )
12 message ( FATAL_ERROR
13 "Missing dist.info file (${CMAKE_CURRENT_SOURCE_DIR}/dist.info)." )
14endif ()
15file ( READ ${CMAKE_CURRENT_SOURCE_DIR}/dist.info DIST_INFO )
16if ( "${DIST_INFO}" STREQUAL "" )
17 message ( FATAL_ERROR "Failed to load dist.info." )
18endif ()
19# Reads field `name` from dist.info string `DIST_INFO` into variable `var`.
20macro ( _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 ()
26endmacro ()
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 )
35message ( "DIST_NAME: ${DIST_NAME}")
36message ( "DIST_VERSION: ${DIST_VERSION}")
37message ( "DIST_LICENSE: ${DIST_LICENSE}")
38message ( "DIST_AUTHOR: ${DIST_AUTHOR}")
39message ( "DIST_MAINTAINER: ${DIST_MAINTAINER}")
40message ( "DIST_URL: ${DIST_URL}")
41message ( "DIST_DESC: ${DIST_DESC}")
42string ( REGEX REPLACE ".*depends[ \t]?=[ \t]?[\"']([^\"']+)[\"'].*" "\\1"
43 DIST_DEPENDS ${DIST_INFO} )
44if ( DIST_DEPENDS STREQUAL DIST_INFO )
45 set ( DIST_DEPENDS "" )
46endif ()
47message ( "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
53set ( INSTALL_BIN bin CACHE PATH "Where to install binaries to." )
54set ( INSTALL_LIB lib CACHE PATH "Where to install libraries to." )
55set ( INSTALL_INC include CACHE PATH "Where to install headers to." )
56set ( INSTALL_ETC etc CACHE PATH "Where to store configuration files" )
57set ( INSTALL_SHARE share CACHE PATH "Directory for shared data." )
58
59# Secondary paths
60option ( INSTALL_VERSION
61 "Install runtime libraries and executables with version information." OFF)
62set ( INSTALL_DATA ${INSTALL_SHARE}/${DIST_NAME} CACHE PATH
63 "Directory the package can store documentation, tests or other data in.")
64set ( INSTALL_DOC ${INSTALL_DATA}/doc CACHE PATH
65 "Recommended directory to install documentation into.")
66set ( INSTALL_EXAMPLE ${INSTALL_DATA}/example CACHE PATH
67 "Recommended directory to install examples into.")
68set ( INSTALL_TEST ${INSTALL_DATA}/test CACHE PATH
69 "Recommended directory to install tests into.")
70set ( 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
75set ( CMAKE_ALLOW_LOOSE_LOOP_CONSTRUCTS true )
76set ( CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake" ${CMAKE_MODULE_PATH} )
77option ( BUILD_SHARED_LIBS "Build shared libraries" ON )
78
79# In MSVC, prevent warnings that can occur when using standard libraries.
80if ( MSVC )
81 add_definitions ( -D_CRT_SECURE_NO_WARNINGS )
82endif ()
83
84# RPath and relative linking
85option ( USE_RPATH "Use relative linking." ON)
86if ( USE_RPATH )
87 string ( REGEX REPLACE "[^!/]+" ".." UP_DIR ${INSTALL_BIN} )
88 set ( CMAKE_SKIP_BUILD_RPATH FALSE CACHE STRING "" FORCE )
89 set ( CMAKE_BUILD_WITH_INSTALL_RPATH FALSE CACHE STRING "" FORCE )
90 set ( CMAKE_INSTALL_RPATH $ORIGIN/${UP_DIR}/${INSTALL_LIB}
91 CACHE STRING "" FORCE )
92 set ( CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE CACHE STRING "" FORCE )
93 set ( CMAKE_INSTALL_NAME_DIR @executable_path/${UP_DIR}/${INSTALL_LIB}
94 CACHE STRING "" FORCE )
95endif ()
96
97## MACROS
98# Parser macro
99macro ( parse_arguments prefix arg_names option_names)
100 set ( DEFAULT_ARGS )
101 foreach ( arg_name ${arg_names} )
102 set ( ${prefix}_${arg_name} )
103 endforeach ()
104 foreach ( option ${option_names} )
105 set ( ${prefix}_${option} FALSE )
106 endforeach ()
107
108 set ( current_arg_name DEFAULT_ARGS )
109 set ( current_arg_list )
110 foreach ( arg ${ARGN} )
111 set ( larg_names ${arg_names} )
112 list ( FIND larg_names "${arg}" is_arg_name )
113 if ( is_arg_name GREATER -1 )
114 set ( ${prefix}_${current_arg_name} ${current_arg_list} )
115 set ( current_arg_name ${arg} )
116 set ( current_arg_list )
117 else ()
118 set ( loption_names ${option_names} )
119 list ( FIND loption_names "${arg}" is_option )
120 if ( is_option GREATER -1 )
121 set ( ${prefix}_${arg} TRUE )
122 else ()
123 set ( current_arg_list ${current_arg_list} ${arg} )
124 endif ()
125 endif ()
126 endforeach ()
127 set ( ${prefix}_${current_arg_name} ${current_arg_list} )
128endmacro ()
129
130
131# install_executable ( executable_targets )
132# Installs any executables generated using "add_executable".
133# USE: install_executable ( lua )
134# NOTE: subdirectories are NOT supported
135set ( CPACK_COMPONENT_RUNTIME_DISPLAY_NAME "${DIST_NAME} Runtime" )
136set ( CPACK_COMPONENT_RUNTIME_DESCRIPTION
137 "Executables and runtime libraries. Installed into ${INSTALL_BIN}." )
138macro ( install_executable )
139 foreach ( _file ${ARGN} )
140 if ( INSTALL_VERSION )
141 set_target_properties ( ${_file} PROPERTIES VERSION ${DIST_VERSION}
142 SOVERSION ${DIST_VERSION} )
143 endif ()
144 install ( TARGETS ${_file} RUNTIME DESTINATION ${INSTALL_BIN}
145 COMPONENT Runtime )
146 endforeach()
147endmacro ()
148
149# install_library ( library_targets )
150# Installs any libraries generated using "add_library" into apropriate places.
151# USE: install_library ( libexpat )
152# NOTE: subdirectories are NOT supported
153set ( CPACK_COMPONENT_LIBRARY_DISPLAY_NAME "${DIST_NAME} Development Libraries" )
154set ( CPACK_COMPONENT_LIBRARY_DESCRIPTION
155 "Static and import libraries needed for development. Installed into ${INSTALL_LIB} or ${INSTALL_BIN}." )
156macro ( install_library )
157 foreach ( _file ${ARGN} )
158 if ( INSTALL_VERSION )
159 set_target_properties ( ${_file} PROPERTIES VERSION ${DIST_VERSION}
160 SOVERSION ${DIST_VERSION} )
161 endif ()
162 install ( TARGETS ${_file}
163 RUNTIME DESTINATION ${INSTALL_BIN} COMPONENT Runtime
164 LIBRARY DESTINATION ${INSTALL_LIB} COMPONENT Runtime
165 ARCHIVE DESTINATION ${INSTALL_LIB} COMPONENT Library )
166 endforeach()
167endmacro ()
168
169# helper function for various install_* functions, for PATTERN/REGEX args.
170macro ( _complete_install_args )
171 if ( NOT("${_ARG_PATTERN}" STREQUAL "") )
172 set ( _ARG_PATTERN PATTERN ${_ARG_PATTERN} )
173 endif ()
174 if ( NOT("${_ARG_REGEX}" STREQUAL "") )
175 set ( _ARG_REGEX REGEX ${_ARG_REGEX} )
176 endif ()
177endmacro ()
178
179# install_header ( files/directories [INTO destination] )
180# Install a directories or files into header destination.
181# USE: install_header ( lua.h luaconf.h ) or install_header ( GL )
182# USE: install_header ( mylib.h INTO mylib )
183# For directories, supports optional PATTERN/REGEX arguments like install().
184set ( CPACK_COMPONENT_HEADER_DISPLAY_NAME "${DIST_NAME} Development Headers" )
185set ( CPACK_COMPONENT_HEADER_DESCRIPTION
186 "Headers needed for development. Installed into ${INSTALL_INC}." )
187macro ( install_header )
188 parse_arguments ( _ARG "INTO;PATTERN;REGEX" "" ${ARGN} )
189 _complete_install_args()
190 foreach ( _file ${_ARG_DEFAULT_ARGS} )
191 if ( IS_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/${_file}" )
192 install ( DIRECTORY ${_file} DESTINATION ${INSTALL_INC}/${_ARG_INTO}
193 COMPONENT Header ${_ARG_PATTERN} ${_ARG_REGEX} )
194 else ()
195 install ( FILES ${_file} DESTINATION ${INSTALL_INC}/${_ARG_INTO}
196 COMPONENT Header )
197 endif ()
198 endforeach()
199endmacro ()
200
201# install_data ( files/directories [INTO destination] )
202# This installs additional data files or directories.
203# USE: install_data ( extra data.dat )
204# USE: install_data ( image1.png image2.png INTO images )
205# For directories, supports optional PATTERN/REGEX arguments like install().
206set ( CPACK_COMPONENT_DATA_DISPLAY_NAME "${DIST_NAME} Data" )
207set ( CPACK_COMPONENT_DATA_DESCRIPTION
208 "Application data. Installed into ${INSTALL_DATA}." )
209macro ( install_data )
210 parse_arguments ( _ARG "INTO;PATTERN;REGEX" "" ${ARGN} )
211 _complete_install_args()
212 foreach ( _file ${_ARG_DEFAULT_ARGS} )
213 if ( IS_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/${_file}" )
214 install ( DIRECTORY ${_file}
215 DESTINATION ${INSTALL_DATA}/${_ARG_INTO}
216 COMPONENT Data ${_ARG_PATTERN} ${_ARG_REGEX} )
217 else ()
218 install ( FILES ${_file} DESTINATION ${INSTALL_DATA}/${_ARG_INTO}
219 COMPONENT Data )
220 endif ()
221 endforeach()
222endmacro ()
223
224# INSTALL_DOC ( files/directories [INTO destination] )
225# This installs documentation content
226# USE: install_doc ( doc/ doc.pdf )
227# USE: install_doc ( index.html INTO html )
228# For directories, supports optional PATTERN/REGEX arguments like install().
229set ( CPACK_COMPONENT_DOCUMENTATION_DISPLAY_NAME "${DIST_NAME} Documentation" )
230set ( CPACK_COMPONENT_DOCUMENTATION_DESCRIPTION
231 "Application documentation. Installed into ${INSTALL_DOC}." )
232macro ( install_doc )
233 parse_arguments ( _ARG "INTO;PATTERN;REGEX" "" ${ARGN} )
234 _complete_install_args()
235 foreach ( _file ${_ARG_DEFAULT_ARGS} )
236 if ( IS_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/${_file}" )
237 install ( DIRECTORY ${_file} DESTINATION ${INSTALL_DOC}/${_ARG_INTO}
238 COMPONENT Documentation ${_ARG_PATTERN} ${_ARG_REGEX} )
239 else ()
240 install ( FILES ${_file} DESTINATION ${INSTALL_DOC}/${_ARG_INTO}
241 COMPONENT Documentation )
242 endif ()
243 endforeach()
244endmacro ()
245
246# install_example ( files/directories [INTO destination] )
247# This installs additional examples
248# USE: install_example ( examples/ exampleA )
249# USE: install_example ( super_example super_data INTO super)
250# For directories, supports optional PATTERN/REGEX argument like install().
251set ( CPACK_COMPONENT_EXAMPLE_DISPLAY_NAME "${DIST_NAME} Examples" )
252set ( CPACK_COMPONENT_EXAMPLE_DESCRIPTION
253 "Examples and their associated data. Installed into ${INSTALL_EXAMPLE}." )
254macro ( install_example )
255 parse_arguments ( _ARG "INTO;PATTERN;REGEX" "" ${ARGN} )
256 _complete_install_args()
257 foreach ( _file ${_ARG_DEFAULT_ARGS} )
258 if ( IS_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/${_file}" )
259 install ( DIRECTORY ${_file} DESTINATION ${INSTALL_EXAMPLE}/${_ARG_INTO}
260 COMPONENT Example ${_ARG_PATTERN} ${_ARG_REGEX} )
261 else ()
262 install ( FILES ${_file} DESTINATION ${INSTALL_EXAMPLE}/${_ARG_INTO}
263 COMPONENT Example )
264 endif ()
265 endforeach()
266endmacro ()
267
268# install_test ( files/directories [INTO destination] )
269# This installs tests and test files, DOES NOT EXECUTE TESTS
270# USE: install_test ( my_test data.sql )
271# USE: install_test ( feature_x_test INTO x )
272# For directories, supports optional PATTERN/REGEX argument like install().
273set ( CPACK_COMPONENT_TEST_DISPLAY_NAME "${DIST_NAME} Tests" )
274set ( CPACK_COMPONENT_TEST_DESCRIPTION
275 "Tests and associated data. Installed into ${INSTALL_TEST}." )
276macro ( install_test )
277 parse_arguments ( _ARG "INTO;PATTERN;REGEX" "" ${ARGN} )
278 _complete_install_args()
279 foreach ( _file ${_ARG_DEFAULT_ARGS} )
280 if ( IS_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/${_file}" )
281 install ( DIRECTORY ${_file} DESTINATION ${INSTALL_TEST}/${_ARG_INTO}
282 COMPONENT Test ${_ARG_PATTERN} ${_ARG_REGEX} )
283 else ()
284 install ( FILES ${_file} DESTINATION ${INSTALL_TEST}/${_ARG_INTO}
285 COMPONENT Test )
286 endif ()
287 endforeach()
288endmacro ()
289
290# install_foo ( files/directories [INTO destination] )
291# This installs optional or otherwise unneeded content
292# USE: install_foo ( etc/ example.doc )
293# USE: install_foo ( icon.png logo.png INTO icons)
294# For directories, supports optional PATTERN/REGEX argument like install().
295set ( CPACK_COMPONENT_OTHER_DISPLAY_NAME "${DIST_NAME} Unspecified Content" )
296set ( CPACK_COMPONENT_OTHER_DESCRIPTION
297 "Other unspecified content. Installed into ${INSTALL_FOO}." )
298macro ( install_foo )
299 parse_arguments ( _ARG "INTO;PATTERN;REGEX" "" ${ARGN} )
300 _complete_install_args()
301 foreach ( _file ${_ARG_DEFAULT_ARGS} )
302 if ( IS_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/${_file}" )
303 install ( DIRECTORY ${_file} DESTINATION ${INSTALL_FOO}/${_ARG_INTO}
304 COMPONENT Other ${_ARG_PATTERN} ${_ARG_REGEX} )
305 else ()
306 install ( FILES ${_file} DESTINATION ${INSTALL_FOO}/${_ARG_INTO}
307 COMPONENT Other )
308 endif ()
309 endforeach()
310endmacro ()
311
312## CTest defaults
313
314## CPack defaults
315set ( CPACK_GENERATOR "ZIP" )
316set ( CPACK_STRIP_FILES TRUE )
317set ( CPACK_PACKAGE_NAME "${DIST_NAME}" )
318set ( CPACK_PACKAGE_VERSION "${DIST_VERSION}")
319set ( CPACK_PACKAGE_VENDOR "LuaDist" )
320set ( CPACK_COMPONENTS_ALL Runtime Library Header Data Documentation Example Other )
321include ( CPack )
diff --git a/cmake/lua.cmake b/cmake/lua.cmake
new file mode 100644
index 0000000..ee2e35d
--- /dev/null
+++ b/cmake/lua.cmake
@@ -0,0 +1,309 @@
1# LuaDist CMake utility library for Lua.
2#
3# Copyright (C) 2007-2012 LuaDist.
4# by David Manura, Peter Drahos
5# Redistribution and use of this file is allowed according to the terms of the MIT license.
6# For details see the COPYRIGHT file distributed with LuaDist.
7# Please note that the package source code is licensed under its own license.
8
9set ( INSTALL_LMOD ${INSTALL_LIB}/lua
10 CACHE PATH "Directory to install Lua modules." )
11set ( INSTALL_CMOD ${INSTALL_LIB}/lua
12 CACHE PATH "Directory to install Lua binary modules." )
13
14option ( LUA_SKIP_WRAPPER
15 "Do not build and install Lua executable wrappers." OFF )
16option ( LUA_STATIC_MODULE "Build modules for static linking" OFF )
17
18# List of (Lua module name, file path) pairs.
19# Used internally by add_lua_test. Built by add_lua_module.
20set ( _lua_modules )
21
22# utility function: appends path `path` to path `basepath`, properly
23# handling cases when `path` may be relative or absolute.
24macro ( _append_path basepath path result )
25 if ( IS_ABSOLUTE "${path}" )
26 set ( ${result} "${path}" )
27 else ()
28 set ( ${result} "${basepath}/${path}" )
29 endif ()
30endmacro ()
31
32# install_lua_executable ( target source )
33# Automatically generate a binary if srlua package is available
34# The application or its source will be placed into /bin
35# If the application source did not have .lua suffix then it will be added
36# USE: lua_executable ( sputnik src/sputnik.lua )
37macro ( install_lua_executable _name _source )
38 get_filename_component ( _source_name ${_source} NAME_WE )
39 # Find srlua and glue
40 find_program( SRLUA_EXECUTABLE NAMES srlua )
41 find_program( GLUE_EXECUTABLE NAMES glue )
42 # Executable output
43 set ( _exe ${CMAKE_CURRENT_BINARY_DIR}/${_name}${CMAKE_EXECUTABLE_SUFFIX} )
44 if ( NOT SKIP_LUA_WRAPPER AND SRLUA_EXECUTABLE AND GLUE_EXECUTABLE )
45 # Generate binary gluing the lua code to srlua, this is a robuust approach for most systems
46 add_custom_command(
47 OUTPUT ${_exe}
48 COMMAND ${GLUE_EXECUTABLE}
49 ARGS ${SRLUA_EXECUTABLE} ${_source} ${_exe}
50 DEPENDS ${_source}
51 WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
52 VERBATIM
53 )
54 # Make sure we have a target associated with the binary
55 add_custom_target(${_name} ALL
56 DEPENDS ${_exe}
57 )
58 # Install with run permissions
59 install ( PROGRAMS ${_exe} DESTINATION ${INSTALL_BIN} COMPONENT Runtime)
60 # Also install source as optional resurce
61 install ( FILES ${_source} DESTINATION ${INSTALL_FOO} COMPONENT Other )
62 else()
63 # Install into bin as is but without the lua suffix, we assume the executable uses UNIX shebang/hash-bang magic
64 install ( PROGRAMS ${_source} DESTINATION ${INSTALL_BIN}
65 RENAME ${_source_name}
66 COMPONENT Runtime
67 )
68 endif()
69endmacro ()
70
71macro ( _lua_module_helper is_install _name )
72 parse_arguments ( _MODULE "LINK;ALL_IN_ONE" "" ${ARGN} )
73 # _target is CMake-compatible target name for module (e.g. socket_core).
74 # _module is relative path of target (e.g. socket/core),
75 # without extension (e.g. .lua/.so/.dll).
76 # _MODULE_SRC is list of module source files (e.g. .lua and .c files).
77 # _MODULE_NAMES is list of module names (e.g. socket.core).
78 if ( _MODULE_ALL_IN_ONE )
79 string ( REGEX REPLACE "\\..*" "" _target "${_name}" )
80 string ( REGEX REPLACE "\\..*" "" _module "${_name}" )
81 set ( _target "${_target}_all_in_one")
82 set ( _MODULE_SRC ${_MODULE_ALL_IN_ONE} )
83 set ( _MODULE_NAMES ${_name} ${_MODULE_DEFAULT_ARGS} )
84 else ()
85 string ( REPLACE "." "_" _target "${_name}" )
86 string ( REPLACE "." "/" _module "${_name}" )
87 set ( _MODULE_SRC ${_MODULE_DEFAULT_ARGS} )
88 set ( _MODULE_NAMES ${_name} )
89 endif ()
90 if ( NOT _MODULE_SRC )
91 message ( FATAL_ERROR "no module sources specified" )
92 endif ()
93 list ( GET _MODULE_SRC 0 _first_source )
94
95 get_filename_component ( _ext ${_first_source} EXT )
96 if ( _ext STREQUAL ".lua" ) # Lua source module
97 list ( LENGTH _MODULE_SRC _len )
98 if ( _len GREATER 1 )
99 message ( FATAL_ERROR "more than one source file specified" )
100 endif ()
101
102 set ( _module "${_module}.lua" )
103
104 get_filename_component ( _module_dir ${_module} PATH )
105 get_filename_component ( _module_filename ${_module} NAME )
106 _append_path ( "${CMAKE_CURRENT_SOURCE_DIR}" "${_first_source}" _module_path )
107 list ( APPEND _lua_modules "${_name}" "${_module_path}" )
108
109 if ( ${is_install} )
110 install ( FILES ${_first_source} DESTINATION ${INSTALL_LMOD}/${_module_dir}
111 RENAME ${_module_filename}
112 COMPONENT Runtime
113 )
114 endif ()
115 else () # Lua C binary module
116 enable_language ( C )
117 find_package ( Lua REQUIRED )
118 include_directories ( ${LUA_INCLUDE_DIR} )
119
120 set ( _module "${_module}${CMAKE_SHARED_MODULE_SUFFIX}" )
121
122 get_filename_component ( _module_dir ${_module} PATH )
123 get_filename_component ( _module_filenamebase ${_module} NAME_WE )
124 foreach ( _thisname ${_MODULE_NAMES} )
125 list ( APPEND _lua_modules "${_thisname}"
126 "${CMAKE_CURRENT_BINARY_DIR}/\${CMAKE_CFG_INTDIR}/${_module}" )
127 endforeach ()
128
129 # Static module (not linking to lua)
130 if ( LUA_STATIC_MODULE )
131 add_library( ${_target} STATIC ${_MODULE_SRC})
132 target_link_libraries ( ${_target} ${_MODULE_LINK} )
133 else ()
134 # Dynamic module
135 add_library( ${_target} MODULE ${_MODULE_SRC})
136 target_link_libraries ( ${_target} ${LUA_LIBRARY} ${_MODULE_LINK} )
137 endif ()
138
139 set_target_properties ( ${_target} PROPERTIES
140 ARCHIVE_OUTPUT_DIRECTORY "${_module_dir}"
141 LIBRARY_OUTPUT_DIRECTORY "${_module_dir}"
142 PREFIX ""
143 OUTPUT_NAME "${_module_filenamebase}" )
144 if ( ${is_install} )
145 install ( TARGETS ${_target}
146 LIBRARY DESTINATION ${INSTALL_CMOD}/${_module_dir}
147 COMPONENT Runtime
148 ARCHIVE DESTINATION ${INSTALL_CMOD}/${_module_dir}
149 COMPONENT Library )
150 endif ()
151 endif ()
152endmacro ()
153
154# add_lua_module
155# Builds a Lua source module into a destination locatable by Lua
156# require syntax.
157# Binary modules are also supported where this function takes sources and
158# libraries to compile separated by LINK keyword.
159# USE: add_lua_module ( socket.http src/http.lua )
160# USE2: add_lua_module ( mime.core src/mime.c )
161# USE3: add_lua_module ( socket.core ${SRC_SOCKET} LINK ${LIB_SOCKET} )
162# USE4: add_lua_module ( ssl.context ssl.core ALL_IN_ONE src/context.c src/ssl.c )
163# This form builds an "all-in-one" module (e.g. ssl.so or ssl.dll containing
164# both modules ssl.context and ssl.core). The CMake target name will be
165# ssl_all_in_one.
166# Also sets variable _module_path (relative path where module typically
167# would be installed).
168macro ( add_lua_module )
169 _lua_module_helper ( 0 ${ARGN} )
170endmacro ()
171
172
173# install_lua_module
174# This is the same as `add_lua_module` but also installs the module.
175# USE: install_lua_module ( socket.http src/http.lua )
176# USE2: install_lua_module ( mime.core src/mime.c )
177# USE3: install_lua_module ( socket.core ${SRC_SOCKET} LINK ${LIB_SOCKET} )
178macro ( install_lua_module )
179 _lua_module_helper ( 1 ${ARGN} )
180endmacro ()
181
182# Builds string representing Lua table mapping Lua modules names to file
183# paths. Used internally.
184macro ( _make_module_table _outvar )
185 set ( ${_outvar} )
186 list ( LENGTH _lua_modules _n )
187 if ( ${_n} GREATER 0 ) # avoids cmake complaint
188 foreach ( _i RANGE 1 ${_n} 2 )
189 list ( GET _lua_modules ${_i} _path )
190 math ( EXPR _ii ${_i}-1 )
191 list ( GET _lua_modules ${_ii} _name )
192 set ( ${_outvar} "${_table} ['${_name}'] = '${_path}'\;\n")
193 endforeach ()
194 endif ()
195 set ( ${_outvar}
196"local modules = {
197${_table}}" )
198endmacro ()
199
200# add_lua_test ( _testfile [ WORKING_DIRECTORY _working_dir ] )
201# Runs Lua script `_testfile` under CTest tester.
202# Optional named argument `WORKING_DIRECTORY` is current working directory to
203# run test under (defaults to ${CMAKE_CURRENT_BINARY_DIR}).
204# Both paths, if relative, are relative to ${CMAKE_CURRENT_SOURCE_DIR}.
205# Any modules previously defined with install_lua_module are automatically
206# preloaded (via package.preload) prior to running the test script.
207# Under LuaDist, set test=true in config.lua to enable testing.
208# USE: add_lua_test ( test/test1.lua [args...] [WORKING_DIRECTORY dir])
209macro ( add_lua_test _testfile )
210 if ( NOT SKIP_TESTING )
211 parse_arguments ( _ARG "WORKING_DIRECTORY" "" ${ARGN} )
212 include ( CTest )
213 find_program ( LUA NAMES lua lua.bat )
214 get_filename_component ( TESTFILEABS ${_testfile} ABSOLUTE )
215 get_filename_component ( TESTFILENAME ${_testfile} NAME )
216 get_filename_component ( TESTFILEBASE ${_testfile} NAME_WE )
217
218 # Write wrapper script.
219 # Note: One simple way to allow the script to find modules is
220 # to just put them in package.preload.
221 set ( TESTWRAPPER ${CMAKE_CURRENT_BINARY_DIR}/${TESTFILENAME} )
222 _make_module_table ( _table )
223 set ( TESTWRAPPERSOURCE
224"local CMAKE_CFG_INTDIR = ... or '.'
225${_table}
226local function preload_modules(modules)
227 for name, path in pairs(modules) do
228 if path:match'%.lua' then
229 package.preload[name] = assert(loadfile(path))
230 else
231 local name = name:gsub('.*%-', '') -- remove any hyphen prefix
232 local symbol = 'luaopen_' .. name:gsub('%.', '_')
233 --improve: generalize to support all-in-one loader?
234 local path = path:gsub('%$%{CMAKE_CFG_INTDIR%}', CMAKE_CFG_INTDIR)
235 package.preload[name] = assert(package.loadlib(path, symbol))
236 end
237 end
238end
239preload_modules(modules)
240arg[0] = '${TESTFILEABS}'
241table.remove(arg, 1)
242return assert(loadfile '${TESTFILEABS}')(unpack(arg))
243" )
244 if ( _ARG_WORKING_DIRECTORY )
245 get_filename_component (
246 TESTCURRENTDIRABS ${_ARG_WORKING_DIRECTORY} ABSOLUTE )
247 # note: CMake 2.6 (unlike 2.8) lacks WORKING_DIRECTORY parameter.
248 set ( _pre ${CMAKE_COMMAND} -E chdir "${TESTCURRENTDIRABS}" )
249 endif ()
250 file ( WRITE ${TESTWRAPPER} ${TESTWRAPPERSOURCE})
251 add_test ( NAME ${TESTFILEBASE} COMMAND ${_pre} ${LUA}
252 ${TESTWRAPPER} "${CMAKE_CFG_INTDIR}"
253 ${_ARG_DEFAULT_ARGS} )
254 endif ()
255 # see also http://gdcm.svn.sourceforge.net/viewvc/gdcm/Sandbox/CMakeModules/UsePythonTest.cmake
256 # Note: ${CMAKE_CFG_INTDIR} is a command-line argument to allow proper
257 # expansion by the native build tool.
258endmacro ()
259
260
261# Converts Lua source file `_source` to binary string embedded in C source
262# file `_target`. Optionally compiles Lua source to byte code (not available
263# under LuaJIT2, which doesn't have a bytecode loader). Additionally, Lua
264# versions of bin2c [1] and luac [2] may be passed respectively as additional
265# arguments.
266#
267# [1] http://lua-users.org/wiki/BinToCee
268# [2] http://lua-users.org/wiki/LuaCompilerInLua
269function ( add_lua_bin2c _target _source )
270 find_program ( LUA NAMES lua lua.bat )
271 execute_process ( COMMAND ${LUA} -e "string.dump(function()end)"
272 RESULT_VARIABLE _LUA_DUMP_RESULT ERROR_QUIET )
273 if ( NOT ${_LUA_DUMP_RESULT} )
274 SET ( HAVE_LUA_DUMP true )
275 endif ()
276 message ( "-- string.dump=${HAVE_LUA_DUMP}" )
277
278 if ( ARGV2 )
279 get_filename_component ( BIN2C ${ARGV2} ABSOLUTE )
280 set ( BIN2C ${LUA} ${BIN2C} )
281 else ()
282 find_program ( BIN2C NAMES bin2c bin2c.bat )
283 endif ()
284 if ( HAVE_LUA_DUMP )
285 if ( ARGV3 )
286 get_filename_component ( LUAC ${ARGV3} ABSOLUTE )
287 set ( LUAC ${LUA} ${LUAC} )
288 else ()
289 find_program ( LUAC NAMES luac luac.bat )
290 endif ()
291 endif ( HAVE_LUA_DUMP )
292 message ( "-- bin2c=${BIN2C}" )
293 message ( "-- luac=${LUAC}" )
294
295 get_filename_component ( SOURCEABS ${_source} ABSOLUTE )
296 if ( HAVE_LUA_DUMP )
297 get_filename_component ( SOURCEBASE ${_source} NAME_WE )
298 add_custom_command (
299 OUTPUT ${_target} DEPENDS ${_source}
300 COMMAND ${LUAC} -o ${CMAKE_CURRENT_BINARY_DIR}/${SOURCEBASE}.lo
301 ${SOURCEABS}
302 COMMAND ${BIN2C} ${CMAKE_CURRENT_BINARY_DIR}/${SOURCEBASE}.lo
303 ">${_target}" )
304 else ()
305 add_custom_command (
306 OUTPUT ${_target} DEPENDS ${SOURCEABS}
307 COMMAND ${BIN2C} ${_source} ">${_target}" )
308 endif ()
309endfunction()