Discussion Using CMake with Orbiter

Urwumpe

Not funny anymore
Addon Developer
Donator
Joined
Feb 6, 2008
Messages
36,873
Reaction score
1,533
Points
203
Location
Langendernbach
I resumed working on a simple find_package script for finding the OrbiterSDK in CMake, in case somebody else needs it or has suggestions how to improve it, feel free to contribute.

Code:
cmake_minimum_required(VERSION 3.17)
# - Try to find OrbiterSDK
# Once done, this will define
#
#  ORBITERSDK_FOUND - system has OrbiterSDK
#  ORBITERSDK_INCLUDE_DIRS - the Orbiter include directory
#  ORBITERSDK_LIBRARIES - link these to use Orbiter

set(ORBITER_HOME "C:\\Orbiter" CACHE PATH "The Orbiter installation directory used as target")


find_path(OrbiterSDK_INCLUDE_DIR 
          HINTS ${ORBITER_HOME}/OrbiterSDK/Include
          NAMES OrbiterAPI.h VesselAPI.h )

find_library(ORBITERSDK_LIBRARY NAMES OrbiterSDK.lib
             HINTS ${ORBITER_HOME}/OrbiterSDK/lib )

find_library(ORBITER_LIBRARY NAMES orbiter.lib
             HINTS ${ORBITER_HOME}/OrbiterSDK/lib )

if(LUA IN_LIST OrbiterSDK_FIND_COMPONENTS) 
    find_library(ORBITER_LUA_LIBRARY NAMES lua5.1.lib
             HINTS ${ORBITER_HOME}/OrbiterSDK/lib/lua )
    if(${ORBITER_LUA_LIBARY})
        set(OrbiterSDK_LUA_FOUND true)
    endif()
endif()

include(FindPackageHandleStandardArgs)
# handle the QUIETLY and REQUIRED arguments and set OrbiterSDK_FOUND to TRUE
# if all listed variables are TRUE
find_package_handle_standard_args(OrbiterSDK 
                                  REQUIRED_VARS ORBITERSDK_LIBRARY ORBITER_LIBRARY OrbiterSDK_INCLUDE_DIR
                                  HANDLE_COMPONENTS
                                  FAIL_MESSAGE DEFAULT_MSG)

mark_as_advanced(ORBITERSDK_INCLUDE_DIR ORBITERSDK_LIBRARY ORBITER_LIBRARY)

set(OrbiterSDK_LIBRARIES ${ORBITERSDK_LIBRARY} ${ORBITER_LIBRARY} )
set(OrbiterSDK_INCLUDE_DIRS ${OrbiterSDK_INCLUDE_DIR} )
set(OrbiterSDK_MESHES_DIR ${ORBITER_HOME}/Meshes)
set(OrbiterSDK_MODULES_DIR ${ORBITER_HOME}/Modules)
set(OrbiterSDK_LINK_OPTIONS /MACHINE:x86)

For using it, include find_package(OrbiterSDK REQUIRED) into your CMakeLists.txt, after placing the script into your CMAKE_MODULE_PATH path, for example by the line list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/CMake/") and putting the script as "FindOrbiterSDK.cmake" into a folder "CMake", which is in your projects root directory.

CMake is supported by any recent Visual Studio version and you can also combine it with VcPkg to get any missing dependencies installed.

UPDATE: 11/13/2020 - Updated the module script with a more sophisticated version of it, this time with limited lua support as OPTIONAL component.
 
Last edited:

Urwumpe

Not funny anymore
Addon Developer
Donator
Joined
Feb 6, 2008
Messages
36,873
Reaction score
1,533
Points
203
Location
Langendernbach
A small update to the script, now its a bit more sophisticated and allows referencing to the lua components as optional component, though that part is still a bit buggy, since I did not yet use Lua in the test project. Will fix things as soon as I really have a use case there, I just tested how this behaves as a small feasibility test.
 
Top