Fix Apple Clang weak symbols warnings

Change-Id: I71eba56ca37060c83d05ff14d6f9bfaef61e9493
This commit is contained in:
Sergiu Deitsch
2022-02-15 20:32:06 +01:00
parent 8e08421628
commit 99698f0535
3 changed files with 23 additions and 82 deletions
+15
View File
@@ -92,6 +92,21 @@ endif()
project(Ceres C CXX)
# NOTE: The following CMake variables must be applied consistently to all
# targets in project to avoid visibility warnings by placing the variables at
# the project top.
# Always build position-independent code (PIC), even when building Ceres as a
# static library so that shared libraries can link against it, not just
# executables (PIC does not apply on Windows). Global variable can be overridden
# by the user whereas target properties can be not.
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
# Set the default symbol visibility to hidden to unify the behavior among
# the various compilers and to get smaller binaries
set(CMAKE_C_VISIBILITY_PRESET hidden)
set(CMAKE_CXX_VISIBILITY_PRESET hidden)
set(CMAKE_VISIBILITY_INLINES_HIDDEN ON)
# NOTE: The 'generic' CMake variables CMAKE_[SOURCE/BINARY]_DIR should not be
# used. Always use the project-specific variants (generated by CMake):
# <PROJECT_NAME_MATCHING_CASE>_[SOURCE/BINARY]_DIR, e.g.
-61
View File
@@ -1,61 +0,0 @@
# Ceres Solver - A fast non-linear least squares minimizer
# Copyright 2015 Google Inc. All rights reserved.
# http://ceres-solver.org/
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# * Redistributions of source code must retain the above copyright notice,
# this list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
# * Neither the name of Google Inc. nor the names of its contributors may be
# used to endorse or promote products derived from this software without
# specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
#
# Author: alexs.mac@gmail.com (Alex Stewart)
# Append item(s) to a property on a declared CMake target:
#
# append_target_property(target property item_to_append1
# [... item_to_appendN])
#
# The set_target_properties() CMake function will overwrite the contents of the
# specified target property. This function instead appends to it, so can
# be called multiple times with the same target & property to iteratively
# populate it.
function(append_target_property TARGET PROPERTY)
if (NOT TARGET ${TARGET})
message(FATAL_ERROR "Invalid target: ${TARGET} cannot append: ${ARGN} "
"to property: ${PROPERTY}")
endif()
if (NOT PROPERTY)
message(FATAL_ERROR "Invalid property to update for target: ${TARGET}")
endif()
# Get the initial state of the specified property for the target s/t
# we can append to it (not overwrite it).
get_target_property(INITIAL_PROPERTY_STATE ${TARGET} ${PROPERTY})
if (NOT INITIAL_PROPERTY_STATE)
# Ensure that if the state is unset, we do not insert the XXX-NOTFOUND
# returned by CMake into the property.
set(INITIAL_PROPERTY_STATE "")
endif()
# Delistify (remove ; separators) the potentially set of items to append
# to the specified target property.
string(REPLACE ";" " " ITEMS_TO_APPEND "${ARGN}")
set_target_properties(${TARGET} PROPERTIES ${PROPERTY}
"${INITIAL_PROPERTY_STATE} ${ITEMS_TO_APPEND}")
endfunction()
+8 -21
View File
@@ -28,17 +28,6 @@
#
# Author: keir@google.com (Keir Mierle)
# Always build position-independent code (PIC), even when building Ceres as a
# static library so that shared libraries can link against it, not just
# executables (PIC does not apply on Windows). Global variable can be overridden
# by the user whereas target properties can be not.
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
# Set the default symbol visibility to hidden to unify the behavior among
# the various compilers and to get smaller binaries
set(CMAKE_C_VISIBILITY_PRESET hidden)
set(CMAKE_CXX_VISIBILITY_PRESET hidden)
set(CMAKE_VISIBILITY_INLINES_HIDDEN ON)
# Avoid 'xxx.cc has no symbols' warnings from source files which are 'empty'
# when their enclosing #ifdefs are disabled.
if (CERES_THREADING_MODEL STREQUAL "CXX_THREADS")
@@ -420,15 +409,18 @@ if (BUILD_TESTING AND GFLAGS)
target_include_directories(test_util PUBLIC ${Ceres_SOURCE_DIR}/internal)
target_link_libraries (test_util PUBLIC ceres_static gflags)
include(AppendTargetProperty)
add_library(gtest gmock_gtest_all.cc gmock_main.cc)
if (BUILD_SHARED_LIBS)
# Define gtest-specific shared library flags for compilation.
append_target_property(gtest COMPILE_DEFINITIONS
GTEST_CREATE_SHARED_LIBRARY)
#
# NOTE: We export the test_srcdir flag not from gflags but from our gtest
# target. Therefore, the gflags visibility macro must be overriden by that
# of gtest.
target_compile_definitions(gtest
PRIVATE GTEST_CREATE_SHARED_LIBRARY=1
GFLAGS_DLL_DEFINE_FLAG=GTEST_API_
INTERFACE GTEST_LINKED_AS_SHARED_LIBRARY=1)
endif()
set_target_properties (gtest PROPERTIES CXX_VISIBILITY_PRESET default)
target_include_directories(gtest PRIVATE ${Ceres_SOURCE_DIR}/internal/ceres)
target_link_libraries(gtest PRIVATE Ceres::ceres gflags)
@@ -443,11 +435,6 @@ if (BUILD_TESTING AND GFLAGS)
PRIVATE ${Ceres_SOURCE_DIR}/internal/ceres
${CERES_LIBRARY_PRIVATE_DEPENDENCIES_INCLUDE_DIRS})
target_link_libraries(${NAME}_test PRIVATE gtest test_util ceres_static)
if (BUILD_SHARED_LIBS)
# Define gtest-specific shared library flags for linking.
append_target_property(${NAME}_test COMPILE_DEFINITIONS
GTEST_LINKED_AS_SHARED_LIBRARY)
endif()
add_test(NAME ${NAME}_test
COMMAND ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${NAME}_test
--test_srcdir