From 049441416dea6276fa1b836a0471fba79c5d3120 Mon Sep 17 00:00:00 2001 From: Doron Behar Date: Wed, 26 Feb 2020 19:08:40 +0200 Subject: [PATCH] CMake: Make BUILD_MODULE and BUILD_SHARED_LIBS non inclusive Fixes https://github.com/luvit/luv/issues/457 and fixes https://github.com/NixOS/nixpkgs/pull/80528 --- CMakeLists.txt | 75 +++++++++++++++++++++++++++++++++++--------------- 1 file changed, 53 insertions(+), 22 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 8928a294..7fe94a24 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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 @@ -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) @@ -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)