Skip to content

Commit

Permalink
Merge pull request #213 from TwinFan/Next
Browse files Browse the repository at this point in the history
v2.50
  • Loading branch information
TwinFan authored Feb 21, 2021
2 parents 43a3d4c + 4ce70a6 commit dba5f74
Show file tree
Hide file tree
Showing 87 changed files with 2,118 additions and 39,378 deletions.
7 changes: 2 additions & 5 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
.DS_Store
.localized
.image
.image*
.vs/
.vscode/

# Build directories
build/
build-lin/
build-win/
build-mac/
build*/

# Generated documentation
docs/html/
Expand Down
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"cmake.configureOnOpen": false
}
221 changes: 121 additions & 100 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,53 +1,97 @@
# 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)
# LiveTraffic - Set up to be used in the provided docker environment to build lin, mac, and win

cmake_minimum_required(VERSION 3.16)
project(LiveTraffic VERSION 2.20 DESCRIPTION "LiveTraffic X-Plane plugin" LANGUAGES C CXX)
project(LiveTraffic
VERSION 2.41
DESCRIPTION "LiveTraffic X-Plane plugin")

# 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 ()
################################################################################
# Target Systems
################################################################################

# Set include directories used by our code and dependencies.
include_directories("${CMAKE_SOURCE_DIR}/Include")
include_directories("${CMAKE_SOURCE_DIR}/Lib/parson")
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/SDK/CHeaders/XPLM")
include_directories("${CMAKE_SOURCE_DIR}/Lib/ImGui")
include_directories("${CMAKE_SOURCE_DIR}/Lib/ImGui/misc/cpp")
include_directories("${CMAKE_SOURCE_DIR}/Lib/ImgWindow")
include_directories("${CMAKE_SOURCE_DIR}/Lib/Font")
# Windows: Target Windows 7.0 and later
if (WIN32)
add_compile_definitions(_WIN32_WINNT=0x0601)
if (NOT DEFINED ENV{platform})
set(ENV{platform} "win")
endif()
elseif(APPLE)
add_compile_options(-mmacosx-version-min=10.11)
add_link_options(-mmacosx-version-min=10.11)
endif()

# Enable all necessary X-Plane SDK APIs
add_definitions(-DXPLM200=1 -DXPLM210=1 -DXPLM300=1 -DXPLM301=1 -DXPLM303=1)
################################################################################
# C++ Standard required
################################################################################

set(CMAKE_CXX_STANDARD 17)
set_property(GLOBAL PROPERTY CXX_STANDARD_REQUIRED 17)
set_property(GLOBAL PROPERTY CXX_STANDARD 17)

################################################################################
# Compile Options
################################################################################

# Enable all X-Plane SDK APIs up to the newest version.
add_compile_definitions(XPLM200=1 XPLM210=1 XPLM300=1 XPLM301=1 XPLM303=1)

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

# Enable stricter warnings and then disable some we are not interested in.
if (MSVC)
# Deprecation warning: once is enough
add_compile_options(/wo4996)
else()
add_compile_options(-Wall -Wshadow -Wfloat-equal -Wextra)
if (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 9.0 AND NOT APPLE)
add_compile_options(-Wno-stringop-truncation)
endif()

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)
add_compile_options(-fexceptions)

# On UNIX systems this makes symbols non-exported by default. On Windows this
# option is simply ignored, since symbol visibility works differently there.
# Makes symbols non-exported by default.
add_compile_options(-fvisibility=hidden)
endif()

# 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)
# Debug vs Release build
if(CMAKE_BUILD_TYPE MATCHES "Debug")
add_compile_definitions(DEBUG=1)
if (MSVC)
add_compile_options(/Zi)
else()
add_compile_options(-O0 -g)
endif()
else()
add_compile_definitions(NDEBUG=1)
if(MSVC)
# Use highest optimization level in Release builds
add_compile_options(/GL)
elseif(APPLE)
add_compile_options(-O3 -fPIC)
elseif (UNIX OR MINGW)
# Use position-independent code and highest optimization level (FPS!).
add_compile_options(-O3 -fPIC)
# Strip symbols during linking
add_link_options(-s)
endif()
endif()

# Set include directories used by our code and dependencies.
include_directories("${CMAKE_SOURCE_DIR}/Include")
include_directories("${CMAKE_SOURCE_DIR}/Lib/parson")
include_directories("${CMAKE_SOURCE_DIR}/Lib/XPMP2/XPMP2.framework/Versions/Current/Headers")
include_directories("${CMAKE_SOURCE_DIR}/Lib/LTAPI")
include_directories("${CMAKE_SOURCE_DIR}/Lib/SDK/CHeaders/XPLM")
include_directories("${CMAKE_SOURCE_DIR}/Lib/ImGui")
include_directories("${CMAKE_SOURCE_DIR}/Lib/ImGui/misc/cpp")
include_directories("${CMAKE_SOURCE_DIR}/Lib/ImgWindow")
include_directories("${CMAKE_SOURCE_DIR}/Lib/Font")

################################################################################
# Source groups
################################################################################
Expand Down Expand Up @@ -87,9 +131,9 @@ set(Header_Files
Lib/ImgWindow/SystemGL.h
Lib/Font/IconsFontAwesome5.h
Lib/Font/fa-solid-900.inc
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
Lib/XPMP2/XPMP2.framework/Versions/Current/Headers/XPCAircraft.h
Lib/XPMP2/XPMP2.framework/Versions/Current/Headers/XPMPMultiplayer.h
Lib/XPMP2/XPMP2.framework/Versions/Current/Headers/XPMPPlaneRenderer.h
)
source_group("Header Files" FILES ${Header_Files})

Expand Down Expand Up @@ -164,45 +208,37 @@ PROPERTIES

# Specify library search locations.
if (APPLE)
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/SDK/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/XPMP2/$ENV{platform}")
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/XPMP2/$ENV{platform}")
list(APPEND CMAKE_LIBRARY_PATH "${CMAKE_CURRENT_SOURCE_DIR}/Lib/SDK/Libraries/Win")
endif ()

# 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 ()
# Link the XPMP2 library
find_library(XPMP2_LIBRARY XPMP2 REQUIRED)
message (" XPMP2_LIBRARY = ${XPMP2_LIBRARY}")
target_link_libraries(LiveTraffic ${XPMP2_LIBRARY})

# CURL Library
# Link libcurl
find_package(CURL REQUIRED)
message(" CURL_INCLUDE_DIRS = ${CURL_INCLUDE_DIRS}")
message(" CURL_LIBRARIES = ${CURL_LIBRARIES}")
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()
# We have built a static up-to-date version of CURL just for ourselves, compile/link it statically
add_compile_definitions(CURL_STATICLIB)
endif ()
include_directories( ${CURL_INCLUDE_DIRS} )
target_link_libraries( LiveTraffic ${CURL_LIBRARIES} )

# Link OpenGL and OpenAL related libraries.
set (OpenGL_GL_PREFERENCE GLVND)
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 )
include_directories( ${OpenGL_INCLUDE_DIRS} )
target_link_libraries( LiveTraffic ${OpenGL_LIBRARIES} )

# Link X-Plane plugin system libraries. They are only provided for OS X and Windows.
if (WIN32 OR APPLE)
Expand All @@ -211,58 +247,43 @@ if (WIN32 OR APPLE)
endif ()


# Link library for dynamic loading of shared objects on UNIX systems.
if (UNIX)
find_library(DL_LIBRARY dl)
target_link_libraries(LiveTraffic ${DL_LIBRARY})
endif ()

# Link OS X core system libraries.
if (APPLE)
find_library(APPLICATION_SERVICES ApplicationServices)
find_library(CORE_FOUNDATION_LIBRARY CoreFoundation)
find_library(SECURITY_LIBRARY Security)
find_library(GSS_LIBRARY GSS)
find_library(Kerberos5_LIBRARY libgssapi_krb5.tbd)
find_library(Cocoa_LIBRARY Cocoa)

if (WIN32)
# Link platform-specific libraries especially for networking
target_link_libraries(LiveTraffic ws2_32.lib iphlpapi wldap32.lib advapi32.lib crypt32.lib)
if (MINGW)
# When cross-compiling we link the standard libraries statically
target_link_options(LiveTraffic PRIVATE -static-libgcc -static-libstdc++)
endif()
elseif (APPLE)
# Link OS X core system libraries.
find_library(CORE_FOUNDATION_LIBRARY CoreFoundation REQUIRED)
find_library(Cocoa_LIBRARY Cocoa REQUIRED)
find_library(Security_LIBRARY Security REQUIRED)
find_library(GSS_LIBRARY GSS REQUIRED)
find_library(OpenGL_LIBRARY OpenGL REQUIRED)
target_link_libraries(LiveTraffic
${APPLICATION_SERVICES}
${CORE_FOUNDATION_LIBRARY}
${SECURITY_LIBRARY}
${Cocoa_LIBRARY}
${Security_LIBRARY}
${GSS_LIBRARY}
${Kerberos5_LIBRARY}
${OpenGL_LIBRARY}
${Cocoa_LIBRARY}
)
endif ()

if (WIN32)
# Link platform-specific libraries especially for networking
target_link_libraries(LiveTraffic ws2_32.lib iphlpapi 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.
# Restrict set of symbols exported from the plugin to the ones required by XPLM:
target_link_libraries(LiveTraffic "-exported_symbols_list ${CMAKE_SOURCE_DIR}/Src/LiveTraffic.sym_mac")
elseif (UNIX)
# Restrict set of symbols exported from the plugin. This reduces changes of
# conflict with other plugins, in particular ones with Lua interpreter
# embedded.
# Link library for dynamic loading of shared objects on UNIX systems.
find_library(DL_LIBRARY dl REQUIRED)
# Threads
set(CMAKE_THREAD_PREFER_PTHREAD TRUE)
set(THREADS_PREFER_PTHREAD_FLAG TRUE)
find_package(Threads REQUIRED)
target_link_libraries(LiveTraffic ${DL_LIBRARY} Threads::Threads)
# Specify additional runtime search paths for dynamically-linked libraries.
# Restrict set of symbols exported from the plugin to the ones required by XPLM:
target_link_libraries(LiveTraffic -Wl,--version-script -Wl,${CMAKE_SOURCE_DIR}/Src/LiveTraffic.sym)
endif ()

# 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 LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/win_x64")
Expand Down
Loading

0 comments on commit dba5f74

Please sign in to comment.