Build source codes once as object target 70/185570/1
authorSunmin Lee <sunm.lee@samsung.com>
Thu, 26 Jul 2018 05:21:20 +0000 (14:21 +0900)
committerSunmin Lee <sunm.lee@samsung.com>
Thu, 26 Jul 2018 07:23:37 +0000 (16:23 +0900)
The codes built as object file can be used for both libraries
(shared/static) without building for each one.

Change-Id: Ic580e691fb93a72cfc8adafcf634422bc26ef112
Signed-off-by: Sunmin Lee <sunm.lee@samsung.com>
CMakeLists.txt

index e403e62..6c231b5 100755 (executable)
@@ -66,17 +66,19 @@ SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--as-needed")
 
 CONFIGURE_FILE(tota.pc.in tota.pc @ONLY)
 
-ADD_LIBRARY(${LIBNAME}-shared SHARED ${SRCS})
-TARGET_LINK_LIBRARIES(${LIBNAME}-shared ${packages_LDFLAGS})
-SET_TARGET_PROPERTIES(${LIBNAME}-shared PROPERTIES VERSION ${VERSION})
-SET_TARGET_PROPERTIES(${LIBNAME}-shared PROPERTIES OUTPUT_NAME ${LIBNAME})
-INSTALL(TARGETS ${LIBNAME}-shared DESTINATION ${LIB_INSTALL_DIR})
+ADD_LIBRARY(${LIBNAME}-object OBJECT ${SRCS})
 
-ADD_LIBRARY(${LIBNAME} STATIC ${SRCS})
+ADD_LIBRARY(${LIBNAME} SHARED $<TARGET_OBJECTS:${LIBNAME}-object>)
 TARGET_LINK_LIBRARIES(${LIBNAME} ${packages_LDFLAGS})
-INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/libtota.a DESTINATION ${LIB_INSTALL_DIR})
-#CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/modulename-api.pc.in ${CMAKE_CURRENT_BINARY_DIR}/modulename-api.pc @ONLY)
-#INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/modulename-api.pc DESTINATION lib/pkgconfig)
+SET_TARGET_PROPERTIES(${LIBNAME} PROPERTIES VERSION ${VERSION})
+SET_TARGET_PROPERTIES(${LIBNAME} PROPERTIES OUTPUT_NAME ${LIBNAME})
+INSTALL(TARGETS ${LIBNAME} DESTINATION ${LIB_INSTALL_DIR})
+
+ADD_LIBRARY(${LIBNAME}-static STATIC $<TARGET_OBJECTS:${LIBNAME}-object>)
+SET_TARGET_PROPERTIES(${LIBNAME}-static PROPERTIES VERSION ${VERSION})
+SET_TARGET_PROPERTIES(${LIBNAME}-static PROPERTIES OUTPUT_NAME ${LIBNAME})
+INSTALL(TARGETS ${LIBNAME}-static DESTINATION ${LIB_INSTALL_DIR})
+
 INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/tota.pc DESTINATION ${LIB_INSTALL_DIR}/pkgconfig)
 FOREACH(hfile ${HEADERS})
         INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/${hfile} DESTINATION include)