Skip to content
This repository was archived by the owner on Nov 20, 2020. It is now read-only.
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit aa50991

Browse files
committedAug 1, 2012
New CMake macros
1 parent 35bf4a3 commit aa50991

File tree

5 files changed

+734
-457
lines changed

5 files changed

+734
-457
lines changed
 

‎CMakeLists.txt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
1-
# Copyright (C) 2007-2011 LuaDist.
1+
# Copyright (C) 2007-2012 LuaDist.
22
# Created by Peter Drahoš
33
# Redistribution and use of this file is allowed according to the terms of the MIT license.
44
# For details see the COPYRIGHT file distributed with LuaDist.
55
# Please note that the package source code is licensed under its own license.
66

77
project ( luaexpat C )
8-
cmake_minimum_required ( VERSION 2.6 )
9-
include ( dist.cmake )
8+
cmake_minimum_required ( VERSION 2.8 )
9+
include ( cmake/dist.cmake )
10+
include ( lua )
1011

1112
# Find Expat
1213
find_package ( EXPAT REQUIRED )
@@ -24,6 +25,5 @@ install_doc ( doc/ )
2425
install_test ( tests/ )
2526

2627
add_lua_test ( tests/test.lua )
27-
add_lua_test ( tests/test-lom.lua
28-
${CMAKE_CURRENT_SOURCE_DIR}/src # workaround to add modules to package.path (improve?)
28+
add_lua_test ( tests/test-lom.lua ${CMAKE_CURRENT_SOURCE_DIR}/src # workaround to add modules to package.path (improve?)
2929
)

‎cmake/FindLua.cmake

Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
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)
35+
SET(_POSSIBLE_LUA_INCLUDE include include/lua)
36+
SET(_POSSIBLE_LUA_EXECUTABLE lua)
37+
SET(_POSSIBLE_LUA_LIBRARY lua)
38+
39+
# Determine possible naming suffixes (there is no standard for this)
40+
IF(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}")
42+
ELSE(Lua_FIND_VERSION_MAJOR AND Lua_FIND_VERSION_MINOR)
43+
SET(_POSSIBLE_SUFFIXES "52" "5.2" "-5.2" "51" "5.1" "-5.1")
44+
ENDIF(Lua_FIND_VERSION_MAJOR AND Lua_FIND_VERSION_MINOR)
45+
46+
# Set up possible search names and locations
47+
FOREACH(_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}")
51+
ENDFOREACH(_SUFFIX)
52+
53+
# Find the lua executable
54+
FIND_PROGRAM(LUA_EXECUTABLE
55+
NAMES ${_POSSIBLE_LUA_EXECUTABLE}
56+
)
57+
58+
# Find the lua header
59+
FIND_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
75+
FIND_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+
91+
IF(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)
100+
ENDIF(LUA_LIBRARY)
101+
102+
# Determine Lua version
103+
IF(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)
108+
ENDIF()
109+
110+
INCLUDE(FindPackageHandleStandardArgs)
111+
# handle the QUIETLY and REQUIRED arguments and set LUA_FOUND to TRUE if
112+
# all listed variables are TRUE
113+
FIND_PACKAGE_HANDLE_STANDARD_ARGS(Lua
114+
REQUIRED_VARS LUA_LIBRARIES LUA_INCLUDE_DIR
115+
VERSION_VAR LUA_VERSION_STRING)
116+
117+
MARK_AS_ADVANCED(LUA_INCLUDE_DIR LUA_LIBRARIES LUA_LIBRARY LUA_MATH_LIBRARY LUA_EXECUTABLE)
118+

‎cmake/dist.cmake

Lines changed: 321 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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
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+
# RPath and relative linking
85+
option ( USE_RPATH "Use relative linking." ON)
86+
if ( 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 )
95+
endif ()
96+
97+
## MACROS
98+
# Parser macro
99+
macro ( 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} )
128+
endmacro ()
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
135+
set ( CPACK_COMPONENT_RUNTIME_DISPLAY_NAME "${DIST_NAME} Runtime" )
136+
set ( CPACK_COMPONENT_RUNTIME_DESCRIPTION
137+
"Executables and runtime libraries. Installed into ${INSTALL_BIN}." )
138+
macro ( 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()
147+
endmacro ()
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
153+
set ( CPACK_COMPONENT_LIBRARY_DISPLAY_NAME "${DIST_NAME} Development Libraries" )
154+
set ( CPACK_COMPONENT_LIBRARY_DESCRIPTION
155+
"Static and import libraries needed for development. Installed into ${INSTALL_LIB} or ${INSTALL_BIN}." )
156+
macro ( 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()
167+
endmacro ()
168+
169+
# helper function for various install_* functions, for PATTERN/REGEX args.
170+
macro ( _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 ()
177+
endmacro ()
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().
184+
set ( CPACK_COMPONENT_HEADER_DISPLAY_NAME "${DIST_NAME} Development Headers" )
185+
set ( CPACK_COMPONENT_HEADER_DESCRIPTION
186+
"Headers needed for development. Installed into ${INSTALL_INC}." )
187+
macro ( 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()
199+
endmacro ()
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().
206+
set ( CPACK_COMPONENT_DATA_DISPLAY_NAME "${DIST_NAME} Data" )
207+
set ( CPACK_COMPONENT_DATA_DESCRIPTION
208+
"Application data. Installed into ${INSTALL_DATA}." )
209+
macro ( 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()
222+
endmacro ()
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().
229+
set ( CPACK_COMPONENT_DOCUMENTATION_DISPLAY_NAME "${DIST_NAME} Documentation" )
230+
set ( CPACK_COMPONENT_DOCUMENTATION_DESCRIPTION
231+
"Application documentation. Installed into ${INSTALL_DOC}." )
232+
macro ( 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()
244+
endmacro ()
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().
251+
set ( CPACK_COMPONENT_EXAMPLE_DISPLAY_NAME "${DIST_NAME} Examples" )
252+
set ( CPACK_COMPONENT_EXAMPLE_DESCRIPTION
253+
"Examples and their associated data. Installed into ${INSTALL_EXAMPLE}." )
254+
macro ( 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()
266+
endmacro ()
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().
273+
set ( CPACK_COMPONENT_TEST_DISPLAY_NAME "${DIST_NAME} Tests" )
274+
set ( CPACK_COMPONENT_TEST_DESCRIPTION
275+
"Tests and associated data. Installed into ${INSTALL_TEST}." )
276+
macro ( 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()
288+
endmacro ()
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().
295+
set ( CPACK_COMPONENT_OTHER_DISPLAY_NAME "${DIST_NAME} Unspecified Content" )
296+
set ( CPACK_COMPONENT_OTHER_DESCRIPTION
297+
"Other unspecified content. Installed into ${INSTALL_FOO}." )
298+
macro ( 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()
310+
endmacro ()
311+
312+
## CTest defaults
313+
314+
## CPack defaults
315+
set ( CPACK_GENERATOR "ZIP" )
316+
set ( CPACK_STRIP_FILES TRUE )
317+
set ( CPACK_PACKAGE_NAME "${DIST_NAME}" )
318+
set ( CPACK_PACKAGE_VERSION "${DIST_VERSION}")
319+
set ( CPACK_PACKAGE_VENDOR "LuaDist" )
320+
set ( CPACK_COMPONENTS_ALL Runtime Library Header Data Documentation Example Other )
321+
include ( CPack )

‎cmake/lua.cmake

Lines changed: 290 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,290 @@
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+
9+
set ( INSTALL_LMOD ${INSTALL_LIB}/lua
10+
CACHE PATH "Directory to install Lua modules." )
11+
set ( INSTALL_CMOD ${INSTALL_LIB}/lua
12+
CACHE PATH "Directory to install Lua binary modules." )
13+
14+
option ( SKIP_LUA_WRAPPER
15+
"Do not build and install Lua executable wrappers." OFF)
16+
17+
# List of (Lua module name, file path) pairs.
18+
# Used internally by add_lua_test. Built by add_lua_module.
19+
set ( _lua_modules )
20+
21+
# utility function: appends path `path` to path `basepath`, properly
22+
# handling cases when `path` may be relative or absolute.
23+
macro ( _append_path basepath path result )
24+
if ( IS_ABSOLUTE "${path}" )
25+
set ( ${result} "${path}" )
26+
else ()
27+
set ( ${result} "${basepath}/${path}" )
28+
endif ()
29+
endmacro ()
30+
31+
# install_lua_executable ( target source )
32+
# Automatically generate a binary if srlua package is available
33+
# The application or its source will be placed into /bin
34+
# If the application source did not have .lua suffix then it will be added
35+
# USE: lua_executable ( sputnik src/sputnik.lua )
36+
macro ( install_lua_executable _name _source )
37+
get_filename_component ( _source_name ${_source} NAME_WE )
38+
# Find srlua and glue
39+
find_program( SRLUA_EXECUTABLE NAMES srlua )
40+
find_program( GLUE_EXECUTABLE NAMES glue )
41+
42+
if ( NOT SKIP_LUA_WRAPPER AND SRLUA_EXECUTABLE AND GLUE_EXECUTABLE )
43+
# Generate binary gluing the lua code to srlua
44+
add_custom_command(
45+
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${_name}
46+
COMMAND ${GLUE_EXECUTABLE}
47+
ARGS ${SRLUA_EXECUTABLE} ${_source} ${CMAKE_CURRENT_BINARY_DIR}/${_name}
48+
DEPENDS ${_source}
49+
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
50+
VERBATIM
51+
)
52+
# Make sure we have a target associated with the binary
53+
add_custom_target(${_name} ALL
54+
DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${_name}
55+
)
56+
# Install with run permissions
57+
install ( PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/${_name} DESTINATION ${INSTALL_BIN} COMPONENT Runtime)
58+
else()
59+
# Add .lua suffix and install as is
60+
install ( PROGRAMS ${_source} DESTINATION ${INSTALL_BIN}
61+
RENAME ${_source_name}.lua
62+
COMPONENT Runtime
63+
)
64+
endif()
65+
endmacro ()
66+
67+
macro ( _lua_module_helper is_install _name )
68+
parse_arguments ( _MODULE "LINK;ALL_IN_ONE" "" ${ARGN} )
69+
# _target is CMake-compatible target name for module (e.g. socket_core).
70+
# _module is relative path of target (e.g. socket/core),
71+
# without extension (e.g. .lua/.so/.dll).
72+
# _MODULE_SRC is list of module source files (e.g. .lua and .c files).
73+
# _MODULE_NAMES is list of module names (e.g. socket.core).
74+
if ( _MODULE_ALL_IN_ONE )
75+
string ( REGEX REPLACE "\\..*" "" _target "${_name}" )
76+
string ( REGEX REPLACE "\\..*" "" _module "${_name}" )
77+
set ( _target "${_target}_all_in_one")
78+
set ( _MODULE_SRC ${_MODULE_ALL_IN_ONE} )
79+
set ( _MODULE_NAMES ${_name} ${_MODULE_DEFAULT_ARGS} )
80+
else ()
81+
string ( REPLACE "." "_" _target "${_name}" )
82+
string ( REPLACE "." "/" _module "${_name}" )
83+
set ( _MODULE_SRC ${_MODULE_DEFAULT_ARGS} )
84+
set ( _MODULE_NAMES ${_name} )
85+
endif ()
86+
if ( NOT _MODULE_SRC )
87+
message ( FATAL_ERROR "no module sources specified" )
88+
endif ()
89+
list ( GET _MODULE_SRC 0 _first_source )
90+
91+
get_filename_component ( _ext ${_first_source} EXT )
92+
if ( _ext STREQUAL ".lua" ) # Lua source module
93+
list ( LENGTH _MODULE_SRC _len )
94+
if ( _len GREATER 1 )
95+
message ( FATAL_ERROR "more than one source file specified" )
96+
endif ()
97+
98+
set ( _module "${_module}.lua" )
99+
100+
get_filename_component ( _module_dir ${_module} PATH )
101+
get_filename_component ( _module_filename ${_module} NAME )
102+
_append_path ( "${CMAKE_CURRENT_SOURCE_DIR}" "${_first_source}" _module_path )
103+
list ( APPEND _lua_modules "${_name}" "${_module_path}" )
104+
105+
if ( ${is_install} )
106+
install ( FILES ${_first_source} DESTINATION ${INSTALL_LMOD}/${_module_dir}
107+
RENAME ${_module_filename}
108+
COMPONENT Runtime
109+
)
110+
endif ()
111+
else () # Lua C binary module
112+
enable_language ( C )
113+
find_package ( Lua REQUIRED )
114+
include_directories ( ${LUA_INCLUDE_DIR} )
115+
116+
set ( _module "${_module}${CMAKE_SHARED_MODULE_SUFFIX}" )
117+
118+
get_filename_component ( _module_dir ${_module} PATH )
119+
get_filename_component ( _module_filenamebase ${_module} NAME_WE )
120+
foreach ( _thisname ${_MODULE_NAMES} )
121+
list ( APPEND _lua_modules "${_thisname}"
122+
"${CMAKE_CURRENT_BINARY_DIR}/\${CMAKE_CFG_INTDIR}/${_module}" )
123+
endforeach ()
124+
125+
add_library( ${_target} MODULE ${_MODULE_SRC})
126+
target_link_libraries ( ${_target} ${LUA_LIBRARY} ${_MODULE_LINK} )
127+
set_target_properties ( ${_target} PROPERTIES LIBRARY_OUTPUT_DIRECTORY
128+
"${_module_dir}" PREFIX "" OUTPUT_NAME "${_module_filenamebase}" )
129+
if ( ${is_install} )
130+
install ( TARGETS ${_target} DESTINATION ${INSTALL_CMOD}/${_module_dir} COMPONENT Runtime)
131+
endif ()
132+
endif ()
133+
endmacro ()
134+
135+
# add_lua_module
136+
# Builds a Lua source module into a destination locatable by Lua
137+
# require syntax.
138+
# Binary modules are also supported where this function takes sources and
139+
# libraries to compile separated by LINK keyword.
140+
# USE: add_lua_module ( socket.http src/http.lua )
141+
# USE2: add_lua_module ( mime.core src/mime.c )
142+
# USE3: add_lua_module ( socket.core ${SRC_SOCKET} LINK ${LIB_SOCKET} )
143+
# USE4: add_lua_module ( ssl.context ssl.core ALL_IN_ONE src/context.c src/ssl.c )
144+
# This form builds an "all-in-one" module (e.g. ssl.so or ssl.dll containing
145+
# both modules ssl.context and ssl.core). The CMake target name will be
146+
# ssl_all_in_one.
147+
# Also sets variable _module_path (relative path where module typically
148+
# would be installed).
149+
macro ( add_lua_module )
150+
_lua_module_helper ( 0 ${ARGN} )
151+
endmacro ()
152+
153+
154+
# install_lua_module
155+
# This is the same as `add_lua_module` but also installs the module.
156+
# USE: install_lua_module ( socket.http src/http.lua )
157+
# USE2: install_lua_module ( mime.core src/mime.c )
158+
# USE3: install_lua_module ( socket.core ${SRC_SOCKET} LINK ${LIB_SOCKET} )
159+
macro ( install_lua_module )
160+
_lua_module_helper ( 1 ${ARGN} )
161+
endmacro ()
162+
163+
# Builds string representing Lua table mapping Lua modules names to file
164+
# paths. Used internally.
165+
macro ( _make_module_table _outvar )
166+
set ( ${_outvar} )
167+
list ( LENGTH _lua_modules _n )
168+
if ( ${_n} GREATER 0 ) # avoids cmake complaint
169+
foreach ( _i RANGE 1 ${_n} 2 )
170+
list ( GET _lua_modules ${_i} _path )
171+
math ( EXPR _ii ${_i}-1 )
172+
list ( GET _lua_modules ${_ii} _name )
173+
set ( ${_outvar} "${_table} ['${_name}'] = '${_path}'\;\n")
174+
endforeach ()
175+
endif ()
176+
set ( ${_outvar}
177+
"local modules = {
178+
${_table}}" )
179+
endmacro ()
180+
181+
# add_lua_test ( _testfile [ WORKING_DIRECTORY _working_dir ] )
182+
# Runs Lua script `_testfile` under CTest tester.
183+
# Optional named argument `WORKING_DIRECTORY` is current working directory to
184+
# run test under (defaults to ${CMAKE_CURRENT_BINARY_DIR}).
185+
# Both paths, if relative, are relative to ${CMAKE_CURRENT_SOURCE_DIR}.
186+
# Any modules previously defined with install_lua_module are automatically
187+
# preloaded (via package.preload) prior to running the test script.
188+
# Under LuaDist, set test=true in config.lua to enable testing.
189+
# USE: add_lua_test ( test/test1.lua [args...] [WORKING_DIRECTORY dir])
190+
macro ( add_lua_test _testfile )
191+
if ( NOT SKIP_TESTING )
192+
parse_arguments ( _ARG "WORKING_DIRECTORY" "" ${ARGN} )
193+
include ( CTest )
194+
find_program ( LUA NAMES lua lua.bat )
195+
get_filename_component ( TESTFILEABS ${_testfile} ABSOLUTE )
196+
get_filename_component ( TESTFILENAME ${_testfile} NAME )
197+
get_filename_component ( TESTFILEBASE ${_testfile} NAME_WE )
198+
199+
# Write wrapper script.
200+
# Note: One simple way to allow the script to find modules is
201+
# to just put them in package.preload.
202+
set ( TESTWRAPPER ${CMAKE_CURRENT_BINARY_DIR}/${TESTFILENAME} )
203+
_make_module_table ( _table )
204+
set ( TESTWRAPPERSOURCE
205+
"local CMAKE_CFG_INTDIR = ... or '.'
206+
${_table}
207+
local function preload_modules(modules)
208+
for name, path in pairs(modules) do
209+
if path:match'%.lua' then
210+
package.preload[name] = assert(loadfile(path))
211+
else
212+
local name = name:gsub('.*%-', '') -- remove any hyphen prefix
213+
local symbol = 'luaopen_' .. name:gsub('%.', '_')
214+
--improve: generalize to support all-in-one loader?
215+
local path = path:gsub('%$%{CMAKE_CFG_INTDIR%}', CMAKE_CFG_INTDIR)
216+
package.preload[name] = assert(package.loadlib(path, symbol))
217+
end
218+
end
219+
end
220+
preload_modules(modules)
221+
arg[0] = '${TESTFILEABS}'
222+
table.remove(arg, 1)
223+
return assert(loadfile '${TESTFILEABS}')(unpack(arg))
224+
" )
225+
if ( _ARG_WORKING_DIRECTORY )
226+
get_filename_component (
227+
TESTCURRENTDIRABS ${_ARG_WORKING_DIRECTORY} ABSOLUTE )
228+
# note: CMake 2.6 (unlike 2.8) lacks WORKING_DIRECTORY parameter.
229+
set ( _pre ${CMAKE_COMMAND} -E chdir "${TESTCURRENTDIRABS}" )
230+
endif ()
231+
file ( WRITE ${TESTWRAPPER} ${TESTWRAPPERSOURCE})
232+
add_test ( NAME ${TESTFILEBASE} COMMAND ${_pre} ${LUA}
233+
${TESTWRAPPER} "${CMAKE_CFG_INTDIR}"
234+
${_ARG_DEFAULT_ARGS} )
235+
endif ()
236+
# see also http://gdcm.svn.sourceforge.net/viewvc/gdcm/Sandbox/CMakeModules/UsePythonTest.cmake
237+
# Note: ${CMAKE_CFG_INTDIR} is a command-line argument to allow proper
238+
# expansion by the native build tool.
239+
endmacro ()
240+
241+
242+
# Converts Lua source file `_source` to binary string embedded in C source
243+
# file `_target`. Optionally compiles Lua source to byte code (not available
244+
# under LuaJIT2, which doesn't have a bytecode loader). Additionally, Lua
245+
# versions of bin2c [1] and luac [2] may be passed respectively as additional
246+
# arguments.
247+
#
248+
# [1] http://lua-users.org/wiki/BinToCee
249+
# [2] http://lua-users.org/wiki/LuaCompilerInLua
250+
function ( add_lua_bin2c _target _source )
251+
find_program ( LUA NAMES lua lua.bat )
252+
execute_process ( COMMAND ${LUA} -e "string.dump(function()end)"
253+
RESULT_VARIABLE _LUA_DUMP_RESULT ERROR_QUIET )
254+
if ( NOT ${_LUA_DUMP_RESULT} )
255+
SET ( HAVE_LUA_DUMP true )
256+
endif ()
257+
message ( "-- string.dump=${HAVE_LUA_DUMP}" )
258+
259+
if ( ARGV2 )
260+
get_filename_component ( BIN2C ${ARGV2} ABSOLUTE )
261+
set ( BIN2C ${LUA} ${BIN2C} )
262+
else ()
263+
find_program ( BIN2C NAMES bin2c bin2c.bat )
264+
endif ()
265+
if ( HAVE_LUA_DUMP )
266+
if ( ARGV3 )
267+
get_filename_component ( LUAC ${ARGV3} ABSOLUTE )
268+
set ( LUAC ${LUA} ${LUAC} )
269+
else ()
270+
find_program ( LUAC NAMES luac luac.bat )
271+
endif ()
272+
endif ( HAVE_LUA_DUMP )
273+
message ( "-- bin2c=${BIN2C}" )
274+
message ( "-- luac=${LUAC}" )
275+
276+
get_filename_component ( SOURCEABS ${_source} ABSOLUTE )
277+
if ( HAVE_LUA_DUMP )
278+
get_filename_component ( SOURCEBASE ${_source} NAME_WE )
279+
add_custom_command (
280+
OUTPUT ${_target} DEPENDS ${_source}
281+
COMMAND ${LUAC} -o ${CMAKE_CURRENT_BINARY_DIR}/${SOURCEBASE}.lo
282+
${SOURCEABS}
283+
COMMAND ${BIN2C} ${CMAKE_CURRENT_BINARY_DIR}/${SOURCEBASE}.lo
284+
">${_target}" )
285+
else ()
286+
add_custom_command (
287+
OUTPUT ${_target} DEPENDS ${SOURCEABS}
288+
COMMAND ${BIN2C} ${_source} ">${_target}" )
289+
endif ()
290+
endfunction()

‎dist.cmake

Lines changed: 0 additions & 452 deletions
This file was deleted.

0 commit comments

Comments
 (0)
This repository has been archived.