Skip to content

Commit

Permalink
Build static and/or shared libaries optionally
Browse files Browse the repository at this point in the history
  • Loading branch information
inniyah committed Aug 4, 2020
1 parent fc2fc5e commit 4e228e2
Showing 1 changed file with 26 additions and 14 deletions.
40 changes: 26 additions & 14 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/src)
ADD_COMPILE_OPTIONS(-Wall -Werror)
ADD_LINK_OPTIONS(LINKER:--as-needed LINKER:--no-undefined LINKER:--no-allow-shlib-undefined)

option(NANOVG_SHARED_LIBS "Build shared libraries" ON)
option(NANOVG_STATIC_LIBS "Build static liraries" ON)
option(NANOVG_BUILD_EXAMPLES "Build examples" ON)
option(NANOVG_BUILD_GL2 "Build OpenGL 2" ON)
option(NANOVG_BUILD_GL3 "Build OpenGL 2" ON)
Expand Down Expand Up @@ -106,26 +108,36 @@ ENDIF()

SET(NANOVG_DEPENDENCIES EGL ${NANOVG_DEPENDENCIES})

ADD_LIBRARY(nanovg_so SHARED ${NANOVG_LIB_OBJECTS})
CONFIGURE_FILE(pkgconfig/nanovg.pc.in nanovg.pc @ONLY)

SET_TARGET_PROPERTIES(nanovg_so PROPERTIES VERSION ${VERSION} SOVERSION 0)
SET_TARGET_PROPERTIES(nanovg_so PROPERTIES OUTPUT_NAME nanovg)
TARGET_LINK_LIBRARIES(nanovg_so PUBLIC ${NANOVG_LIB_NAMES})
TARGET_LINK_LIBRARIES(nanovg_so PRIVATE ${NANOVG_DEPENDENCIES})
IF(NANOVG_SHARED_LIBS)
ADD_LIBRARY(nanovg_so SHARED ${NANOVG_LIB_OBJECTS})

ADD_LIBRARY(nanovg_a STATIC ${NANOVG_LIB_OBJECTS})
SET_TARGET_PROPERTIES(nanovg_so PROPERTIES VERSION ${VERSION} SOVERSION 0)
SET_TARGET_PROPERTIES(nanovg_so PROPERTIES OUTPUT_NAME nanovg)
TARGET_LINK_LIBRARIES(nanovg_so PUBLIC ${NANOVG_LIB_NAMES})
TARGET_LINK_LIBRARIES(nanovg_so PRIVATE ${NANOVG_DEPENDENCIES})

SET_TARGET_PROPERTIES(nanovg_a PROPERTIES OUTPUT_NAME nanovg)
TARGET_LINK_LIBRARIES(nanovg_a PUBLIC ${NANOVG_LIB_NAMES})
TARGET_LINK_LIBRARIES(nanovg_a PRIVATE ${NANOVG_DEPENDENCIES})
INSTALL(TARGETS nanovg_so
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION bin)
ENDIF()

CONFIGURE_FILE(pkgconfig/nanovg.pc.in nanovg.pc @ONLY)
IF(NANOVG_STATIC_LIBS)
ADD_LIBRARY(nanovg_a STATIC ${NANOVG_LIB_OBJECTS})

INSTALL(TARGETS nanovg_so nanovg_a
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION bin)
SET_TARGET_PROPERTIES(nanovg_a PROPERTIES OUTPUT_NAME nanovg)
TARGET_LINK_LIBRARIES(nanovg_a PUBLIC ${NANOVG_LIB_NAMES})
TARGET_LINK_LIBRARIES(nanovg_a PRIVATE ${NANOVG_DEPENDENCIES})

INSTALL(TARGETS nanovg_a
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION bin)
ENDIF()

# Install header files
INSTALL(DIRECTORY ${CMAKE_SOURCE_DIR}/src/
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/nanovg
FILES_MATCHING PATTERN "nano*.h*")
Expand Down

0 comments on commit 4e228e2

Please sign in to comment.