Created
July 15, 2020 11:05
-
-
Save lategoodbye/4b6fc3b33fb6c7dd146cf0bb14da3312 to your computer and use it in GitHub Desktop.
WIP: build static library of libmbus
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/CMakeLists.txt b/CMakeLists.txt | |
index c47a94c..9230a64 100644 | |
--- a/CMakeLists.txt | |
+++ b/CMakeLists.txt | |
@@ -95,8 +95,8 @@ set(PACKAGE_VERSION "${PROJECT_VERSION}") | |
set(VERSION "${PROJECT_VERSION}") | |
configure_file(${CMAKE_CURRENT_LIST_DIR}/mbus/config.h.in ${CMAKE_CURRENT_LIST_DIR}/config.h @ONLY) | |
-add_library( | |
- ${PROJECT_NAME} | |
+# list of source files | |
+set(libsrc | |
"${CMAKE_CURRENT_LIST_DIR}/mbus/mbus-protocol.c" | |
"${CMAKE_CURRENT_LIST_DIR}/mbus/mbus-protocol.h" | |
"${CMAKE_CURRENT_LIST_DIR}/mbus/mbus-tcp.c" | |
@@ -107,6 +107,16 @@ add_library( | |
"${CMAKE_CURRENT_LIST_DIR}/mbus/mbus-protocol-aux.h" | |
"${CMAKE_CURRENT_LIST_DIR}/mbus/mbus-serial.c" | |
"${CMAKE_CURRENT_LIST_DIR}/mbus/mbus-serial.h") | |
+ | |
+add_library(objlib OBJECT ${libsrc}) | |
+ | |
+# shared and static libraries built from the same object files | |
+add_library(${PROJECT_NAME} SHARED $<TARGET_OBJECTS:objlib>) | |
+add_library(libmbus_static STATIC $<TARGET_OBJECTS:objlib>) | |
+ | |
+set_target_properties(${PROJECT_NAME} PROPERTIES PREFIX "") | |
+set_target_properties(libmbus_static PROPERTIES OUTPUT_NAME ${PROJECT_NAME}) | |
+ | |
target_include_directories( | |
${PROJECT_NAME} | |
PUBLIC "$<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}>" "$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}>" | |
@@ -118,8 +128,6 @@ if(NOT MSVC) | |
target_compile_options(${PROJECT_NAME} PRIVATE -Wall -Wextra -Wno-pedantic) | |
endif() | |
-set_target_properties(${PROJECT_NAME} PROPERTIES PREFIX "") | |
- | |
if(CLANG_TIDY_EXE) | |
set_target_properties(${PROJECT_NAME} PROPERTIES CXX_CLANG_TIDY "${CLANG_TIDY_EXE}") | |
endif() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment