Skip to content

Commit

Permalink
Reverted additional static linker flags
Browse files Browse the repository at this point in the history
  • Loading branch information
jesper-friis committed Oct 11, 2024
1 parent 7ad62e2 commit 48f4fb0
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 47 deletions.
53 changes: 28 additions & 25 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -281,34 +281,37 @@ if(WITH_PYTHON)
OUTPUT_STRIP_TRAILING_WHITESPACE
)
list(APPEND extra_link_libraries ${Python3_LDFLAGS})
message(STATUS "Python3_LDFLAGS: ${Python3_LDFLAGS}")
#message(STATUS "Python3_LDFLAGS: ${Python3_LDFLAGS}")

# Link libraries when compiling against static Python (e.g. manylinux)
# if(WITH_STATIC_PYTHON)
# execute_process(
# COMMAND ${Python3_EXECUTABLE}-config --ldflags
# OUTPUT_VARIABLE Python3_LDFLAGS
# OUTPUT_STRIP_TRAILING_WHITESPACE
# )
#
# # TODO: find a more portable way to add the "-Xlinker -export-dynamic" options.
# # They are needed to ensure that the linker include all symbols in
# # the static Python library.
# set(Python3_STATIC_LIBS
# ${Python3_LDFLAGS}
# -Xlinker -export-dynamic
# ${Python3_LIBRARY}
# )
#
# list(APPEND extra_link_libraries ${Python3_STATIC_LIBS})
# endif()
if(WITH_STATIC_PYTHON)
execute_process(
COMMAND ${Python3_EXECUTABLE}-config --ldflags
OUTPUT_VARIABLE Python3_LDFLAGS
OUTPUT_STRIP_TRAILING_WHITESPACE
)

# Link libraries when compiling against static Python (e.g. cibuildwheel)
if(DEFINED ENV{Python3_LIBRARY})
set(Python3_STATIC_LIBS $ENV{Python3_LIBRARY})
list(APPEND extra_link_libraries $ENV{Python3_LIBRARY})
# Linker flags "-Xlinker -export-dynamic" are needed to ensure that
# the linker include all symbols in the static Python library.
include(CheckLinkerFlag)
check_linker_flag(C "-Xlinker -export-dynamic" HAVE_linker_dynexport)
if(HAVE_linker_dynexport)
list(APPEND Python3_LDFLAGS "-Xlinker" "-export-dynamic")
endif()

set(Python3_STATIC_LIBS
${Python3_LDFLAGS}
${Python3_LIBRARY}
)
list(APPEND extra_link_libraries ${Python3_STATIC_LIBS})
endif()
message(STATUS "ENV{Python3_LIBRARY}: $ENV{Python3_LIBRARY}")

# Link libraries when compiling against static Python (e.g. cibuildwheel)
# if(DEFINED ENV{Python3_LIBRARY})
# set(Python3_STATIC_LIBS $ENV{Python3_LIBRARY})
# list(APPEND extra_link_libraries $ENV{Python3_LIBRARY})
# endif()
# message(STATUS "ENV{Python3_LIBRARY}: $ENV{Python3_LIBRARY}")


message(STATUS "CMAKE_INSTALL_PREFIX = ${CMAKE_INSTALL_PREFIX}")
Expand Down Expand Up @@ -349,7 +352,7 @@ else()
set(Python3_LIBRARIES "")
endif()

message(STATUS "extra_link_libraries = ${extra_link_libraries}")
#message(STATUS "extra_link_libraries = ${extra_link_libraries}")


#
Expand Down
57 changes: 35 additions & 22 deletions src/pyembed/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,28 +1,41 @@
# -*- Mode: cmake -*-

include(CheckCSourceCompiles)
# include(CheckLinkerFlag)
#
# check_linker_flag(C "-lrt" HAVE_LINKER_FLAG_RT)
# check_linker_flag(C "-ldl" HAVE_LINKER_FLAG_DL)
#
# if(HAVE_LINKER_FLAG_RT)
# list(APPEND extra_link_libraries "-lrt")
# endif()
#
# if(HAVE_LINKER_FLAG_DL)
# list(APPEND extra_link_libraries "-ldl")
# endif()

# Check if clock_settime (used by Python) need linking with -lrt
set(CMAKE_REQUIRED_LINK_OPTIONS_save ${CMAKE_REQUIRED_LINK_OPTIONS})
set(CMAKE_REQUIRED_LINK_OPTIONS "-lrt")
check_c_source_compiles("
#define _XOPEN_SOURCE 600
#include <time.h>
int main(void) {
clockid_t clock = CLOCK_REALTIME;
struct timespec ts;
clock_gettime(clock, &ts);
return 0;
}" need_lrt)

if(need_lrt)
message(STATUS "Adding -lrt to extra_link_libraries")
list(APPEND extra_link_libraries "-lrt")
endif()

set(CMAKE_REQUIRED_LINK_OPTIONS ${CMAKE_REQUIRED_LINK_OPTIONS_save})
unset(CMAKE_REQUIRED_LINK_OPTIONS_save)
unset(need_lrt)
# include(CheckCSourceCompiles)
#
# # Check if clock_settime (used by Python) need linking with -lrt
# set(CMAKE_REQUIRED_LINK_OPTIONS_save ${CMAKE_REQUIRED_LINK_OPTIONS})
# set(CMAKE_REQUIRED_LINK_OPTIONS "-lrt")
# check_c_source_compiles("
# #define _XOPEN_SOURCE 600
# #include <time.h>
# int main(void) {
# clockid_t clock = CLOCK_REALTIME;
# struct timespec ts;
# clock_gettime(clock, &ts);
# return 0;
# }" need_lrt)
#
# if(need_lrt)
# message(STATUS "Adding -lrt to extra_link_libraries")
# list(APPEND extra_link_libraries "-lrt")
# endif()
#
# set(CMAKE_REQUIRED_LINK_OPTIONS ${CMAKE_REQUIRED_LINK_OPTIONS_save})
# unset(CMAKE_REQUIRED_LINK_OPTIONS_save)
# unset(need_lrt)


set(pyembed_sources
Expand Down

0 comments on commit 48f4fb0

Please sign in to comment.