Skip to content

Commit

Permalink
Make OpenSSL work with POSITION_INDEPENDENT_CODE (ruslo#1121)
Browse files Browse the repository at this point in the history
  • Loading branch information
isaachier authored and ruslo committed Oct 27, 2017
1 parent 1c1f821 commit f8260a0
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 7 deletions.
11 changes: 6 additions & 5 deletions cmake/modules/hunter_dump_cmake_flags.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ include(hunter_test_string_not_empty)
# * OpenSSL
# * odb-boost
function(hunter_dump_cmake_flags)
cmake_parse_arguments(x "SKIP_INCLUDES" "CPPFLAGS" "" "${ARGV}")
cmake_parse_arguments(x "SKIP_INCLUDES" "SKIP_PIC" "CPPFLAGS" "" "${ARGV}")
# -> x_SKIP_INCLUDES
# -> x_SKIP_PIC
# -> x_CPPFLAGS

string(COMPARE NOTEQUAL "${x_UNPARSED_ARGUMENTS}" "" has_unparsed)
Expand All @@ -32,11 +33,11 @@ function(hunter_dump_cmake_flags)
set(CMAKE_CXX_FLAGS "-miphoneos-version-min=${IOS_DEPLOYMENT_SDK_VERSION}")
set(CMAKE_C_FLAGS "-miphoneos-version-min=${IOS_DEPLOYMENT_SDK_VERSION}")
endif()

if(CMAKE_XCODE_ATTRIBUTE_ENABLE_BITCODE)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fembed-bitcode")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fembed-bitcode")
endif()
endif()
endif()

set(cppflags "")
Expand Down Expand Up @@ -123,14 +124,14 @@ function(hunter_dump_cmake_flags)

# PIC {
string(COMPARE NOTEQUAL "${CMAKE_CXX_COMPILE_OPTIONS_PIC}" "" has_pic)
if(CMAKE_POSITION_INDEPENDENT_CODE AND has_pic)
if(CMAKE_POSITION_INDEPENDENT_CODE AND has_pic AND NOT x_SKIP_PIC)
set(
CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CMAKE_CXX_COMPILE_OPTIONS_PIC}"
)
endif()

string(COMPARE NOTEQUAL "${CMAKE_C_COMPILE_OPTIONS_PIC}" "" has_pic)
if(CMAKE_POSITION_INDEPENDENT_CODE AND has_pic)
if(CMAKE_POSITION_INDEPENDENT_CODE AND has_pic AND NOT x_SKIP_PIC)
set(
CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${CMAKE_C_COMPILE_OPTIONS_PIC}"
)
Expand Down
2 changes: 1 addition & 1 deletion cmake/projects/OpenSSL/hunter.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -318,4 +318,4 @@ if(MINGW)
endif()

hunter_cacheable(OpenSSL)
hunter_download(PACKAGE_NAME OpenSSL PACKAGE_INTERNAL_DEPS_ID "14")
hunter_download(PACKAGE_NAME OpenSSL PACKAGE_INTERNAL_DEPS_ID "15")
9 changes: 8 additions & 1 deletion cmake/projects/OpenSSL/schemes/url_sha1_openssl.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,14 @@ else()
set(configure_command "./config")
endif()

hunter_dump_cmake_flags(SKIP_INCLUDES)
set(skip_pic "")
if(APPLE)
# Apple cannot process `-fPIC` flag argument
# (https://github.com/ruslo/hunter/pull/1109#discussion_r146360981)
set(skip_pic SKIP_PIC)
endif()

hunter_dump_cmake_flags(SKIP_INCLUDES ${skip_pic})
# -> CMAKE_CXX_FLAGS
# -> CMAKE_C_FLAGS

Expand Down

0 comments on commit f8260a0

Please sign in to comment.