Adding a new app#
Now that you have a taste of creating your own POLARIS objects, you may be ready to add a project of your own. This guide will cover how you can utilize CMake to add libraries and executables on multiple platforms.
Open up the main CMakeLists.txt located in the root directory
Determine whether your project is an executable or a library. If it is an executable, it will live in the apps folder - if it is a library it will live in the libs folder.
Add your project to the list of include directories
#Other POLARIS projects
include_directories(libs)
include_directories(libs/io)
include_directories(libs/core)
include_directories(libs/repository)
include_directories(libs/traffic_simulator)
include_directories(libs/scenario_manager)
include_directories(libs/population_synthesis)
include_directories(apps)
include_directories(tests)
#Adding the my_library and my_application
include_directories(libs/my_library)
include_directories(apps/my_application)
Add your project to the list of sub directories
#Other POLARIS projects
add_subdirectory(libs/core)
add_subdirectory(libs/repository)
add_subdirectory(libs/io)
add_subdirectory(libs/spatial)
add_subdirectory(libs/routing)
add_subdirectory(libs/traffic_simulator)
add_subdirectory(libs/scenario_manager)
add_subdirectory(libs/population_synthesis)
add_subdirectory(libs/activity_simulator)
#Adding the my_library and my_application
add_subdirectory(libs/my_library)
add_subdirectory(apps/my_application)
If your project depends on additional libraries we will cover that in: [Linking Dependencies Using CMake](https://github.com/anl-tracc/polaris/wiki/Linking Dependencies Using CMake)
Make folder(s) in the directory structure for your projects. For this example, two are being created, one at libs/my_library and another at apps/my_application
Add a .cpp file to each new folder. For this example: My_Library.cpp in libs/my_library and My_Application.cpp in apps/my_application.
Make a new file in each directory called “CMakeLists.txt”, the contents will be different for applications versus libraries.
For my_library, below is a good starting template:
file(GLOB_RECURSE hppfiles RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} *.h)
file(GLOB_RECURSE cppfiles RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} *.cpp)
source_group("Implementations" _Implementation*..h)
source_group("Prototypes" _Prototype*..h)
add_library(My_Library ${cppfiles} ${hppfiles})
set_target_properties(My_Library PROPERTIES FOLDER libs)
For my_application, let’s assume we need to link to my_library and all other existing POLARIS libraries:
file(GLOB_RECURSE hppfiles RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} *.h)
file(GLOB_RECURSE cppfiles RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} *.cpp)
add_executable(My_Application My_Application.cpp)
target_link_libraries(My_Application ${libtcmalloc} ${antareslibs} ${iolibs} Scenario_Manager Core Routing My_Library)
set_target_properties(My_Application PROPERTIES FOLDER apps)
Go back to the root directory and run this CMake command from the build folder:
python build.py -c
Re-open visual studio where you will find your new projects to begin work on