Skip to content

Creating MEL Projects

Evan Pezent edited this page Feb 24, 2019 · 15 revisions

Setting Up your Project Directory and CMakeLists.txt

Now you have the MEL library built and installed, it's time to create your own project which uses it. Here's a typical C++ folder structure and CMakeLists.txt you can start with:

Note: You can save yourself some time by downloading the provided project template.

MyProject             # top level of your project
├── CMakeLists.txt    # your top-level CMakeLists.txt
├── build             # conventionally where building occurs
├── include           # where your header files live
    ├── MyClass.hpp   # a class header file
    ├── ...           # more header files
├── src               # where your source files live
    ├── MyClass.cpp   # a class source file
    ├── ...           # more source files
    ├── my_app.cpp    # an application file defining main()

CMakeLists.txt would then look like this:

# set minimum needed CMake version (always required)
cmake_minimum_required(VERSION 3.13)
# create your C++ project
project(MyProject VERSION 0.1.0 LANGUAGES CXX)
# find MEL::MEL and all available MEL::xxx modules
find_package(MEL REQUIRED)
# add your include directories
include_directories("include")
# create an app from your source files
add_executable(my_app "include/MyClass.hpp" "src/MyClass.cpp" "src/my_app.cpp")
# link your app to MEL libraries
target_link_libraries(my_app MEL::MEL)

If your're using MEL classes which target particular hardware, you need to link the the sub-module library that includes them. For example, to use Quanser devices:

target_link_libraries(my_app MEL::quanser)

or to use myRIO:

target_link_libraries(my_app MEL::myrio)

Note that we don't need to link to the core library MEL::MEL because MEL::quanser and MEL::myrio automatically import it as a dependency. You can also link against two compatible MEL sub-module libraries at once:

target_link_libraries(my_app MEL::quanser MEL::myo)

Building your Project

To generate your project build files, open a command prompt at the top level of your project directory and run:

> mkdir build                      # make build directory if it doesn't exist
> cd build                         # change directory to ./build
> cmake .. -G "GENERATOR STRING"   # call cmake with same generator used for MEL

Note: If you are compiling for NI embedded systems (myRIO/cRIO), don't forget to set CMAKE_TOOLCHAIN_FILE when calling CMake on your project.

(e.g.cmake .. -G Ninja -DCMAKE_TOOLCHAIN_FILE="../cmake/nilrt-arm-toolchain.cmake")

Now you can proceed to compile your project:

> cmake --build . --config Release

Those using native Windows hardware should be able to immediately run their executables. NI LRT device users will have to transfer the resulting binaries to the device over SFTP and execute them via SSH.