Skip to content

Commit

Permalink
igsc: cmake: add option to static build
Browse files Browse the repository at this point in the history
Add option to build static library and static cli without udev.

Signed-off-by: Alexander Usyskin <alexander.usyskin@intel.com>
Signed-off-by: Tomas Winkler <tomas.winkler@intel.com>
  • Loading branch information
ausyskin authored and tomasbw committed Jul 24, 2022
1 parent c5f077d commit a362423
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 15 deletions.
5 changes: 3 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# SPDX-License-Identifier: Apache-2.0
# Copyright (C) 2019-2020 Intel Corporation
# Copyright (C) 2019-2022 Intel Corporation
cmake_minimum_required(VERSION 3.10)
project(igsc C)
set(LICENSE Apache)
Expand All @@ -20,6 +20,7 @@ option(ENABLE_DOCS "Enable docs build" OFF)
option(ENABLE_TESTS "Perform unit tests after build" OFF)
option(ENABLE_WERROR "Enable treat warnings as error" ON)
option(ENABLE_CLI "Enable command line tool build" ON)
option(ENABLE_CLI_FORCE "Enable command line tool build also if enumeration is not supported" OFF)
option(ENABLE_ENUM "Enable enumeration build" ON)
option(BUILD_SHARED_LIBS "Build shared library" ON)
option (BUILD_USE_CONAN "Use Conan for dependencies download" NO)
Expand Down Expand Up @@ -97,7 +98,7 @@ set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} ${LINK_OPTIONS}")

add_subdirectory("lib")

if(CLI_ENABLED)
if(CLI_ENABLED OR ENABLE_CLI_FORCE)
add_subdirectory("src")
endif()

Expand Down
26 changes: 17 additions & 9 deletions include/igsc_lib.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,25 @@ extern "C" {
#endif /* OUT */

#if defined (_WIN32) || defined (_WIN64)
#ifdef IGSC_DLL_EXPORTS
#define IGSC_EXPORT __declspec(dllexport)
#else
#define IGSC_EXPORT __declspec(dllimport)
#endif
#ifndef IGSC_DLL
#define IGSC_EXPORT
#else /* IGSC_DLL */
#ifdef IGSC_DLL_EXPORTS
#define IGSC_EXPORT __declspec(dllexport)
#else
#define IGSC_EXPORT __declspec(dllimport)
#endif
#endif /* IGSC_DLL */
#else
#ifdef IGSC_DLL_EXPORTS
#define IGSC_EXPORT __attribute__((__visibility__("default")))
#else
#ifndef IGSC_DLL
#define IGSC_EXPORT
#endif
#else /* IGSC_DLL */
#ifdef IGSC_DLL_EXPORTS
#define IGSC_EXPORT __attribute__((__visibility__("default")))
#else
#define IGSC_EXPORT
#endif
#endif /* IGSC_DLL */
#endif
/** @endcond */

Expand Down
7 changes: 4 additions & 3 deletions lib/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# SPDX-License-Identifier: Apache-2.0
# Copyright (C) 2019-2021 Intel Corporation
# Copyright (C) 2019-2022 Intel Corporation
cmake_minimum_required(VERSION 3.10)
project(igsc C)
set(LICENSE Apache)
Expand Down Expand Up @@ -31,7 +31,7 @@ set(LIBSOURCES
$<$<BOOL:${WIN32}>:${PROJECT_BINARY_DIR}/igsc_lib.rc>
)

add_library(${PROJECT_NAME} SHARED ${LIBSOURCES})
add_library(${PROJECT_NAME} ${LIBSOURCES})
set_target_properties(${PROJECT_NAME}
PROPERTIES PUBLIC_HEADER ${CMAKE_SOURCE_DIR}/include/igsc_lib.h)

Expand All @@ -42,7 +42,8 @@ target_compile_options(${PROJECT_NAME} PRIVATE ${COMPILE_OPTIONS})

target_compile_definitions(
${PROJECT_NAME}
PRIVATE IGSC_DLL_EXPORTS
PRIVATE $<$<BOOL:${BUILD_SHARED_LIBS}>:IGSC_DLL_EXPORTS>
PRIVATE $<$<BOOL:${BUILD_SHARED_LIBS}>:IGSC_DLL>
PRIVATE $<$<BOOL:${ENABLE_ENUM}>:IGSC_ENUM>
PRIVATE $<$<BOOL:${SYSLOG}>:SYSLOG>
PRIVATE $<$<BOOL:${ENABLE_PERF}>:IGSC_PERF>
Expand Down
10 changes: 9 additions & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# SPDX-License-Identifier: Apache-2.0
# Copyright (C) 2019-2020 Intel Corporation
# Copyright (C) 2019-2022 Intel Corporation
cmake_minimum_required(VERSION 3.10)
project(igsc-cli C)
set(LICENSE Apache)
Expand All @@ -25,6 +25,14 @@ target_compile_options(${PROJECT_NAME} PRIVATE ${COMPILE_OPTIONS})
target_link_libraries(${PROJECT_NAME} igsc)
set_target_properties(${PROJECT_NAME} PROPERTIES OUTPUT_NAME igsc)

if(NOT BUILD_SHARED_LIBS)
if(CMAKE_C_COMPILER_ID MATCHES Clang OR
CMAKE_C_COMPILER_ID MATCHES AppleClang OR
CMAKE_C_COMPILER_ID MATCHES GNU)
target_link_options(${PROJECT_NAME} PRIVATE -static-libgcc -static)
endif()
endif()

install(
TARGETS ${PROJECT_NAME}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
Expand Down

0 comments on commit a362423

Please sign in to comment.