Skip to content

Commit

Permalink
Merge pull request #177 from TwinFan/Next
Browse files Browse the repository at this point in the history
Merge v2.00 from Next into Master
  • Loading branch information
TwinFan authored Apr 25, 2020
2 parents 078b713 + 6352a55 commit 9a5a8c5
Show file tree
Hide file tree
Showing 73 changed files with 1,926 additions and 17,161 deletions.
203 changes: 96 additions & 107 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,59 +1,49 @@
# LiveTraffic build script.
#
# LiveTraffic - Set up to be used in the provided docker environment to build lin and mac
# mac does currently compile only, but fails linking.
# Set up to be used in a Visual Studio environment to build win (File > Open > Folder, then VS recognized the CMAKE configuration)

cmake_minimum_required(VERSION 3.9)
project(LiveTraffic VERSION 1.22 DESCRIPTION "LiveTraffic X-Plane plugin")
project(LiveTraffic VERSION 1.22 DESCRIPTION "LiveTraffic X-Plane plugin" LANGUAGES C CXX)

# By default, use optimized release configuration.
if (NOT CMAKE_BUILD_TYPE OR CMAKE_BUILD_TYPE STREQUAL "")
set(CMAKE_BUILD_TYPE "Release" CACHE STRING "" FORCE)
endif ()

set(CMAKE_CXX_STANDARD 17)

# Set include directories used by our code and dependencies.
include_directories("${CMAKE_SOURCE_DIR}/Include")
include_directories("${CMAKE_SOURCE_DIR}/Lib/xplanemp/xplanemp.framework/Headers")
include_directories("${CMAKE_SOURCE_DIR}/Lib/XPMP2/XPMP2.framework/Versions/1.0/Headers")
include_directories("${CMAKE_SOURCE_DIR}/Lib/LTAPI")
include_directories("${CMAKE_SOURCE_DIR}/Lib/XPSDK301/CHeaders/Widgets")
include_directories("${CMAKE_SOURCE_DIR}/Lib/XPSDK301/CHeaders/Wrappers")
include_directories("${CMAKE_SOURCE_DIR}/Lib/XPSDK301/CHeaders/XPLM")
message("CMAKE_CURRENT_SOURCE_DIR = "(${CMAKE_CURRENT_SOURCE_DIR}))
message("CMAKE_SOURCE_DIR = "(${CMAKE_SOURCE_DIR}))

# Specify library search locations.
if (WIN32)
list(APPEND CMAKE_LIBRARY_PATH "${CMAKE_CURRENT_SOURCE_DIR}/Lib/XPSDK301/Libraries/Win")
elseif (APPLE)
list(APPEND CMAKE_FRAMEWORK_PATH "${CMAKE_CURRENT_SOURCE_DIR}/Lib/XPSDK301/Libraries/Mac")
elseif (UNIX)

endif ()

# message (STATUS "CMAKE_LIBRARY_PATH" = ${CMAKE_LIBRARY_PATH})

# Enable all X-Plane SDK APIs up to the newest version.
add_definitions(-DXPLM200=1 -DXPLM210=1 -DXPLM300=1 -DXPLM301=1)

# Define platform macros.
add_definitions(-DAPL=$<BOOL:${APPLE}> -DIBM=$<BOOL:${WIN32}> -DLIN=$<AND:$<BOOL:${UNIX}>,$<NOT:$<BOOL:${APPLE}>>>)

# Force-enable exception support. This is most likely redundant, although for C
# code the default is the opposite. Since we are mixing C++ and C libraries,
# safer to set it on?
add_compile_options(-fexceptions -fpermissive)
# On UNIX systems this makes symbols non-exported by default. On Windows this
# option is simply ignored, since symbol visibility works differently there.
add_compile_options(-fvisibility=hidden)
if (UNIX OR APPLE)
# Force-enable exception support. This is most likely redundant, although for C
# code the default is the opposite. Since we are mixing C++ and C libraries,
# safer to set it on?
add_compile_options(-fexceptions -fpermissive)

# Enable stricter warnings and then disable some we are not interested in.
add_compile_options(-Wall -Wshadow -Wfloat-equal -Wextra)
add_compile_options(-Wno-unused)
# On UNIX systems this makes symbols non-exported by default. On Windows this
# option is simply ignored, since symbol visibility works differently there.
add_compile_options(-fvisibility=hidden)

# Always use position-independent code and highest optimization level (FPS!).
add_compile_options(-O3 -fPIC)

# X-Plane plugin
# Enable stricter warnings and then disable some we are not interested in.
add_compile_options(-Wall -Wshadow -Wfloat-equal -Wextra)
add_compile_options(-Wno-unused)

# Always use position-independent code and highest optimization level (FPS!).
add_compile_options(-O3 -fPIC)
elseif(WIN32)
# Deprecation warning: once is enough
add_compile_options(/wo4996)
endif()

################################################################################
# Source groups
Expand All @@ -79,9 +69,9 @@ set(Header_Files
Include/TFWidgets.h
Include/XPCompatibility.h
Lib/LTAPI/LTAPI.h
Lib/xplanemp/xplanemp.framework/Headers/XPCAircraft.h
Lib/xplanemp/xplanemp.framework/Headers/XPMPMultiplayer.h
Lib/xplanemp/xplanemp.framework/Headers/XPMPPlaneRenderer.h
Lib/XPMP2/XPMP2.framework/Versions/1.0/Headers/XPCAircraft.h
Lib/XPMP2/XPMP2.framework/Versions/1.0/Headers/XPMPMultiplayer.h
Lib/XPMP2/XPMP2.framework/Versions/1.0/Headers/XPMPPlaneRenderer.h
)
source_group("Header Files" FILES ${Header_Files})

Expand Down Expand Up @@ -111,56 +101,46 @@ source_group("Source Files" FILES ${Source_Files})

set(ALL_FILES ${Header_Files} ${Source_Files})

add_library(LiveTraffic SHARED ${ALL_FILES})
add_library(LiveTraffic MODULE ${ALL_FILES})

target_compile_features(LiveTraffic PUBLIC cxx_std_17)
################################################################################
# Link Libraries
################################################################################

# Specify library search locations.
if (APPLE)
# X-Plane supports OS X 10.10+, so this should ensure FlyWithLua can run on
# all supported versions.
target_compile_options(LiveTraffic PUBLIC -mmacosx-version-min=10.10)
target_link_libraries(LiveTraffic -mmacosx-version-min=10.10)
list(APPEND CMAKE_FRAMEWORK_PATH "${CMAKE_CURRENT_SOURCE_DIR}/Lib/CURL")
list(APPEND CMAKE_FRAMEWORK_PATH "${CMAKE_CURRENT_SOURCE_DIR}/Lib/XPMP2")
list(APPEND CMAKE_FRAMEWORK_PATH "${CMAKE_CURRENT_SOURCE_DIR}/Lib/XPSDK301/Libraries/Mac")
elseif (UNIX)
list(APPEND CMAKE_LIBRARY_PATH "${CMAKE_CURRENT_SOURCE_DIR}/Lib/XPMP2")
list(APPEND CMAKE_LIBRARY_PATH "${CMAKE_CURRENT_SOURCE_DIR}/Lib/XPSDK301/Libraries/Win")
elseif (WIN32)
list(APPEND CMAKE_LIBRARY_PATH "${CMAKE_CURRENT_SOURCE_DIR}/Lib/CURL")
list(APPEND CMAKE_LIBRARY_PATH "${CMAKE_CURRENT_SOURCE_DIR}/Lib/XPMP2")
list(APPEND CMAKE_LIBRARY_PATH "${CMAKE_CURRENT_SOURCE_DIR}/Lib/XPSDK301/Libraries/Win")
endif ()

# Link OpenGL and OpenAL related libraries.
find_package(OpenGL REQUIRED) # apt install freeglut3-dev
if ( OpenGL_FOUND )
include_directories( ${OpenGL_INCLUDE_DIRS} )
target_link_libraries( LiveTraffic ${OpenGL_LIBRARIES} )
endif( OpenGL_FOUND )

find_package(OpenAL REQUIRED) # apt install libopenal-dev
if ( OpenAL_FOUND )
include_directories( ${OpenAL_INCLUDE_DIRS} )
target_link_libraries( LiveTraffic ${OpenAL_LIBRARIES} )
endif( OpenAL_FOUND )

find_package(GLUT REQUIRED) # apt install freeglut3-dev
if ( GLUT_FOUND )
include_directories( ${GLUT_INCLUDE_DIRS} )
target_link_libraries( LiveTraffic ${GLUT_LIBRARIES} )
endif( GLUT_FOUND )

find_package(ZLIB REQUIRED) # sudo apt-get install zlib1g-dev
if ( ZLIB_FOUND )
include_directories( ${ZLIB_INCLUDE_DIRS} )
target_link_libraries( LiveTraffic ${ZLIB_LIBRARIES} )
endif( ZLIB_FOUND )

find_package(PNG REQUIRED) # sudo apt-get install libpng-dev
if ( PNG_FOUND )
include_directories( ${PNG_INCLUDE_DIRS} )
target_link_libraries( LiveTraffic ${PNG_LIBRARIES} )
endif( PNG_FOUND )


# ****************************************************
# This workd correctly with cmake but not with docker
find_package(CURL REQUIRED) # sudo apt-get install curl
if ( CURL_FOUND )
include_directories( ${CURL_INCLUDE_DIRS} )
target_link_libraries( LiveTraffic ${CURL_LIBRARIES} )
endif( CURL_FOUND )
# Find the XPMP2 library
if (APPLE)
find_library(XPMP2_LIBRARY NAMES XPMP2)
elseif (UNIX)
find_library(XPMP2_LIBRARY NAMES libXPMP2.a)
elseif (WIN32)
find_library(XPMP2_LIBRARY NAMES XPMP2.lib)
endif ()
target_link_libraries(LiveTraffic ${XPMP2_LIBRARY})

# CURL Library
if (WIN32)
find_library(CURL_LIBRARIES NAMES libcurl.lib)
include_directories("${CMAKE_SOURCE_DIR}/Lib/CURL/libcurl.framework/Versions/Release-7.65.3/Headers")
add_definitions(-DCURL_STATICLIB)
else()
find_package(CURL REQUIRED) # sudo apt-get install curl
include_directories( ${CURL_INCLUDE_DIRS} )
endif()
target_link_libraries( LiveTraffic ${CURL_LIBRARIES} )


# ***********************************************
Expand All @@ -177,7 +157,6 @@ endif( CURL_FOUND )

# Link X-Plane plugin system libraries. They are only provided for OS X and Windows.
if (WIN32 OR APPLE)
# if (WIN32)
find_library(XPLM_LIBRARY NAMES XPLM XPLM_64.lib)
find_library(XPWIDGETS_LIBRARY NAMES XPWidgets XPWidgets_64.lib)
target_link_libraries(LiveTraffic ${XPLM_LIBRARY} ${XPWIDGETS_LIBRARY})
Expand All @@ -194,50 +173,60 @@ endif ()
if (APPLE)
find_library(IOKIT_LIBRARY IOKit)
find_library(CORE_FOUNDATION_LIBRARY CoreFoundation)
find_library(GLUT_LIBRARY GLUT)
find_library(OpenGL_LIBRARY OpenGL)
find_library(SECURITY_LIBRARY Security)
find_library(GSS_LIBRARY GSS)
find_library(Kerberos5_LIBRARY libgssapi_krb5.tbd)
find_library(Cocoa_LIBRARY Cocoa)

target_link_libraries(LiveTraffic ${IOKIT_LIBRARY} ${CORE_FOUNDATION_LIBRARY} ${GLUT_LIBRARY})
target_link_libraries(LiveTraffic ${OpenGL_LIBRARY} ${Cocoa_LIBRARY})
target_link_libraries(LiveTraffic
${IOKIT_LIBRARY}
${CORE_FOUNDATION_LIBRARY}
${SECURITY_LIBRARY}
${GSS_LIBRARY}
${Kerberos5_LIBRARY}
${OpenGL_LIBRARY}
${Cocoa_LIBRARY}
)
endif ()

if (WIN32)
# Unlike OS X and Linux we build standard libraries statically since X-Plane does not provide them.
target_link_libraries(LiveTraffic -static-libgcc -static-libstdc++ opengl32)
# MSYS2 for some reason always links against winpthread, so we have to work around it by statically linking the
# entire plugin. This allows building the plugin nativaly on Windows.
target_link_libraries(LiveTraffic -static)
# Link platform-specific libraries especially for networking
target_link_libraries(LiveTraffic ws2_32.lib wldap32.lib advapi32.lib crypt32.lib)
elseif (APPLE)
# X-Plane supports OS X 10.10+, so this should ensure FlyWithLua can run on
# all supported versions.
target_compile_options(LiveTraffic PUBLIC -mmacosx-version-min=10.11)
target_link_libraries(LiveTraffic -mmacosx-version-min=10.11)

# Restrict set of symbols exported from the plugin. This reduces changes of
# conflict with other plugins, in particular ones with Lua interpreter
# embedded.
target_link_libraries(LiveTraffic "-exported_symbols_list ${CMAKE_SOURCE_DIR}/Src/LiveTraffic.sym_mac")
target_link_libraries(LiveTraffic "-framework XPLM -framework XPWidgets -ldl")
elseif (UNIX)
# Specify additional runtime search laths for dynamically-linked libraries.
# Restrict set of symbols exported from the plugin. This reduces changes of
# conflict with other plugins, in particular ones with Lua interpreter
# embedded.
message(${CMAKE_CURRENT_SOURCE_DIR})
list(APPEND CMAKE_LIBRARY_PATH "${CMAKE_CURRENT_SOURCE_DIR}/Lib/xplanemp")

find_library(XPLANEMP_LIBRARY NAMES libxplanemp.a)
target_link_libraries(LiveTraffic ${XPLANEMP_LIBRARY})

target_link_libraries(LiveTraffic -Wl,--version-script -Wl,${CMAKE_SOURCE_DIR}/Src/LiveTraffic.sym)
endif ()

set_target_properties(LiveTraffic PROPERTIES PREFIX "")
# We need C++ 17
set(CMAKE_CXX_STANDARD 17)
target_compile_features(LiveTraffic PUBLIC cxx_std_17)
set_property(TARGET LiveTraffic PROPERTY CXX_STANDARD_REQUIRED 17)
set_property(TARGET LiveTraffic PROPERTY CXX_STANDARD 17)

# Target directory and file name
if (WIN32)
set_target_properties(LiveTraffic PROPERTIES OUTPUT_NAME "win")
set_target_properties(LiveTraffic PROPERTIES LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/win_x64")
elseif (APPLE)
set_target_properties(LiveTraffic PROPERTIES OUTPUT_NAME "mac")
set_target_properties(LiveTraffic PROPERTIES LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/mac_x64")
elseif (UNIX)
set_target_properties(LiveTraffic PROPERTIES OUTPUT_NAME "lin")
set_target_properties(LiveTraffic PROPERTIES LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lin_x64")
endif ()
set_target_properties(LiveTraffic PROPERTIES SUFFIX ".xpl")

# set_target_properties(LiveTraffic PROPERTIES PREFIX "")
# set_target_properties(LiveTraffic PROPERTIES OUTPUT_NAME "LiveTraffic")
# set_target_properties(LiveTraffic PROPERTIES SUFFIX ".xpl")
set_target_properties(LiveTraffic
PROPERTIES
PREFIX ""
OUTPUT_NAME "LiveTraffic"
SUFFIX ".xpl"
)
70 changes: 70 additions & 0 deletions CMakeSettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
{
"configurations": [
{
"name": "x64-Debug",
"generator": "Ninja",
"configurationType": "Debug",
"inheritEnvironments": [ "msvc_x64_x64" ],
"buildRoot": "${projectDir}\\build-win\\${name}",
"installRoot": "${projectDir}\\build-win\\install\\${name}",
"cmakeCommandArgs": "",
"buildCommandArgs": "-v",
"ctestCommandArgs": "",
"variables": [
{
"name": "CMAKE_CXX_FLAGS",
"value": "/DWIN32 /D_WINDOWS /DWIN32_LEAN_AND_MEAN /D_CRT_SECURE_NO_WARNINGS /GS- /Gd /Gy- /Zc:wchar_t /Zc:forScope /Zc:inline /Zc:__cplusplus /W4 /EHsc /fp:precise /diagnostics:column",
"type": "STRING"
},
{
"name": "CMAKE_CXX_FLAGS_DEBUG",
"value": "/MDd /Od /RTC1 /Zi /DDEBUG",
"type": "STRING"
},
{
"name": "CMAKE_MODULE_LINKER_FLAGS",
"value": "/machine:x64",
"type": "STRING"
},
{
"name": "CMAKE_MODULE_LINKER_FLAGS_DEBUG",
"value": "/debug /INCREMENTAL:NO",
"type": "STRING"
}
]
},
{
"name": "x64-Release",
"generator": "Ninja",
"configurationType": "RelWithDebInfo",
"buildRoot": "${projectDir}\\build-win\\${name}",
"installRoot": "${projectDir}\\build-win\\install\\${name}",
"cmakeCommandArgs": "",
"buildCommandArgs": "-v",
"ctestCommandArgs": "",
"inheritEnvironments": [ "msvc_x64_x64" ],
"variables": [
{
"name": "CMAKE_CXX_FLAGS",
"value": "/DWIN32 /D_WINDOWS /DWIN32_LEAN_AND_MEAN /D_CRT_SECURE_NO_WARNINGS /GS- /Gd /Gy- /Zc:wchar_t /Zc:forScope /Zc:inline /Zc:__cplusplus /W4 /EHsc /fp:precise /diagnostics:column",
"type": "STRING"
},
{
"name": "CMAKE_CXX_FLAGS_RELWITHDEBINFO",
"value": "/MD /Zi /GL /O2 /DNDEBUG",
"type": "STRING"
},
{
"name": "CMAKE_MODULE_LINKER_FLAGS",
"value": "/machine:x64",
"type": "STRING"
},
{
"name": "CMAKE_MODULE_LINKER_FLAGS_RELWITHDEBINFO",
"value": "/LTCG /debug /INCREMENTAL:NO",
"type": "STRING"
}
]
}
]
}
Loading

0 comments on commit 9a5a8c5

Please sign in to comment.