If OpenMS' TOPP and UTILS tools are not enough in a certain scenario, you can either request a change to OpenMS, if you feel this functionality is useful for others as well, or modify/extend OpenMS privately. For the latter, there are multiple ways to do this: You can modify the developer version of OpenMS by changing existing tools or adding new ones. Or you use an External Project to write a new tool, while not touching OpenMS itself (see below on how to do that). Once you've finished your new tool, and it only needs to run on the development machine, you're done. If you want to ship it to a new client machine, see Shipping your external code to a new machine .
Compiling external code
It is very easy to set up an environment to write your own programs using OpenMS. Make sure you downloaded and installed the source package of OpenMS/TOPP properly. Note that you cannot use the 'install' target when working with the development version of OpenMS - it must be built and used within the build tree.
All important compiler settings and preprocessor definitions along with the OpenMS library will be available to you. The most important variables are:
-
OpenMS_INCLUDE_DIRECTORIES - all include directories containing OpenMS headers
-
OPENMS_ADDCXX_FLAGS - preprocessor macros we require written as (-DMACRO1 -DMACRO2) etc
and the OpenMS target itself (which you can link against).
The example that follows will be explained in details:
### example CMakeLists.txt to develop C++ programs using OpenMS
project("Example_Project_using_OpenMS")
cmake_minimum_required(VERSION 2.8.3)
## list all your executables here (a corresponding .cpp file should exist, e.g. Main.cpp)
set(my_executables
Main
)
## list all classes here, which are required by your executables
## (all these classes will be linked into a library)
set(my_sources
ExampleLibraryFile.cpp
)
##
find OpenMS configuration and
register target
"OpenMS" (our library)
## if the above fails you can try calling cmake with -D OpenMS_DIR=/path/to/OpenMS/
## or modify the find_package() call accordingly
## find_package(OpenMS PATHS "</path/to/OpenMS//")
# check whether the OpenMS package was found
if (OpenMS_FOUND)
# check if the variable containing the include directories is defined
if(NOT OpenMS_INCLUDE_DIRECTORIES)
set(_message "The variable \${OpenMS_INCLUDE_DIRECTORIES} is not defined.")
set(_message "${_message}This CMakeLists.txt and your build of OpenMS seem incompatible.")
set(_message "${_message}Please use the latest version from the OpenMS release!")
message(FATAL_ERROR ${_message})
endif()
## include directories for OpenMS headers (and contrib)
# Note: If you want to link against a specific library contained
# in the OpenMS package you should also list the
# corresponding include variable here, e.g.,
# OpenMS_GUI -> ${OpenMS_GUI_INCLUDE_DIRECTORIES}
include_directories(${OpenMS_INCLUDE_DIRECTORIES})
## append precompiler macros and compiler flags specific to
OpenMS ## Warning: this could be harmful to your project. Check this if problems occur.
## Also, use this to add your own compiler flags, e.g. for OpenMP support.
## e.g. for Visual Studio use /openmp
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OPENMS_ADDCXX_FLAGS}")
# set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OPENMS_ADDCXX_FLAGS} /openmp")
add_definitions(/DBOOST_ALL_NO_LIB) ## disable auto-linking of boost libs (Boost tends to guess wrong lib names)
## library with additional classes from above
add_library(my_custom_lib STATIC ${my_sources})
## add targets for the executables
foreach(i ${my_executables})
add_executable(${i} ${i}.cpp)
## link executables against
OpenMS target_link_libraries(${i}
OpenMS my_custom_lib)
endforeach(i)
else(OpenMS_FOUND)
message(FATAL_ERROR "OpenMSConfig.cmake file not found!")
endif(OpenMS_FOUND)
The command project defines the name of the project - the name is only of interest of you're working in an IDE or want to export this project's targets. To compile your program just append it to the my_executables list. If you also use object files (classes which do not contain a main program), append them to the my_sources list. In the next step CMake creates a statically linked library of the object files, listed in my_sources. This simple CMakeLists.txt example can be extended to also build shared libraries, include other external libraries and so on.
An example external project can be found in OpenMS/share/OpenMS/examples/external_code. Copy these files to a separate directory and use CMake to configure it (here as an in-source build).
cd <path_to_external_project>
cmake -G "<generator>" .
For more information visit the website of cmake at cmake.org and consult the documentation.
Have fun coding with OpenMS!
Shipping your external code to a new machine
If you've modified OpenMS itself and not used an external project you can just use our installer scripts, to build your own OpenMS installer for your platform (see our internal FAQ which is built using "make doc_internal") and ship that to a client machine.
If you've used an external project and have a new executable (+ an optional new library), you can use the installer approach as well, and manually copy the new executable to the TOPP/UTILS binary directory (e.g. on Windows this could be c:/program files/OpenMS/bin, on Linux it could be /bin.
If you do NOT use the installer, you can copy all required files manually, plus a few extra steps - see below. What needs to be done is a little platform dependent, thus very cumbersome to explain. You should look at the cmake installer scripts, to see whats required (for Mac and Linux see OpenMS/cmake/package*.cmake, for Windows see https://github.com/OpenMS/windows-installer/OpenMS_installer.nsi ).
In short:
-
copy the OpenMS/share/OpenMS directory to the client machine (e.g. <client/my_dir>/share) and set the environment variable OPENMS_DATA_PATH to this directory
-
copy the OpenMS library (OpenMS.dll for Windows or OpenMS.so/.dylib for Linux/Mac) to <client/my_dir>/bin
-
copy all Qt4 libraries to the client <client/my_dir>/bin or on Linux/Mac make sure you have installed the Qt4 package
-
[Windows only] copy Xerces dll (see contrib/lib) to <client/my_dir>/bin
-
[Windows only] install the VS redistributable package (see Microsoft Homepage) on the client machine which corresponds to the VS version that was used to compile your code (use the correct redistributable package! , i.e. architecture 32|64bit, VS version, VS Service Pack version). If you choose the wrong redistributable package, you will get "Application failed to initialize properly..." error messages.