-
Notifications
You must be signed in to change notification settings - Fork 3
Creating MEL Projects
Now you have the MEL library built, it's time to create your own project which uses it. Since you already have CMake installed, here's a typical C++ folder structure and CMakeLists.txt
you can use as the basis for your own projects:
my_project # top level of your project
├── bin # conventionally where compiled binaries (applications) go
├── build # conventionally where building occurs
├── include # where your header files live
├── MyClass.hpp
├── ...
├── src # where your source files live
├── MyClass.cpp
├── ...
├── main.cpp
├── CMakeLists.txt # your top-level CMakeLists.txt
The CMakeLists.txt
would then look like this:
cmake_minimum_required(VERSION 3.7)
# enable C++11
set(CMAKE_CXX_STANDARD 11)
# create project
project(MyProject)
# set binary output location (optional, but recommended)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_SOURCE_DIR}/bin")
# include directories (your includes and MEL's)
include_directories("include" "/path/to/.../MEL/include")
# indicate where MEL.lib is
link_directories("/path/to/.../MEL/lib")
# create application
add_executable(MyApp include/MyClass.hpp src/MyClass.cpp src/main.cpp)
# link MEL
target_link_libraries(MyApp MEL)
You can save yourself some time by downloading the provided project template.
Note: If you built MEL statically, your project MUST define the preprocessor variable
MEL_STATIC
(e.g. by addingadd_definitions(-DMEL_STATIC)
to your ownCMakeLists.txt
). You will have to manually link your project against all of the external libraries MEL links against. To figure out which libraries are required, consult MEL'sCMakeLists.txt
.
Finally, to build your project open a command prompt at the top level of your project directory and run:
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!
That's it! Now you can proceed to compile your project with the appropriate software. Remember, you should use the same compiler/generator that compiled MEL and MEL.dll or libMEL.so
should be visible by your application if you built MEL as a dynamic library.