Skip to content

Commit

Permalink
CMake: Make BUILD_MODULE and BUILD_SHARED_LIBS non inclusive
Browse files Browse the repository at this point in the history
  • Loading branch information
doronbehar committed Feb 26, 2020
1 parent f38ae04 commit 0494414
Showing 1 changed file with 53 additions and 22 deletions.
75 changes: 53 additions & 22 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -131,13 +131,13 @@ endif (LUA)
if (BUILD_MODULE)
add_library(luv MODULE src/luv.c)
set_target_properties(luv PROPERTIES PREFIX "")
else (BUILD_MODULE)
add_library(luv src/luv.c)
if (BUILD_SHARED_LIBS)
set_target_properties(luv
PROPERTIES VERSION ${LUV_VERSION} SOVERSION ${LUV_VERSION_MAJOR})
endif (BUILD_SHARED_LIBS)
endif (BUILD_MODULE)
if (BUILD_SHARED_LIBS)
add_library(libluv src/luv.c)
set_target_properties(libluv PROPERTIES PREFIX "")
set_target_properties(libluv
PROPERTIES VERSION ${LUV_VERSION} SOVERSION ${LUV_VERSION_MAJOR})
endif (BUILD_SHARED_LIBS)

if(APPLE)
set(CMAKE_SHARED_MODULE_CREATE_C_FLAGS
Expand All @@ -157,6 +157,7 @@ if(DEFINED ENV{LUA_COMPAT53_DIR})
endif()
include_directories(${LUA_COMPAT53_DIR}/c-api)

if (BUILD_MODULE)
if(WIN32)
add_definitions(-DLUA_BUILD_AS_DLL -DLUA_LIB)
if (LUA)
Expand All @@ -177,39 +178,69 @@ elseif("${CMAKE_SYSTEM_NAME}" MATCHES "Linux")
else()
target_link_libraries(luv ${LIBUV_LIBRARIES})
endif()
endif (BUILD_MODULE)
if (BUILD_SHARED_LIBS)
if(WIN32)
add_definitions(-DLUA_BUILD_AS_DLL -DLUA_LIB)
if (LUA)
target_link_libraries(libluv ${LIBUV_LIBRARIES} ${LUA_LIBRARIES})
else (LUA)
if (USE_LUAJIT)
target_link_libraries(libluv ${LIBUV_LIBRARIES} ${LUAJIT_LIBRARIES})
else (USE_LUAJIT)
if (LUA_BUILD_TYPE STREQUAL System)
target_link_libraries(libluv ${LIBUV_LIBRARIES} ${LUA_LIBRARIES})
else (LUA_BUILD_TYPE STREQUAL System)
target_link_libraries(libluv ${LIBUV_LIBRARIES} lualib)
endif (LUA_BUILD_TYPE STREQUAL System)
endif (USE_LUAJIT)
endif (LUA)
elseif("${CMAKE_SYSTEM_NAME}" MATCHES "Linux")
target_link_libraries(libluv ${LIBUV_LIBRARIES} rt)
else()
target_link_libraries(libluv ${LIBUV_LIBRARIES})
endif()
endif (BUILD_SHARED_LIBS)

if (NOT LUA)
if (BUILD_MODULE)
if (WIN32)
set(INSTALL_LIB_DIR "${CMAKE_INSTALL_PREFIX}/lib")
set(MODULE_INSTALL_LIB_DIR "${CMAKE_INSTALL_PREFIX}/lib")
else (WIN32)
set(INSTALL_LIB_DIR "${CMAKE_INSTALL_PREFIX}/lib/lua/${LUA_VERSION_MAJOR}.${LUA_VERSION_MINOR}")
set(MODULE_INSTALL_LIB_DIR "${CMAKE_INSTALL_PREFIX}/lib/lua/${LUA_VERSION_MAJOR}.${LUA_VERSION_MINOR}")
endif (WIN32)
else (BUILD_MODULE)
set(INSTALL_LIB_DIR "${CMAKE_INSTALL_PREFIX}/lib"
endif (BUILD_MODULE)
if (BUILD_SHARED_LIBS)
set(SHAREDLIBS_INSTALL_LIB_DIR "${CMAKE_INSTALL_PREFIX}/lib"
CACHE PATH "Installation directory for libraries")
set(INSTALL_INC_DIR "${CMAKE_INSTALL_PREFIX}/include/luv"
set(SHAREDLIBS_INSTALL_INC_DIR "${CMAKE_INSTALL_PREFIX}/include/luv"
CACHE PATH "Installation directory for headers")
endif (BUILD_MODULE)
endif (BUILD_SHARED_LIBS)
endif ()

if (CMAKE_INSTALL_PREFIX)
install(TARGETS luv
ARCHIVE DESTINATION "${INSTALL_LIB_DIR}"
LIBRARY DESTINATION "${INSTALL_LIB_DIR}"
)
if (NOT BUILD_MODULE)
if (BUILD_MODULE)
install(TARGETS luv
ARCHIVE DESTINATION "${MODULE_INSTALL_LIB_DIR}"
LIBRARY DESTINATION "${MODULE_INSTALL_LIB_DIR}"
)
endif (BUILD_MODULE)
if (BUILD_SHARED_LIBS)
install(TARGETS libluv
ARCHIVE DESTINATION "${SHAREDLIBS_INSTALL_LIB_DIR}"
LIBRARY DESTINATION "${SHAREDLIBS_INSTALL_LIB_DIR}"
)
if(UNIX)
set(prefix ${CMAKE_INSTALL_PREFIX})
set(includedir ${INSTALL_INC_DIR})
set(libdir ${INSTALL_LIB_DIR})
set(includedir ${SHAREDLIBS_INSTALL_INC_DIR})
set(libdir ${SHAREDLIBS_INSTALL_LIB_DIR})
configure_file(libluv.pc.in ${CMAKE_CURRENT_BINARY_DIR}/libluv.pc @ONLY)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/libluv.pc
DESTINATION ${INSTALL_LIB_DIR}/pkgconfig)
DESTINATION ${SHAREDLIBS_INSTALL_LIB_DIR}/pkgconfig)
endif()
install(
FILES src/luv.h src/util.h src/lhandle.h src/lreq.h
DESTINATION "${INSTALL_INC_DIR}"
DESTINATION "${SHAREDLIBS_INSTALL_INC_DIR}"
)
endif (NOT BUILD_MODULE)
endif (BUILD_SHARED_LIBS)
endif (CMAKE_INSTALL_PREFIX)

0 comments on commit 0494414

Please sign in to comment.