Skip to content

Commit

Permalink
Build metall_c as a static lib by default explicitly.
Browse files Browse the repository at this point in the history
- To generate shared library. specify BUILD_SHARED_LIBS=ON with CMake.

- Stop hardcoding -fPIC option.
  • Loading branch information
Keita Iwabuchi committed Jun 26, 2024
1 parent e748db7 commit 4580e12
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ option(JUST_INSTALL_METALL_HEADER "Just install Metall header files (do not buil
option(BUILD_UTILITY "Build utility programs" OFF)
option(BUILD_DOC "Build API documentation" OFF)
option(BUILD_C "Build C examples and libraries" OFF)
option(BUILD_SHARED_LIBS "Generate shared libraries" OFF)
option(BUILD_EXAMPLE "Build the examples" OFF)
option(BUILD_TEST "Build the test" OFF)
option(RUN_LARGE_SCALE_TEST "Run large scale tests" OFF)
Expand Down
16 changes: 14 additions & 2 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,21 @@ if (BUILD_C)
return()
endif ()

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC")

if (BUILD_SHARED_LIBS)
message(STATUS "Building metall_c as a shared library")
else ()
message(STATUS "Building metall_c as a static library")
endif ()
# 'BUILD_SHARED_LIBS' variable is used to determine
# whether to build a shared library or a static library.
add_library(metall_c metall_c.cpp)
get_target_property(PIC_metall_c metall_c POSITION_INDEPENDENT_CODE)
if (PIC_metall_c)
message(STATUS "POSITION_INDEPENDENT_CODE for metall_c : ON")
else ()
message(STATUS "POSITION_INDEPENDENT_CODE for metall_c : OFF")
endif ()

add_library(${PROJECT_NAME}::metall_c ALIAS metall_c)

target_include_directories(metall_c PUBLIC
Expand Down

0 comments on commit 4580e12

Please sign in to comment.