diff --git a/ApplicationExeCode/CMakeLists.txt b/ApplicationExeCode/CMakeLists.txt index 490eaf92f3c..9a2412a379b 100644 --- a/ApplicationExeCode/CMakeLists.txt +++ b/ApplicationExeCode/CMakeLists.txt @@ -229,7 +229,30 @@ if(RESINSIGHT_ENABLE_OPENVDS) add_definitions(-DUSE_OPENVDS) endif() -target_link_libraries(ResInsight PRIVATE ${LINK_LIBRARIES}) +# Link libraries with WHOLE_ARCHIVE for ApplicationLibCode, cafCommandFeatures, Commands, and GrpcInterface +# to ensure static initialization is not optimized away by the linker. +# Other libraries are linked normally. +set(FILTERED_LINK_LIBRARIES ${LINK_LIBRARIES}) +list(REMOVE_ITEM FILTERED_LINK_LIBRARIES ApplicationLibCode cafCommandFeatures Commands GrpcInterface) + +target_link_libraries( + ResInsight + PRIVATE + ${FILTERED_LINK_LIBRARIES} + $ + $ + $ + $<$:$> +) + +# Add RifGeoMechFileInterface after WHOLE_ARCHIVE to resolve link order issues +if(UNIX AND NOT APPLE) + target_link_options(ResInsight PRIVATE "LINKER:--start-group") + target_link_libraries(ResInsight PRIVATE RifGeoMechFileInterface RigGeoMechDataModel) + target_link_options(ResInsight PRIVATE "LINKER:--end-group") +else() + target_link_libraries(ResInsight PRIVATE RifGeoMechFileInterface) +endif() if(UNIX AND NOT APPLE) target_link_libraries(ResInsight PRIVATE xcb) diff --git a/ApplicationLibCode/CMakeLists.txt b/ApplicationLibCode/CMakeLists.txt index 37997cc2564..1a744b9b0b4 100644 --- a/ApplicationLibCode/CMakeLists.txt +++ b/ApplicationLibCode/CMakeLists.txt @@ -220,7 +220,7 @@ list(APPEND ALL_SOURCE_FILES ${CPP_SOURCES} ${MOC_SOURCE_FILES} ${FORM_FILES_CPP} ${QRC_FILES} ) -add_library(${PROJECT_NAME} OBJECT ${ALL_SOURCE_FILES}) +add_library(${PROJECT_NAME} STATIC ${ALL_SOURCE_FILES}) option(RESINSIGHT_ENABLE_DYNAMIC_DEOPTIMALIZATION "Ensable Dynamic Deoptimalization" OFF diff --git a/ApplicationLibCode/Commands/CMakeLists.txt b/ApplicationLibCode/Commands/CMakeLists.txt index 0ecee04926b..21fa44bbbaf 100644 --- a/ApplicationLibCode/Commands/CMakeLists.txt +++ b/ApplicationLibCode/Commands/CMakeLists.txt @@ -74,7 +74,7 @@ endforeach(referencedfile) find_package(Eigen3 REQUIRED) add_library( - ${PROJECT_NAME} OBJECT + ${PROJECT_NAME} STATIC ${COMMAND_CODE_SOURCE_FILES} ${COMMAND_CODE_HEADER_FILES} ${COMMAND_MOC_SOURCE_FILES} ) @@ -91,6 +91,8 @@ endif() target_include_directories( ${PROJECT_NAME} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/EclipseCommands + $ + $ ) if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang") @@ -135,7 +137,8 @@ if(MSVC) endif() -set(LINK_LIBRARIES ApplicationLibCode ResultStatisticsCache +set(LINK_LIBRARIES # ApplicationLibCode removed - linked with WHOLE_ARCHIVE in executables + ResultStatisticsCache ResInsightCommonSettings ) target_link_libraries(Commands PRIVATE ${LINK_LIBRARIES}) diff --git a/ApplicationLibCode/GeoMech/GeoMechDataModel/CMakeLists.txt b/ApplicationLibCode/GeoMech/GeoMechDataModel/CMakeLists.txt index aac48d14e59..2b5f0d29159 100644 --- a/ApplicationLibCode/GeoMech/GeoMechDataModel/CMakeLists.txt +++ b/ApplicationLibCode/GeoMech/GeoMechDataModel/CMakeLists.txt @@ -110,7 +110,8 @@ add_library( RigFemAddressDefines.cpp ) -target_include_directories(${PROJECT_NAME} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}) +target_include_directories(${PROJECT_NAME} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE $) target_link_libraries( RigGeoMechDataModel PUBLIC LibCore cafPdmCvf cafTensor cafUserInterface diff --git a/ApplicationLibCode/GeoMech/GeoMechFileInterface/CMakeLists.txt b/ApplicationLibCode/GeoMech/GeoMechFileInterface/CMakeLists.txt index 62346d4090d..f42956d252e 100644 --- a/ApplicationLibCode/GeoMech/GeoMechFileInterface/CMakeLists.txt +++ b/ApplicationLibCode/GeoMech/GeoMechFileInterface/CMakeLists.txt @@ -18,7 +18,8 @@ add_library( RifVtkReader.cpp ) -target_include_directories(${PROJECT_NAME} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}) +target_include_directories(${PROJECT_NAME} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE $) target_link_libraries( RifGeoMechFileInterface PUBLIC RigGeoMechDataModel LibCore diff --git a/ApplicationLibCode/ModelVisualization/Faults/RivReservoirFaultsPartMgr.cpp b/ApplicationLibCode/ModelVisualization/Faults/RivReservoirFaultsPartMgr.cpp index a529abf3f16..0bda63b9234 100644 --- a/ApplicationLibCode/ModelVisualization/Faults/RivReservoirFaultsPartMgr.cpp +++ b/ApplicationLibCode/ModelVisualization/Faults/RivReservoirFaultsPartMgr.cpp @@ -245,8 +245,7 @@ void RivReservoirFaultsPartMgr::updateColors( size_t timeStepIndex, RimEclipseCe { if ( !m_reservoirView ) return; - RimFaultInViewCollection* faultCollection = m_reservoirView->faultCollection(); - CVF_ASSERT( faultCollection ); + CVF_ASSERT( m_reservoirView->faultCollection() ); for ( auto& faultPart : m_faultParts ) { diff --git a/ApplicationLibCode/ResultStatisticsCache/CMakeLists.txt b/ApplicationLibCode/ResultStatisticsCache/CMakeLists.txt index 121aae877b4..2f544cced15 100644 --- a/ApplicationLibCode/ResultStatisticsCache/CMakeLists.txt +++ b/ApplicationLibCode/ResultStatisticsCache/CMakeLists.txt @@ -7,6 +7,8 @@ add_library( RigStatisticsMath.cpp ) -target_include_directories(${PROJECT_NAME} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}) +target_include_directories(${PROJECT_NAME} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE $) -target_link_libraries(${PROJECT_NAME} LibCore ApplicationLibCode) +target_link_libraries(${PROJECT_NAME} PRIVATE LibCore) +# ApplicationLibCode removed - linked with WHOLE_ARCHIVE in executables diff --git a/ApplicationLibCode/UnitTests/CMakeLists.txt b/ApplicationLibCode/UnitTests/CMakeLists.txt index e9ebcf2d1d2..2b3889960bc 100644 --- a/ApplicationLibCode/UnitTests/CMakeLists.txt +++ b/ApplicationLibCode/UnitTests/CMakeLists.txt @@ -233,7 +233,22 @@ if(RESINSIGHT_USE_ODB_API) list(APPEND LINK_LIBRARIES RifOdbReader) endif() -target_link_libraries(ResInsight-tests PUBLIC ${LINK_LIBRARIES} GTest::gtest) +# Link libraries with WHOLE_ARCHIVE for ApplicationLibCode, cafCommandFeatures, Commands, and GrpcInterface +# to ensure static initialization is not optimized away by the linker. +# Other libraries are linked normally. +set(FILTERED_LINK_LIBRARIES ${LINK_LIBRARIES}) +list(REMOVE_ITEM FILTERED_LINK_LIBRARIES ApplicationLibCode cafCommandFeatures Commands GrpcInterface) + +target_link_libraries( + ResInsight-tests + PUBLIC + ${FILTERED_LINK_LIBRARIES} + GTest::gtest + $ + $ + $ + $<$:$> +) if(MSVC) add_custom_command( diff --git a/CMakeLists.txt b/CMakeLists.txt index 434f3532e7b..0646ea6a072 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -977,7 +977,7 @@ list( CommonCode cafVizExtensions cafPdmScripting - cafCommandFeatures + # cafCommandFeatures removed - linked with WHOLE_ARCHIVE in executables ) set_property(TARGET ${APP_FWK_LIBRARIES} PROPERTY FOLDER "AppFwk") diff --git a/Fwk/AppFwk/cafCommandFeatures/CMakeLists.txt b/Fwk/AppFwk/cafCommandFeatures/CMakeLists.txt index de9b8c8c392..9b8e1eba85e 100644 --- a/Fwk/AppFwk/cafCommandFeatures/CMakeLists.txt +++ b/Fwk/AppFwk/cafCommandFeatures/CMakeLists.txt @@ -53,18 +53,18 @@ set(QRC_FILES PARENT_SCOPE ) -# NOTE! Adding the library as a cmake "OBJECT" library to make sure the linker -# is not pruning the seemingly unused features, and to make sure that the static -# initialization based registration of the features into the factory is done -# properly see -# https://gitlab.kitware.com/cmake/community/wikis/doc/tutorials/Object-Library -# and -# https://cmake.org/cmake/help/v3.15/command/add_library.html?highlight=add_library#object-libraries +# NOTE! Adding the library as a cmake "STATIC" library. To ensure the linker +# doesn't prune seemingly unused features and that static initialization based +# registration of features into the factory is done properly, MSVC uses +# /WHOLEARCHIVE and GCC/Clang use --whole-archive linker flags. See +# https://cmake.org/cmake/help/latest/command/add_library.html -add_library(${PROJECT_NAME} OBJECT ${PROJECT_FILES} ${MOC_SOURCE_FILES}) +add_library(${PROJECT_NAME} STATIC ${PROJECT_FILES} ${MOC_SOURCE_FILES}) + +target_include_directories(${PROJECT_NAME} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}) target_link_libraries( - ${PROJECT_NAME} cafCommand cafUserInterface ${QT_LIBRARIES} + ${PROJECT_NAME} PRIVATE cafCommand cafUserInterface ${QT_LIBRARIES} ) if(MSVC) diff --git a/Fwk/AppFwk/cafTests/cafTestApplication/CMakeLists.txt b/Fwk/AppFwk/cafTests/cafTestApplication/CMakeLists.txt index 1ab7147d7a1..e1bc4a1e056 100644 --- a/Fwk/AppFwk/cafTests/cafTestApplication/CMakeLists.txt +++ b/Fwk/AppFwk/cafTests/cafTestApplication/CMakeLists.txt @@ -52,17 +52,13 @@ set(PROJECT_FILES qt_add_executable( ${PROJECT_NAME} ${PROJECT_FILES} ${MOC_SOURCE_FILES} ${QRC_FILES} - $ # Needed for cmake version < 3.12. Remove - # when we can use target_link_libraries with OBJECT libraries ) set(TAP_LINK_LIBRARIES cafUserInterface) if(USE_COMMAND_FRAMEWORK) - set(TAP_LINK_LIBRARIES - ${TAP_LINK_LIBRARIES} cafCommand - # cafCommandFeatures # Not possible using cmake version < 3.12. Use when - # we can use target_link_libraries with OBJECT libraries + set(TAP_LINK_LIBRARIES ${TAP_LINK_LIBRARIES} cafCommand + $ ) endif(USE_COMMAND_FRAMEWORK) diff --git a/GrpcInterface/CMakeLists.txt b/GrpcInterface/CMakeLists.txt index 703bc9ca7cd..2c82586d604 100644 --- a/GrpcInterface/CMakeLists.txt +++ b/GrpcInterface/CMakeLists.txt @@ -124,10 +124,10 @@ set(_LINK_LIBRARIES LibCore CommonCode cafCommand - cafCommandFeatures + # cafCommandFeatures and ApplicationLibCode removed - linked with WHOLE_ARCHIVE in executables cafProjectDataModel cafPdmScripting - ApplicationLibCode) + ) # Proto files file(GLOB GRPC_PROTO_FILES GrpcProtos/*.proto) @@ -219,7 +219,7 @@ list( list(APPEND GRPC_PYTHON_SOURCES ${GRPC_PYTHON_GENERATED_SOURCES}) add_library( - ${PROJECT_NAME} OBJECT + ${PROJECT_NAME} STATIC ${SOURCE_GROUP_HEADER_FILES} ${SOURCE_GROUP_SOURCE_FILES} ${GRPC_HEADER_FILES} ${GRPC_CPP_SOURCES}) @@ -228,6 +228,7 @@ target_include_directories(${PROJECT_NAME} PUBLIC PRIVATE ${GRPC_INCLUDE_DIRS} ${CMAKE_BINARY_DIR}/Generated + $ ) target_link_libraries(${PROJECT_NAME} PRIVATE ${_LINK_LIBRARIES}) diff --git a/ThirdParty/openzgy b/ThirdParty/openzgy index 5babbb8937b..0b7a2dd6365 160000 --- a/ThirdParty/openzgy +++ b/ThirdParty/openzgy @@ -1 +1 @@ -Subproject commit 5babbb8937bb9914a846951ada561714d021952a +Subproject commit 0b7a2dd6365805ec1b984d0aa93fd17516de76dd