From fa6f8920550571c27fe8c884a282734150d0daea Mon Sep 17 00:00:00 2001 From: b-r-o-c-k Date: Thu, 1 Mar 2018 22:36:30 -0600 Subject: [PATCH] build/msvc: Add CMakeLists.txt and header for Unibilium A header was added for compatibility with MSVC and CMakeLists.txt was added for building with CMake. --- third-party/CMakeLists.txt | 9 ++------ third-party/cmake/BuildUnibilium.cmake | 18 ++++++++++----- third-party/cmake/UnibiliumCMakeLists.txt | 27 +++++++++++++++++++++++ third-party/msvc-compat/unistd.h | 10 +++++++++ 4 files changed, 51 insertions(+), 13 deletions(-) create mode 100644 third-party/cmake/UnibiliumCMakeLists.txt create mode 100644 third-party/msvc-compat/unistd.h diff --git a/third-party/CMakeLists.txt b/third-party/CMakeLists.txt index 4fe896e497..53ec81669b 100644 --- a/third-party/CMakeLists.txt +++ b/third-party/CMakeLists.txt @@ -103,13 +103,8 @@ set(LUA_SHA256 2640fc56a795f29d28ef15e13c34a47e223960b0240e8cb0a82d9b0738695333) set(LUAROCKS_URL https://github.com/luarocks/luarocks/archive/v2.4.3.tar.gz) set(LUAROCKS_SHA256 ea1881d6954f2a98c34f93674571c8f0cbdbc28dedb3fa3cb56b6a91886d1a99) -if(WIN32) - set(UNIBILIUM_URL https://github.com/b-r-o-c-k/unibilium/archive/v2.0.0.tar.gz) - set(UNIBILIUM_SHA256 37a81954f78a27a024b805b330f0b1c082d6c1e9aeed32509a00272c1695cdac) -else() - set(UNIBILIUM_URL https://github.com/mauke/unibilium/archive/v2.0.0.tar.gz) - set(UNIBILIUM_SHA256 78997d38d4c8177c60d3d0c1aa8c53fd0806eb21825b7b335b1768d7116bc1c1) -endif() +set(UNIBILIUM_URL https://github.com/mauke/unibilium/archive/v2.0.0.tar.gz) +set(UNIBILIUM_SHA256 78997d38d4c8177c60d3d0c1aa8c53fd0806eb21825b7b335b1768d7116bc1c1) if(WIN32) set(LIBTERMKEY_URL https://github.com/equalsraf/libtermkey/archive/tb-windows.zip) diff --git a/third-party/cmake/BuildUnibilium.cmake b/third-party/cmake/BuildUnibilium.cmake index d3aa91f11e..f5342e3d34 100644 --- a/third-party/cmake/BuildUnibilium.cmake +++ b/third-party/cmake/BuildUnibilium.cmake @@ -11,12 +11,18 @@ if(WIN32) -DTARGET=unibilium -DUSE_EXISTING_SRC_DIR=${USE_EXISTING_SRC_DIR} -P ${CMAKE_CURRENT_SOURCE_DIR}/cmake/DownloadAndExtractFile.cmake - CONFIGURE_COMMAND ${CMAKE_COMMAND} ${DEPS_BUILD_DIR}/src/unibilium - -DCMAKE_INSTALL_PREFIX=${DEPS_INSTALL_DIR} - # Pass toolchain - -DCMAKE_TOOLCHAIN_FILE=${TOOLCHAIN} - -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} - -DCMAKE_GENERATOR=${CMAKE_GENERATOR} + CONFIGURE_COMMAND ${CMAKE_COMMAND} -E copy + ${CMAKE_CURRENT_SOURCE_DIR}/cmake/UnibiliumCMakeLists.txt + ${DEPS_BUILD_DIR}/src/unibilium/CMakeLists.txt + COMMAND ${CMAKE_COMMAND} -E copy + ${CMAKE_CURRENT_SOURCE_DIR}/msvc-compat/unistd.h + ${DEPS_BUILD_DIR}/src/unibilium/msvc-compat/unistd.h + COMMAND ${CMAKE_COMMAND} ${DEPS_BUILD_DIR}/src/unibilium + -DCMAKE_INSTALL_PREFIX=${DEPS_INSTALL_DIR} + # Pass toolchain + -DCMAKE_TOOLCHAIN_FILE=${TOOLCHAIN} + -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} + -DCMAKE_GENERATOR=${CMAKE_GENERATOR} BUILD_COMMAND ${CMAKE_COMMAND} --build . --config ${CMAKE_BUILD_TYPE} INSTALL_COMMAND ${CMAKE_COMMAND} --build . --target install --config ${CMAKE_BUILD_TYPE}) else() diff --git a/third-party/cmake/UnibiliumCMakeLists.txt b/third-party/cmake/UnibiliumCMakeLists.txt new file mode 100644 index 0000000000..3c419654c4 --- /dev/null +++ b/third-party/cmake/UnibiliumCMakeLists.txt @@ -0,0 +1,27 @@ +cmake_minimum_required(VERSION 2.8.7) +project(unibilium LANGUAGES C) + +file(GLOB SRC_FILES ${PROJECT_SOURCE_DIR}/*.c) +add_library(unibilium ${SRC_FILES}) +set_target_properties(unibilium PROPERTIES PUBLIC_HEADER ${PROJECT_SOURCE_DIR}/unibilium.h + VERSION "${VERSION_MAJOR}.${VERSION_MINOR}") + +if(NOT WIN32) + execute_process(COMMAND "shell ncursesw6-config --terminfo-dirs 2>/dev/null || \ + ncurses6-config --terminfo-dirs 2>/dev/null || \ + ncursesw5-config --terminfo-dirs 2>/dev/null || \ + ncurses5-config --terminfo-dirs 2>/dev/null || \ + echo '/etc/terminfo:/lib/terminfo:/usr/share/terminfo:/usr/lib/terminfo:/usr/local/share/terminfo:/usr/local/lib/terminfo'" + OUTPUT_VARIABLE TERMINFO_DIRS) +endif() +target_compile_definitions(unibilium PUBLIC TERMINFO_DIRS ${TERMINFO_DIRS}) + +if(MSVC) + target_include_directories(unibilium PUBLIC ${PROJECT_SOURCE_DIR}/msvc-compat) +endif() + +include(GNUInstallDirs) +install(TARGETS unibilium + PUBLIC_HEADER + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} + PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}) diff --git a/third-party/msvc-compat/unistd.h b/third-party/msvc-compat/unistd.h new file mode 100644 index 0000000000..d9ee57b54b --- /dev/null +++ b/third-party/msvc-compat/unistd.h @@ -0,0 +1,10 @@ +#ifndef GUARD_UNIBILIUM_UNISTD_H_ +#define GUARD_UNIBILIUM_UNISTD_H_ + +#ifdef _WIN64 +typedef unsigned __int64 ssize_t; +#else +typedef _W64 unsigned int ssize_t; +#endif + +#endif