A CMake compiler to help building Ports/NIFs in your Elixir/mix project.
Add elixir_cmake to your list of dependencies in mix.exs:
def deps do
[
{:elixir_cmake, "~> 0.1.0"}
]
endAdd :cmake to your compilers in mix.exs:
def project do
[
# ...
compilers: [:cmake] ++ Mix.compilers(),
# ...
]
endCreate your CMakeLists.txt in the root of your project or specify the path to an existing CMakeLists.txt file in your project config.
def project do
[
# ...
cmake_lists: "path/to/CMakeLists.txt",
# ...
]
endThe source files can reside anywhere the CMakeLists.txt file has access to.
You will need to copy the contents to your priv directory by either specifying
a compile alias or by directing the binary output to priv/ in your CMakeLists.txt.
file.
In this example we specify a project namedEXAMPLE, with source files in src/:
cmake_minimum_required(VERSION 3.0)
project(EXAMPLE)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/priv)
file(GLOB EXAMPLE_SRC src/*.c)
SET (CMAKE_C_FLAGS "-g -O3 -pedantic -Wall -Wextra -Wno-unused-parameter -std=c99")
include_directories(SYSTEM)
add_executable(example ${EXAMPLE_SRC})Run mix compile (or mix compile.cmake for just the CMake build) and you should find a compiled
binary in priv/ afterwards.
TODO
Be sure to read the documentation too.