From 346344ee09a6c21852f8f20457bdbd80e2481fd5 Mon Sep 17 00:00:00 2001 From: James Turner Date: Sun, 21 Jun 2020 19:31:35 +0100 Subject: [PATCH] C++17: use an OBJECT_LIBRARY to build HLA This allows us to easily have different CXX version for the HLA code, to the rest of the project. --- CMakeLists.txt | 14 ++------------ SimGearConfig.cmake.in | 10 +++++----- simgear/CMakeLists.txt | 25 +++++++++++-------------- simgear/hla/CMakeLists.txt | 23 +++++++++++++++++++++-- 4 files changed, 39 insertions(+), 33 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 54d9901c..f0c6fe08 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -213,7 +213,7 @@ if(${CMAKE_SYSTEM_NAME} MATCHES "Linux" OR ${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD endif() find_package(Boost REQUIRED) -set (BOOST_CXX_FLAGS "-DBOOST_BIMAP_DISABLE_SERIALIZATION -DBOOST_NO_STDLIB_CONFIG") +set (BOOST_CXX_FLAGS "-DBOOST_BIMAP_DISABLE_SERIALIZATION -DBOOST_NO_STDLIB_CONFIG -DBOOST_NO_AUTO_PTR -DBOOST_NO_CXX98_BINDERS") include(BoostTestTargets) if(SIMGEAR_HEADLESS) @@ -287,7 +287,7 @@ if(ENABLE_RTI) find_package(PkgConfig) if(PKG_CONFIG_FOUND) SET(ENV{PKG_CONFIG_PATH} "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}/pkgconfig:$ENV{PKG_CONFIG_PATH}") - pkg_check_modules(RTI hla-rti13) + pkg_check_modules(RTI IMPORTED_TARGET hla-rti13) endif(PKG_CONFIG_FOUND) if(RTI_FOUND) message(STATUS "RTI: ENABLED") @@ -360,16 +360,6 @@ SET(CMAKE_RELEASE_POSTFIX "" CACHE STRING "add a postfix, usually empty on windo SET(CMAKE_RELWITHDEBINFO_POSTFIX "" CACHE STRING "add a postfix, usually empty on windows") SET(CMAKE_MINSIZEREL_POSTFIX "" CACHE STRING "add a postfix, usually empty on windows") -# isnan might not be real symbol, so can't check using function_exists -check_cxx_source_compiles( - "#include - int main() { return std::isnan(0.0);} " - HAVE_STD_ISNAN) - -if (NOT ${HAVE_STD_ISNAN}) - message(FATAL_ERROR "Your compiler lacks C++11 std::isnan, please update it") -endif() - # Check if the implementation in the C++ standard library is usable. # This is necessary because g++ 4.8 lies about its C++11 compliance: its # is utterly unusable, cf. [1]. diff --git a/SimGearConfig.cmake.in b/SimGearConfig.cmake.in index 3b51d4d6..8327cf9c 100644 --- a/SimGearConfig.cmake.in +++ b/SimGearConfig.cmake.in @@ -2,6 +2,7 @@ include(CMakeFindDependencyMacro) find_dependency(ZLIB) find_dependency(Threads) +find_dependency(CURL) # OSG @@ -21,11 +22,10 @@ set(ENABLE_SIMD @ENABLE_SIMD@) # OpenRTI support set(ENABLE_RTI @ENABLE_RTI@) if(ENABLE_RTI) - set(RTI_FOUND @RTI_FOUND@) - if(RTI_FOUND) - set(RTI_INCLUDE_DIRS @RTI_INCLUDE_DIRS@) - set(RTI_LDFLAGS @RTI_LDFLAGS@) - endif(RTI_FOUND) + find_dependency(PkgConfig) + if(PKG_CONFIG_FOUND) + pkg_check_modules(RTI IMPORTED_TARGET hla-rti13) + endif(PKG_CONFIG_FOUND) endif(ENABLE_RTI) # Alternative terrain engine based on pagedLOD diff --git a/simgear/CMakeLists.txt b/simgear/CMakeLists.txt index 8162cea3..aee895a2 100644 --- a/simgear/CMakeLists.txt +++ b/simgear/CMakeLists.txt @@ -124,9 +124,9 @@ target_include_directories(SimGearCore BEFORE PUBLIC $) target_include_directories(SimGearCore PUBLIC - ${Boost_INCLUDE_DIRS} ${ZLIB_INCLUDE_DIR}) + ${Boost_INCLUDE_DIRS}) target_include_directories(SimGearCore PRIVATE - ${EXPAT_INCLUDE_DIRS} ${CURL_INCLUDE_DIRS}) + ${EXPAT_INCLUDE_DIRS} ) if (NOT SYSTEM_EXPAT) # XML_STATIC is important to avoid sg_expat_external.h @@ -159,14 +159,19 @@ if (NOT SIMGEAR_HEADLESS) endif() # we expose ZLib in some of our headers -target_link_libraries(SimGearCore PUBLIC ${ZLIB_LIBRARY}) +target_link_libraries(SimGearCore PUBLIC ZLIB::ZLIB) + +if (ENABLE_RTI) + target_sources(SimGearCore PRIVATE $ $) + target_link_libraries(SimGearCore PRIVATE PkgConfig::RTI) +endif() target_link_libraries(SimGearCore PRIVATE ${RT_LIBRARY} ${DL_LIBRARY} ${CMAKE_THREAD_LIBS_INIT} ${COCOA_LIBRARY} - ${CURL_LIBRARIES} + CURL::libcurl ${WINSOCK_LIBRARY}) if(SYSTEM_EXPAT) @@ -186,7 +191,7 @@ if(NOT SIMGEAR_HEADLESS) ) target_link_libraries(SimGearScene PRIVATE - ${ZLIB_LIBRARY} + ZLIB::ZLIB ${OPENAL_LIBRARY} ${OPENGL_LIBRARY} ${JPEG_LIBRARY}) @@ -197,12 +202,4 @@ if(NOT SIMGEAR_HEADLESS) # only actually needed by canvas/KeyboardEvent.cxx target_include_directories(SimGearScene PRIVATE ${PROJECT_SOURCE_DIR}/3rdparty/utf8/source) -endif() - -if(ENABLE_RTI) - # Ugly first aid to make hla compile agian - set_property(SOURCE hla/RTI13InteractionClass.cxx hla/RTI13ObjectClass.cxx - hla/RTI13ObjectInstance.cxx hla/RTI13Federate.cxx - hla/RTI13FederateFactory.cxx - APPEND PROPERTY COMPILE_FLAGS "-I${RTI_INCLUDE_DIRS}") -endif(ENABLE_RTI) +endif() \ No newline at end of file diff --git a/simgear/hla/CMakeLists.txt b/simgear/hla/CMakeLists.txt index 4e97253d..181c96d1 100644 --- a/simgear/hla/CMakeLists.txt +++ b/simgear/hla/CMakeLists.txt @@ -50,6 +50,7 @@ set(HLA_SOURCES HLAVariantRecordDataElement.cxx HLAVariantRecordDataType.cxx ) + simgear_component(hla hla "${HLA_SOURCES}" "${HLA_HEADERS}") if(RTI_FOUND) @@ -60,7 +61,16 @@ if(RTI_FOUND) RTI13Federate.cxx RTI13FederateFactory.cxx ) - simgear_component(rti13 hla "${RTI13_SOURCES}" "") + + add_library(rti13 OBJECT ${RTI13_SOURCES}) + + target_include_directories(rti13 PUBLIC ${PROJECT_SOURCE_DIR}) + target_include_directories(rti13 PUBLIC ${PROJECT_BINARY_DIR}) + #target_include_directories(rti13 PRIVATE ${RTI_INCLUDE_DIRS}) + target_link_libraries(rti13 PRIVATE PkgConfig::RTI) + + set_property(TARGET rti13 PROPERTY CXX_STANDARD 11) + #simgear_component(rti13 hla "${RTI13_SOURCES}" "") endif() set(RTI_SOURCES @@ -71,4 +81,13 @@ set(RTI_SOURCES RTIFederateFactory.cxx RTIFederateFactoryRegistry.cxx ) -simgear_component(rti hla "${RTI_SOURCES}" "") + + add_library(rti OBJECT ${RTI_SOURCES}) + target_include_directories(rti PUBLIC ${PROJECT_SOURCE_DIR}) + target_include_directories(rti PUBLIC ${PROJECT_BINARY_DIR}) + #target_include_directories(rti PRIVATE ${RTI_INCLUDE_DIRS}) + target_link_libraries(rti PRIVATE PkgConfig::RTI) + + set_property(TARGET rti PROPERTY CXX_STANDARD 11) + +#simgear_component(rti hla "${RTI_SOURCES}" "")