Skip to content

Commit

Permalink
update(cmake): propagate position-independent code option to dependen…
Browse files Browse the repository at this point in the history
…cies

Signed-off-by: Jason Dellaluce <[email protected]>
  • Loading branch information
jasondellaluce committed May 28, 2024
1 parent 00b4d19 commit 844ff42
Show file tree
Hide file tree
Showing 10 changed files with 50 additions and 6 deletions.
8 changes: 7 additions & 1 deletion cmake/modules/cares.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,18 @@ else()
set(CARES_INSTALL_DIR "${CARES_SRC}/target")

if(NOT TARGET c-ares)
if(NOT ENABLE_PIC)
set(CARES_PIC_OPTION )
else()
set(CARES_PIC_OPTION "--with-pic=yes")
endif()

message(STATUS "Using bundled c-ares in '${CARES_SRC}'")
ExternalProject_Add(c-ares
PREFIX "${PROJECT_BINARY_DIR}/c-ares-prefix"
URL "https://c-ares.haxx.se/download/c-ares-1.19.1.tar.gz"
URL_HASH "SHA256=321700399b72ed0e037d0074c629e7741f6b2ec2dda92956abe3e9671d3e268e"
CONFIGURE_COMMAND CPPFLAGS=${CARES_CPPFLAGS} ./configure ${CARES_STATIC_OPTION} --prefix=${CARES_INSTALL_DIR}
CONFIGURE_COMMAND CPPFLAGS=${CARES_CPPFLAGS} ./configure ${CARES_STATIC_OPTION} ${CARES_PIC_OPTION} --prefix=${CARES_INSTALL_DIR}
BUILD_COMMAND make
BUILD_IN_SOURCE 1
BUILD_BYPRODUCTS ${CARES_INCLUDE} ${CARES_LIB}
Expand Down
7 changes: 7 additions & 0 deletions cmake/modules/curl.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,12 @@ else()
endif()
message(STATUS "Using bundled curl in '${CURL_BUNDLE_DIR}'")

if(NOT ENABLE_PIC)
set(CURL_PIC_OPTION )
else()
set(CURL_PIC_OPTION "--with-pic")
endif()

if(NOT TARGET curl)
ExternalProject_Add(
curl
Expand All @@ -61,6 +67,7 @@ else()
${CURL_SSL_OPTION}
${CURL_ZLIB_OPTION}
${CURL_STATIC_OPTION}
${CURL_PIC_OPTION}
--enable-optimize
--disable-curldebug
--disable-rt
Expand Down
1 change: 1 addition & 0 deletions cmake/modules/grpc.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ else()
CMAKE_CACHE_ARGS
-DCMAKE_INSTALL_PREFIX:PATH=${GRPC_INSTALL_DIR}
-DCMAKE_BUILD_TYPE:STRING=Release
-DCMAKE_POSITION_INDEPENDENT_CODE:BOOL=${ENABLE_PIC}
-DgRPC_INSTALL:BOOL=OFF
# disable unused stuff
-DgRPC_BUILD_TESTS:BOOL=OFF
Expand Down
2 changes: 2 additions & 0 deletions cmake/modules/jsoncpp.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ else()
URL_HASH
"SHA256=f409856e5920c18d0c2fb85276e24ee607d2a09b5e7d5f0a371368903c275da2"
CMAKE_ARGS
-DCMAKE_POSITION_INDEPENDENT_CODE=${ENABLE_PIC}
-DBUILD_OBJECT_LIBS=Off
${JSONCPP_STATIC_OPTION}
-DBUILD_SHARED_LIBS=${BUILD_SHARED_LIBS}
Expand All @@ -71,6 +72,7 @@ else()
CMAKE_ARGS
-DCMAKE_CXX_FLAGS_DEBUG=${FALCOSECURITY_LIBS_DEBUG_FLAGS}
-DCMAKE_CXX_FLAGS_RELEASE=${FALCOSECURITY_LIBS_RELEASE_FLAGS}
-DCMAKE_POSITION_INDEPENDENT_CODE=${ENABLE_PIC}
-DBUILD_OBJECT_LIBS=Off
${JSONCPP_STATIC_OPTION}
-DBUILD_SHARED_LIBS=${BUILD_SHARED_LIBS}
Expand Down
6 changes: 5 additions & 1 deletion cmake/modules/libelf.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ else()
else()
set(LIBELF_LIB_SUFFIX ${CMAKE_STATIC_LIBRARY_SUFFIX})
endif()
set(LIBELF_CFLAGS "-I${ZLIB_INCLUDE}")
if (ENABLE_PIC)
set(LIBELF_CFLAGS "${LIBELF_CFLAGS} -fPIC")
endif()
set(LIBELF_SRC "${PROJECT_BINARY_DIR}/libelf-prefix/src")
set(LIBELF_INCLUDE "${LIBELF_SRC}/libelf/libelf")
set(LIBELF_LIB "${LIBELF_SRC}/libelf/libelf/libelf${LIBELF_LIB_SUFFIX}")
Expand All @@ -48,7 +52,7 @@ else()
DEPENDS zlib
URL "https://sourceware.org/elfutils/ftp/0.189/elfutils-0.189.tar.bz2"
URL_HASH "SHA256=39bd8f1a338e2b7cd4abc3ff11a0eddc6e690f69578a57478d8179b4148708c8"
CONFIGURE_COMMAND ./configure LDFLAGS=-L${ZLIB_SRC} "CFLAGS=-I${ZLIB_INCLUDE}" --enable-deterministic-archives --disable-debuginfod --disable-libdebuginfod --without-zstd
CONFIGURE_COMMAND ./configure LDFLAGS=-L${ZLIB_SRC} "CFLAGS=${LIBELF_CFLAGS}" --enable-deterministic-archives --disable-debuginfod --disable-libdebuginfod --without-zstd
BUILD_IN_SOURCE 1
BUILD_COMMAND make -C lib libeu.a
COMMAND make -C libelf libelf${LIBELF_LIB_SUFFIX}
Expand Down
8 changes: 7 additions & 1 deletion cmake/modules/openssl.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,19 @@ else()
set(OPENSSL_LIBRARIES ${OPENSSL_LIBRARY_SSL} ${OPENSSL_LIBRARY_CRYPTO})

if(NOT TARGET openssl)
if(NOT ENABLE_PIC)
set(OPENSSL_PIC_OPTION )
else()
set(OPENSSL_PIC_OPTION "-fPIC")
endif()

message(STATUS "Using bundled openssl in '${OPENSSL_BUNDLE_DIR}'")

ExternalProject_Add(openssl
PREFIX "${PROJECT_BINARY_DIR}/openssl-prefix"
URL "https://github.com/openssl/openssl/releases/download/openssl-3.1.4/openssl-3.1.4.tar.gz"
URL_HASH "SHA256=840af5366ab9b522bde525826be3ef0fb0af81c6a9ebd84caa600fea1731eee3"
CONFIGURE_COMMAND ./config ${OPENSSL_SHARED_OPTION} --prefix=${OPENSSL_INSTALL_DIR} --libdir=lib
CONFIGURE_COMMAND ./config ${OPENSSL_SHARED_OPTION} ${OPENSSL_PIC_OPTION} --prefix=${OPENSSL_INSTALL_DIR} --libdir=lib
BUILD_COMMAND make
BUILD_IN_SOURCE 1
BUILD_BYPRODUCTS ${OPENSSL_LIBRARY_SSL} ${OPENSSL_LIBRARY_CRYPTO}
Expand Down
8 changes: 7 additions & 1 deletion cmake/modules/protobuf.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,20 @@ else()
set(PROTOBUF_INSTALL_DIR "${PROTOBUF_SRC}/target")

if(NOT TARGET protobuf)
if(NOT ENABLE_PIC)
set(PROTOBUF_PIC_OPTION )
else()
set(PROTOBUF_PIC_OPTION "--with-pic=yes")
endif()

message(STATUS "Using bundled protobuf in '${PROTOBUF_SRC}'")
ExternalProject_Add(protobuf
PREFIX "${PROJECT_BINARY_DIR}/protobuf-prefix"
DEPENDS zlib
URL "https://github.com/protocolbuffers/protobuf/releases/download/v3.20.3/protobuf-cpp-3.20.3.tar.gz"
URL_HASH "SHA256=e51cc8fc496f893e2a48beb417730ab6cbcb251142ad8b2cd1951faa5c76fe3d"
# TODO what if using system zlib?
CONFIGURE_COMMAND CPPFLAGS=-I${ZLIB_INCLUDE} LDFLAGS=-L${ZLIB_SRC} ./configure --with-zlib ${PROTOBUF_CONFIGURE_FLAGS} --prefix=${PROTOBUF_INSTALL_DIR}
CONFIGURE_COMMAND CPPFLAGS=-I${ZLIB_INCLUDE} LDFLAGS=-L${ZLIB_SRC} ./configure --with-zlib ${PROTOBUF_CONFIGURE_FLAGS} ${PROTOBUF_PIC_OPTION} --prefix=${PROTOBUF_INSTALL_DIR}
BUILD_COMMAND make
BUILD_IN_SOURCE 1
BUILD_BYPRODUCTS ${PROTOC} ${PROTOBUF_INCLUDE} ${PROTOBUF_LIB}
Expand Down
4 changes: 4 additions & 0 deletions cmake/modules/re2.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ else()
BUILD_BYPRODUCTS ${RE2_LIB}
CMAKE_ARGS
-DCMAKE_INSTALL_LIBDIR=lib
-DCMAKE_POSITION_INDEPENDENT_CODE=${ENABLE_PIC}
-DRE2_BUILD_TESTING=OFF
-DBUILD_SHARED_LIBS=${BUILD_SHARED_LIBS}
-DCMAKE_INSTALL_PREFIX=${RE2_SRC})
Expand All @@ -68,6 +69,7 @@ else()
COMMAND sed -i".bak" "/set_and_check/d" re2Config.cmake.in
CMAKE_ARGS
-DCMAKE_INSTALL_LIBDIR=lib
-DCMAKE_POSITION_INDEPENDENT_CODE=${ENABLE_PIC}
-DRE2_BUILD_TESTING=OFF
-DBUILD_SHARED_LIBS=${BUILD_SHARED_LIBS}
-DCMAKE_INSTALL_PREFIX=${RE2_SRC})
Expand All @@ -87,6 +89,7 @@ else()
-DCMAKE_CXX_FLAGS_DEBUG=${FALCOSECURITY_LIBS_DEBUG_FLAGS}
-DCMAKE_CXX_FLAGS_RELEASE=${FALCOSECURITY_LIBS_RELEASE_FLAGS}
-DCMAKE_INSTALL_LIBDIR=lib
-DCMAKE_POSITION_INDEPENDENT_CODE=${ENABLE_PIC}
-DRE2_BUILD_TESTING=OFF
-DBUILD_SHARED_LIBS=${BUILD_SHARED_LIBS}
-DCMAKE_INSTALL_PREFIX=${RE2_SRC})
Expand All @@ -101,6 +104,7 @@ else()
-DCMAKE_POLICY_DEFAULT_CMP0091:STRING=NEW
-DCMAKE_MSVC_RUNTIME_LIBRARY=${CMAKE_MSVC_RUNTIME_LIBRARY}
-DCMAKE_INSTALL_LIBDIR=lib
-DCMAKE_POSITION_INDEPENDENT_CODE=${ENABLE_PIC}
-DRE2_BUILD_TESTING=OFF
-DBUILD_SHARED_LIBS=${BUILD_SHARED_LIBS}
-DCMAKE_INSTALL_PREFIX=${RE2_SRC})
Expand Down
3 changes: 3 additions & 0 deletions cmake/modules/tbb.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ else()
-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}
-DTBB_OUTPUT_DIR_BASE=lib
-DCMAKE_CXX_FLAGS="${TBB_FLAGS}"
-DCMAKE_POSITION_INDEPENDENT_CODE=${ENABLE_PIC}
BUILD_BYPRODUCTS ${TBB_LIB}
INSTALL_COMMAND "")
else()
Expand All @@ -96,6 +97,7 @@ else()
-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}
-DTBB_OUTPUT_DIR_BASE=lib
-DCMAKE_CXX_FLAGS="${TBB_FLAGS}"
-DCMAKE_POSITION_INDEPENDENT_CODE=${ENABLE_PIC}
BUILD_BYPRODUCTS ${TBB_LIB}
INSTALL_COMMAND "")
else()
Expand All @@ -112,6 +114,7 @@ else()
-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}
-DTBB_OUTPUT_DIR_BASE=lib
-DCMAKE_CXX_FLAGS="${TBB_FLAGS}"
-DCMAKE_POSITION_INDEPENDENT_CODE=${ENABLE_PIC}
BUILD_BYPRODUCTS ${TBB_LIB}
INSTALL_COMMAND "")
endif()
Expand Down
9 changes: 7 additions & 2 deletions cmake/modules/zlib.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ else()
"${ZLIB_INCLUDE}/zutil.h"
)
if(NOT TARGET zlib)
set(ZLIB_CFLAGS )
if (ENABLE_PIC)
set(ZLIB_CFLAGS -fPIC)
endif()

message(STATUS "Using bundled zlib in '${ZLIB_SRC}'")
if(NOT WIN32)
if(BUILD_SHARED_LIBS)
Expand All @@ -56,7 +61,7 @@ else()
PREFIX "${PROJECT_BINARY_DIR}/zlib-prefix"
URL "https://github.com/madler/zlib/archive/v1.2.13.tar.gz"
URL_HASH "SHA256=1525952a0a567581792613a9723333d7f8cc20b87a81f920fb8bc7e3f2251428"
CONFIGURE_COMMAND ./configure --prefix=${ZLIB_SRC} ${ZLIB_CONFIGURE_FLAGS}
CONFIGURE_COMMAND CFLAGS=${ZLIB_CFLAGS} ./configure --prefix=${ZLIB_SRC} ${ZLIB_CONFIGURE_FLAGS}
BUILD_COMMAND make
BUILD_IN_SOURCE 1
BUILD_BYPRODUCTS ${ZLIB_LIB}
Expand All @@ -77,7 +82,7 @@ else()
URL "https://github.com/madler/zlib/archive/v1.2.13.tar.gz"
URL_HASH "SHA256=1525952a0a567581792613a9723333d7f8cc20b87a81f920fb8bc7e3f2251428"
CONFIGURE_COMMAND ""
BUILD_COMMAND nmake -f win32/Makefile.msc LOC=-DZLIB_WINAPI
BUILD_COMMAND nmake -f win32/Makefile.msc LOC="-DZLIB_WINAPI ${ZLIB_CFLAGS}"
BUILD_IN_SOURCE 1
BUILD_BYPRODUCTS ${ZLIB_LIB}
INSTALL_COMMAND "")
Expand Down

0 comments on commit 844ff42

Please sign in to comment.