Git Product home page Git Product logo

cmake's Introduction

omnetpp-cmake — CMake + OMNeT++ = ❤

This repository is a community-supported work-in-progress, and may never be fully completed. Please help us and others like you by contributing. Thanks!

CMake Modules for building OMNeT++ projects and integrating with you CMake supporting editor.

These CMake modules were originally developed against OMNeT+ 5.X, but should also work with OMNeT++ 6.0 and beyond.

We are currently building our 📝 documentation website at https://omnetpp.github.io/cmake. Though this documentation is still work-in-progress, you may already have a look at it!

Usage

The following is one of many other ways to do it.

  1. Add the repository as a git submodule to your repository in cmake.1

    git submodule add https://github.com/omnetpp/cmake.git cmake

    Note: If you have other CMake modules it is recommended that you replace cmake with cmake/omnet and so forth here and in the following steps.

  2. Update and/or initialise the submodule.1

    git submodule update --init --recursive
  3. Create a minimal CMakeLists.txt in the root repository folder.

    project(YourProject)
    
    # It is recommended to increase the minimum version to your current
    cmake_minimum_required(VERSION 3.1)
    
    # Change "cmake" if you put the submodule in a different directory
    set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)
    
    find_package(OmnetPP 6.0 REQUIRED)
    
    # Load the CMake commands for OMNeT++
    include(OmnetppHelpers)
  4. Update your CMakeLists.txt with your OMNeT++ project details

    # Uncomment the following if you have external dependencies like INET
    #find_path(INET_DIR NAMES src/inet/package.ned DOC "INET root directory")
    #import_opp_target(inet ${INET_DIR}/src/Makefile)
    
    # Define your library/simulation sources
    set(SOURCES
        src/a.cc
        src/b.cc)
    
    add_library(project_library SHARED ${SOURCES})
    
    # Define your messages as well
    set(MESSAGE_SOURCES
        messages/a.msg
        messages/b.msg)
    
    generate_opp_message(project_library
        MESSAGE_FILES ${MESSAGE_SOURCES})
    
    # You will need to tweak and add the additional properties for your project
    set_target_properties(project_library PROPERTIES
        OUTPUT_NAME my_project_sim
        NED_FOLDERS src)
    
    # Link the libraries you need for your project; add "inet" if necessary
    target_link_libraries(project_library opp_interface)
    
    # This creates an OMNet++ CMake run for you
    add_opp_run(project_name 
        CONFIG omnetpp.ini 
        DEPENDENCY project_library)

Macros Available

  • generate_opp_message(<target> MESSAGE_FILES <file1> ...)
    Generates and links a message file to a given target.

  • import_opp_target(<opp_makemake_target> <Makefile> [ <cmake_target_file> ])
    Imports a target from a Makefile created by opp_makemake.
    Note: The target must have the same name as in the Makefile!

  • add_opp_build_target(<name>)
    Adds a build target with a given name.

  • add_opp_run(<name> [ CONFIG <file> | WORKING_DIRECTORY <dir> | NED_FOLDERS <dir1> ... ] DEPENDENCY <target> )
    Adds a build target with a given name based on the given dependency.

  • add_opp_test(<name> [CONFIG <file> | RUN <entry> | SIMTIME_LIMIT <limit> | SUFFIX <name>]) Adds a test target with a given name.

Interfaces and Library Targets Available

OmnetPP::header is a bare interface target with at least the compile definitions and include directories set for the found OMNeT++ setup. Additionally, the following OMNeT++ libraries are provided as imported library targets:

  • OmnetPP::cmdenv
  • OmnetPP::common
  • OmnetPP::envir
  • OmnetPP::eventlog
  • OmnetPP::layout
  • OmnetPP::main
  • OmnetPP::nedxml
  • OmnetPP::qtenv
  • OmnetPP::qtenv-osg
  • OmnetPP::scave
  • OmnetPP::sim
  • OmnetPP::tkenv

Motivation & Background

For the full motivation and background please see Raphael Riebl's presentation at the 2015 OMNeT++ Summit.

Some benefits include:

  • CMake is widely used for C/C++ projects
  • Convenient user interfaces available for configuring builds
  • Solid dependency handling, both internal and external
  • More accessible syntax compared to Makefiles
  • Several IDEs support the CMake build system
  • Support OMNeT++ 6.0 preview releases (by @thor)

Caveats

There have been some changes which might require fixes or future improvements. These are primarily changes to make the proof-of-concept employed in Artery also work with OMNet++ 6.0. However, there are also some minor oddities and questions, uncertainties and the likes of which.

  • opp_cmake.py will not take a lot of automatic definitions into account when importing a project
  • clean_opp_messages() is unavailable as message files are no longer gathered in a single folder for buliding
  • include path needs to be adjusted manually if #include "generated_m.h" is used
  • add_opp_run doesn't seem to utilise the parameter NED_FOLDERS

Licensing

The CMake modules were based on those in the OMNet++ V2X simulation framework in riebl/artery, which is licensed as GPL-2.0.

References


1: You could also just download the files and put them where you'd like, or if you want to contribute, fork it and add that repository as a submodule!

2: You may exchange the paths as you wish, but make sure to update them later on too.

cmake's People

Contributors

hplightcorner avatar karlhto avatar riebl avatar thor avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

cmake's Issues

Adding Examples/A Project Skeleton

To further lower the entry-bar for new CMake users, we should add examples and extend the documentation. A simple project skeleton would also be a good idea.

Furthermore, we could create ready-made CMake Files for common tasks like building INET.

Incorrect LICENSE file

I have just noticed that the LICENSE file contains the Apache 2.0 license.
I would like to "officially" confirm with this issue ticket that the license is actually GPL 2.0 as mentioned in our README.

Add an option to execute environment-setup script to add_opp_run

Hi,
When dealing with multiple OMNeT++ Versions, I normally avoid setting global environment variables. When using CMake, setting up various OMNeT++ Versions is supported by using CMake-Tools CMake-Kits. However, running a simulation directly from the IDE does not work as the DLLs are not found - because the paths are missing/not propagated.

It would be handy if I can add a setup script to commands like add_opp_run to, for example, modify the PATH.

Any thoughts on that?
I am implementing a prototype, setting up e.g. the PATH from within CMake for custom_target is not so straightforward, but I think I found a workaround.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.