Skip to content

Commit

Permalink
* add SLEEF_BUILD_SHARED_LIBS build config.
Browse files Browse the repository at this point in the history
* default build sleef in shared mode.
* fix install files to dummy folder.
  • Loading branch information
xuhancn committed Mar 8, 2024
1 parent cf532e2 commit f98ce8f
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 64 deletions.
10 changes: 5 additions & 5 deletions CMakeLists.txt
@@ -1,6 +1,6 @@

# Options

option(SLEEF_BUILD_SHARED_LIBS "Build sleef as static library" ON)
option(SLEEF_BUILD_STATIC_TEST_BINS "Build statically linked test executables" OFF)
option(SLEEF_ENABLE_LTO "Enable LTO on GCC or ThinLTO on clang" OFF)
option(SLEEF_BUILD_LIBM "libsleef will be built." ON)
Expand Down Expand Up @@ -157,9 +157,9 @@ separate build directory. Note: Please remove autogenerated file \
`CMakeCache.txt` and directory `CMakeFiles` in the current directory.")
endif()

if(SLEEF_ENABLE_LTO AND BUILD_SHARED_LIBS)
message(FATAL_ERROR "SLEEF_ENABLE_LTO and BUILD_SHARED_LIBS cannot be specified at the same time")
endif(SLEEF_ENABLE_LTO AND BUILD_SHARED_LIBS)
if(SLEEF_ENABLE_LTO AND SLEEF_BUILD_SHARED_LIBS)
message(FATAL_ERROR "SLEEF_ENABLE_LTO and SLEEF_BUILD_SHARED_LIBS cannot be specified at the same time")
endif(SLEEF_ENABLE_LTO AND SLEEF_BUILD_SHARED_LIBS)

if(SLEEF_ENABLE_LTO)
cmake_policy(SET CMP0069 NEW)
Expand Down Expand Up @@ -305,7 +305,7 @@ if(SLEEF_SHOW_CONFIG)
message(" Native build dir: ${NATIVE_BUILD_DIR}")
endif(CMAKE_CROSSCOMPILING)
message(STATUS "Using option `${SLEEF_C_FLAGS}` to compile libsleef")
message(STATUS "Building shared libs : " ${BUILD_SHARED_LIBS})
message(STATUS "Building shared libs : " ${SLEEF_BUILD_SHARED_LIBS})
message(STATUS "Building static test bins: " ${SLEEF_BUILD_STATIC_TEST_BINS})
message(STATUS "MPFR : " ${LIB_MPFR})
if (MPFR_INCLUDE_DIR)
Expand Down
4 changes: 2 additions & 2 deletions Configure.cmake
Expand Up @@ -7,7 +7,7 @@ include(CheckLanguage)

if (SLEEF_BUILD_STATIC_TEST_BINS)
set(CMAKE_FIND_LIBRARY_SUFFIXES ".a")
set(BUILD_SHARED_LIBS OFF)
set(SLEEF_BUILD_SHARED_LIBS OFF)
set(CMAKE_EXE_LINKER_FLAGS "-static")
endif()

Expand Down Expand Up @@ -834,7 +834,7 @@ endif()

# Set common definitions

if (NOT BUILD_SHARED_LIBS)
if (NOT SLEEF_BUILD_SHARED_LIBS)
set(COMMON_TARGET_DEFINITIONS SLEEF_STATIC_LIBS=1)
set(SLEEF_STATIC_LIBS 1)
endif()
Expand Down
2 changes: 1 addition & 1 deletion docs/build-with-cmake.md
Expand Up @@ -133,7 +133,7 @@ optimized, or any other special set of flags.
- `SLEEF_SHOW_CONFIG` : Show relevant CMake variables upon configuring a build
- `SLEEF_SHOW_ERROR_LOG` : Show the content of CMakeError.log

- `BUILD_SHARED_LIBS` : Static libs are built if set to FALSE
- `SLEEF_BUILD_SHARED_LIBS` : Static libs are built if set to FALSE
- `SLEEF_BUILD_GNUABI_LIBS` : Avoid building libraries with GNU ABI if set to FALSE
- `SLEEF_BUILD_INLINE_HEADERS` : Generate header files for inlining whole SLEEF functions

Expand Down
2 changes: 1 addition & 1 deletion src/common/CMakeLists.txt
Expand Up @@ -4,7 +4,7 @@ set(COMMON_TARGET_PROPERTIES
C_STANDARD 99 # -std=gnu99
)

if (BUILD_SHARED_LIBS)
if (SLEEF_BUILD_SHARED_LIBS)
list(APPEND COMMON_TARGET_PROPERTIES POSITION_INDEPENDENT_CODE ON) # -fPIC
endif()

Expand Down
20 changes: 7 additions & 13 deletions src/dft/CMakeLists.txt
Expand Up @@ -174,7 +174,7 @@ set(COMMON_TARGET_PROPERTIES
C_STANDARD 99 # -std=gnu99
)

if (BUILD_SHARED_LIBS)
if (SLEEF_BUILD_SHARED_LIBS)
list(APPEND COMMON_TARGET_PROPERTIES POSITION_INDEPENDENT_CODE ON) # -fPIC
endif()

Expand Down Expand Up @@ -323,8 +323,11 @@ foreach(T ${LIST_SUPPORTED_FPTYPE})
endforeach()

# Target libdft

add_library(${TARGET_LIBDFT} $<TARGET_OBJECTS:dftcommon_obj> $<TARGET_OBJECTS:${TARGET_LIBARRAYMAP_OBJ}>)
if(SLEEF_BUILD_SHARED_LIBS)
add_library(${TARGET_LIBDFT} SHARED $<TARGET_OBJECTS:dftcommon_obj> $<TARGET_OBJECTS:${TARGET_LIBARRAYMAP_OBJ}>)
else()
add_library(${TARGET_LIBDFT} STATIC $<TARGET_OBJECTS:dftcommon_obj> $<TARGET_OBJECTS:${TARGET_LIBARRAYMAP_OBJ}>)
endif()
target_link_libraries(${TARGET_LIBDFT} ${TARGET_LIBSLEEF} ${LIBM})

foreach(T ${LIST_SUPPORTED_FPTYPE})
Expand Down Expand Up @@ -372,13 +375,4 @@ install(
COMPONENT sleef_Runtime
INCLUDES #
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}"
)

install(
TARGETS ${TARGET_LIBDFT}
DESTINATION dummy # provided above already
LIBRARY #
DESTINATION "${CMAKE_INSTALL_LIBDIR}"
COMPONENT sleef_Development
NAMELINK_ONLY
)
)
47 changes: 17 additions & 30 deletions src/libm/CMakeLists.txt
Expand Up @@ -348,7 +348,7 @@ set(COMMON_TARGET_PROPERTIES
C_STANDARD 99 # -std=gnu99
)

if (BUILD_SHARED_LIBS)
if (SLEEF_BUILD_SHARED_LIBS)
list(APPEND COMMON_TARGET_PROPERTIES POSITION_INDEPENDENT_CODE ON) # -fPIC
endif()

Expand All @@ -359,7 +359,12 @@ endif()
# Original sleef sources
set(STANDARD_SOURCES rempitab.c)

add_library(${TARGET_LIBSLEEF} ${STANDARD_SOURCES})
if(SLEEF_BUILD_SHARED_LIBS)
add_library(${TARGET_LIBSLEEF} SHARED ${STANDARD_SOURCES})
else()
add_library(${TARGET_LIBSLEEF} STATIC ${STANDARD_SOURCES})
endif()

add_dependencies(${TARGET_LIBSLEEF} ${TARGET_HEADERS})
set_target_properties(${TARGET_LIBSLEEF} PROPERTIES
VERSION ${SLEEF_VERSION}
Expand Down Expand Up @@ -884,7 +889,11 @@ if(ENABLE_GNUABI)
endforeach()

# Create library
add_library(${TARGET_LIBSLEEFGNUABI} ${TARGET_LIBSLEEFGNUABI_OBJECTS} rempitab.c)
if(SLEEF_BUILD_SHARED_LIBS)
add_library(${TARGET_LIBSLEEFGNUABI} SHARED ${TARGET_LIBSLEEFGNUABI_OBJECTS} rempitab.c)
else()
add_library(${TARGET_LIBSLEEFGNUABI} STATIC ${TARGET_LIBSLEEFGNUABI_OBJECTS} rempitab.c)
endif()

# Library properties
set_target_properties(${TARGET_LIBSLEEFGNUABI} PROPERTIES
Expand Down Expand Up @@ -973,7 +982,11 @@ endif()
# --------------------------------------------------------------------
# Build scalar-only library from sleefdp.c and sleefsp.c

add_library(sleefscalar sleefdp.c sleefsp.c rempitab.c)
if(SLEEF_BUILD_SHARED_LIBS)
add_library(sleefscalar SHARED sleefdp.c sleefsp.c rempitab.c)
else()
add_library(sleefscalar STATIC sleefdp.c sleefsp.c rempitab.c)
endif()
add_dependencies(sleefscalar ${TARGET_HEADERS})
set_target_properties(sleefscalar PROPERTIES
VERSION ${SLEEF_VERSION}
Expand Down Expand Up @@ -1005,15 +1018,6 @@ if(SLEEF_BUILD_SCALAR_LIB)
DESTINATION "${CMAKE_INSTALL_BINDIR}"
COMPONENT sleef_Runtime
)

install(
TARGETS sleefscalar
DESTINATION dummy # provided above already
LIBRARY #
DESTINATION "${CMAKE_INSTALL_LIBDIR}"
COMPONENT sleef_Development
NAMELINK_ONLY
)
endif()

# --------------------------------------------------------------------
Expand All @@ -1039,14 +1043,6 @@ install(
INCLUDES #
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}"
)
install(
TARGETS ${TARGET_LIBSLEEF}
DESTINATION dummy # provided above already
LIBRARY #
DESTINATION "${CMAKE_INSTALL_LIBDIR}"
COMPONENT sleef_Development
NAMELINK_ONLY
)
configure_file("sleef.pc.in" "${CMAKE_CURRENT_BINARY_DIR}/sleef.pc" @ONLY)
install(
FILES "${CMAKE_CURRENT_BINARY_DIR}/sleef.pc"
Expand All @@ -1069,13 +1065,4 @@ if(ENABLE_GNUABI)
DESTINATION "${CMAKE_INSTALL_BINDIR}"
COMPONENT sleef_Runtime
)

install(
TARGETS ${TARGET_LIBSLEEF}
DESTINATION dummy # provided above already
LIBRARY #
DESTINATION "${CMAKE_INSTALL_LIBDIR}"
COMPONENT sleef_Development
NAMELINK_ONLY
)
endif()
19 changes: 7 additions & 12 deletions src/quad/CMakeLists.txt
Expand Up @@ -100,7 +100,7 @@ if(COMPILER_SUPPORTS_BUILTIN_MATH)
list(APPEND COMMON_TARGET_DEFINITIONS ENABLE_BUILTIN_MATH=1)
endif()

if (BUILD_SHARED_LIBS)
if (SLEEF_BUILD_SHARED_LIBS)
list(APPEND COMMON_TARGET_PROPERTIES POSITION_INDEPENDENT_CODE ON)
endif()

Expand Down Expand Up @@ -202,7 +202,11 @@ foreach(SIMD ${SLEEF_SUPPORTED_QUAD_EXTENSIONS})
endif()
endforeach()

add_library(sleefquad rempitabqp.c ${SLEEFQUAD_OBJECTS})
if(SLEEF_BUILD_SHARED_LIBS)
add_library(sleefquad SHARED rempitabqp.c ${SLEEFQUAD_OBJECTS})
else()
add_library(sleefquad STATIC rempitabqp.c ${SLEEFQUAD_OBJECTS})
endif()

set_target_properties(sleefquad PROPERTIES
VERSION ${SLEEF_VERSION}
Expand Down Expand Up @@ -489,13 +493,4 @@ install(
COMPONENT sleef_Runtime
INCLUDES #
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}"
)

install(
TARGETS sleefquad
DESTINATION dummy # provided above already
LIBRARY #
DESTINATION "${CMAKE_INSTALL_LIBDIR}"
COMPONENT sleef_Development
NAMELINK_ONLY
)
)

0 comments on commit f98ce8f

Please sign in to comment.