This repository has been archived by the owner on Nov 20, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 41
Example: C module
drahosp edited this page Feb 19, 2013
·
4 revisions
Writing CMake scripts for installing C modules without dependenies is very straightforward. The following steps are required:
- Define project name - This is usually equal to the name of the module.
- Copy the cmake macro folder directory from our Tools
- Create the module using a macro
- Write commands for installing module and other files
For example here is the CMake script for building the LPeg module:
# Define projects name
# The C tells CMAKE to check for C compilers
project ( lpeg C )
# Define minimun version of CMAKE for compatibility
cmake_minimum_required ( VERSION 2.8 )
# Include dist.cmake - defines LuaDist related macros and install paths
# Also include Lua related macros
include ( cmake/dist.cmake )
include ( lua )
# Create and install a Lua module:
# first parameter is module's name (the name that can be required in Lua)
# second and following parameters are the source files (here only one file)
# last parameter is a .def file for exporting symbols from dll produced by MS compilers
install_lua_module ( lpeg lpeg.c lpeg.def)
install_lua_module ( re re.lua )
# Schedules a test, this is optional
add_lua_test ( test.lua )
# Install test ( NOTE: This does not execute testing, just installs)
install_test ( test.lua )
# Install documentation
install_doc ( re.html lpeg.html lpeg-128.gif )
If a module is build from multiple files, e.g. md5 module, the following form can be used:
# Multiple files in subdirectory with link
install_lua_module ( other.lib.core src/core.c src/util.c LINK ${SOME_LIB} ${SOME_OTHER_LIB} )
Additionally file paths can be stored as a list in a variable and passed into the macro. You can find out more abut CMake by reading the full documentation.