build: cmake cleanup

- Simplify error checking when using execute_process.
- Set BUILD_SHARED_LIBS to OFF when building dependencies.
  This is normally not needed, but msgpack interprets an unset
  BUILD_SHARED_LIBS to build a shared library, which is the opposite of
  the cmake behavior.
- Move function check_lua_module to Util.cmake.
- Remove unnecessary code.
- Make variable naming more consistent
This commit is contained in:
dundargoc 2023-05-13 12:12:29 +02:00 committed by GitHub
parent ed8c44f767
commit 1086016477
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
16 changed files with 50 additions and 71 deletions

View File

@ -22,9 +22,11 @@ list(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake")
include(CheckCCompilerFlag)
include(CheckCSourceCompiles)
include(CheckLibraryExists)
include(FindPackageHandleStandardArgs)
include(GNUInstallDirs)
include(InstallHelpers)
include(LuaHelpers)
include(PreventInTreeBuilds)
include(Util)

View File

@ -9,7 +9,9 @@ endif()
# Point CMake at any custom modules we may ship
list(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake" "${PROJECT_SOURCE_DIR}/../cmake")
include(ExternalProject)
include(CheckCCompilerFlag)
include(Util)
set(DEPS_CMAKE_ARGS
@ -17,13 +19,13 @@ set(DEPS_CMAKE_ARGS
-D CMAKE_C_STANDARD=99
-D CMAKE_GENERATOR=${CMAKE_GENERATOR}
-D CMAKE_GENERATOR_PLATFORM=${CMAKE_GENERATOR_PLATFORM}
-D BUILD_SHARED_LIBS=OFF
-D CMAKE_POSITION_INDEPENDENT_CODE=ON
-D CMAKE_FIND_FRAMEWORK=${CMAKE_FIND_FRAMEWORK})
set(DEPS_CMAKE_CACHE_ARGS -DCMAKE_OSX_ARCHITECTURES:STRING=${CMAKE_OSX_ARCHITECTURES})
set_default_buildtype()
get_property(isMultiConfig GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
if(NOT isMultiConfig)
list(APPEND DEPS_CMAKE_ARGS -D CMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE})
@ -132,7 +134,6 @@ if(APPLE)
message(STATUS "Using deployment target ${CMAKE_OSX_DEPLOYMENT_TARGET}")
endif()
include(ExternalProject)
set_directory_properties(PROPERTIES
EP_PREFIX "${DEPS_BUILD_DIR}"
CMAKE_CONFIGURE_DEPENDS deps.txt)

View File

@ -1,4 +1,4 @@
# Luarocks recipe. Luarocks is only required when building Neovim.
# Luarocks recipe. Luarocks is only required when testing Neovim.
# NOTE: LuaRocks rocks need to "DEPENDS" on the previous module, because
# running luarocks in parallel will break, e.g. when some rocks have
# the same dependency.
@ -31,7 +31,7 @@ if(UNIX)
find_package(Luajit)
if(LUAJIT_FOUND)
list(APPEND LUAROCKS_OPTS
--with-lua-include=${LUAJIT_INCLUDE_DIRS}
--with-lua-include=${LUAJIT_INCLUDE_DIR}
--with-lua-interpreter=luajit)
endif()
@ -46,7 +46,7 @@ if(UNIX)
OUTPUT_VARIABLE LUA_VERSION
ERROR_VARIABLE ERR
RESULT_VARIABLE RES)
if(NOT RES EQUAL 0)
if(RES)
message(FATAL_ERROR "Could not get LUA_VERSION with ${LUA_EXE}: ${ERR}")
endif()
endif()

View File

@ -2,7 +2,6 @@ set(LUV_CMAKE_ARGS
-D LUA_BUILD_TYPE=System
-D LUA_COMPAT53_DIR=${DEPS_BUILD_DIR}/src/lua-compat-5.3
-D WITH_SHARED_LIBUV=ON
-D BUILD_SHARED_LIBS=OFF
-D BUILD_STATIC_LIBS=ON
-D BUILD_MODULE=OFF)
@ -38,7 +37,7 @@ ExternalProject_Add(lua-compat-5.3
BUILD_COMMAND ""
INSTALL_COMMAND "")
ExternalProject_Add(luv-static
ExternalProject_Add(luv
DEPENDS lua-compat-5.3
URL ${LUV_URL}
URL_HASH SHA256=${LUV_SHA256}
@ -49,10 +48,10 @@ ExternalProject_Add(luv-static
CMAKE_CACHE_ARGS ${DEPS_CMAKE_CACHE_ARGS})
if(USE_BUNDLED_LUAJIT)
add_dependencies(luv-static luajit)
add_dependencies(luv luajit)
elseif(USE_BUNDLED_LUA)
add_dependencies(luv-static lua)
add_dependencies(luv lua)
endif()
if(USE_BUNDLED_LIBUV)
add_dependencies(luv-static libuv)
add_dependencies(luv libuv)
endif()

View File

@ -7,11 +7,3 @@ ExternalProject_Add(msgpack
-D MSGPACK_BUILD_TESTS=OFF
-D MSGPACK_BUILD_EXAMPLES=OFF
CMAKE_CACHE_ARGS ${DEPS_CMAKE_CACHE_ARGS})
if (NOT MSVC)
add_custom_target(clean_shared_libraries_msgpack ALL
COMMAND ${CMAKE_COMMAND}
-D REMOVE_FILE_GLOB=${DEPS_LIB_DIR}/${CMAKE_SHARED_LIBRARY_PREFIX}*${CMAKE_SHARED_LIBRARY_SUFFIX}*
-P ${PROJECT_SOURCE_DIR}/cmake/RemoveFiles.cmake)
add_dependencies(clean_shared_libraries_msgpack msgpack)
endif()

View File

@ -14,7 +14,7 @@ execute_process(COMMAND ${CMAKE_COMMAND} -E make_directory ${TO})
file(GLOB files ${FROM_GLOB})
foreach(file ${files})
execute_process(COMMAND ${CMAKE_COMMAND} -E copy ${file} ${TO} RESULT_VARIABLE rv)
if(NOT rv EQUAL 0)
if(rv)
message(FATAL_ERROR "Error copying ${file}")
endif()
endforeach()

View File

@ -6,7 +6,7 @@ execute_process(
OUTPUT_VARIABLE trans
ERROR_VARIABLE err
RESULT_VARIABLE res)
if(NOT res EQUAL 0)
if(res)
message(FATAL_ERROR "iconv failed to run correctly: ${err}")
endif()

View File

@ -1,14 +0,0 @@
find_path(LIBLUV_INCLUDE_DIR luv/luv.h)
find_library(LIBLUV_LIBRARY NAMES luv_a luv libluv_a)
# Ubuntu-specific workaround to find system paths
function(ubuntu)
set(CMAKE_FIND_LIBRARY_PREFIXES "")
find_path(LIBLUV_INCLUDE_DIR luv/luv.h PATH_SUFFIXES lua5.1)
find_library(LIBLUV_LIBRARY NAMES luv PATH_SUFFIXES lua/5.1)
endfunction()
ubuntu()
find_package_handle_standard_args(Libluv DEFAULT_MSG
LIBLUV_LIBRARY LIBLUV_INCLUDE_DIR)
mark_as_advanced(LIBLUV_INCLUDE_DIR LIBLUV_LIBRARY)

View File

@ -1,13 +1,7 @@
find_path(LIBUV_INCLUDE_DIR uv.h)
list(APPEND LIBUV_NAMES uv_a uv)
find_library(LIBUV_LIBRARY NAMES ${LIBUV_NAMES})
find_library(LIBUV_LIBRARY NAMES uv_a uv)
set(LIBUV_LIBRARIES ${LIBUV_LIBRARY})
set(LIBUV_INCLUDE_DIRS ${LIBUV_INCLUDE_DIR})
include(CheckLibraryExists)
check_library_exists(dl dlopen "dlfcn.h" HAVE_LIBDL)
if(HAVE_LIBDL)

View File

@ -11,9 +11,6 @@ endif()
find_library(LUAJIT_LIBRARY NAMES ${LUAJIT_NAMES})
set(LUAJIT_LIBRARIES ${LUAJIT_LIBRARY})
set(LUAJIT_INCLUDE_DIRS ${LUAJIT_INCLUDE_DIR})
find_package_handle_standard_args(Luajit DEFAULT_MSG
LUAJIT_LIBRARY LUAJIT_INCLUDE_DIR)

14
cmake/FindLuv.cmake Normal file
View File

@ -0,0 +1,14 @@
find_path(LUV_INCLUDE_DIR luv/luv.h)
find_library(LUV_LIBRARY NAMES luv_a luv libluv_a)
# Ubuntu-specific workaround to find system paths
function(ubuntu)
set(CMAKE_FIND_LIBRARY_PREFIXES "")
find_path(LUV_INCLUDE_DIR luv/luv.h PATH_SUFFIXES lua5.1)
find_library(LUV_LIBRARY NAMES luv PATH_SUFFIXES lua/5.1)
endfunction()
ubuntu()
find_package_handle_standard_args(Luv DEFAULT_MSG
LUV_LIBRARY LUV_INCLUDE_DIR)
mark_as_advanced(LUV_INCLUDE_DIR LUV_LIBRARY)

View File

@ -7,9 +7,6 @@ if(CMAKE_SYSTEM_NAME MATCHES "BSD" AND NOT DEFINED CMAKE_INSTALL_MANDIR)
endif()
endif()
# For $CMAKE_INSTALL_{DATAROOT,MAN, ...}DIR
include(GNUInstallDirs)
# This will create any directories that need to be created in the destination
# path with the typical owner, group, and user permissions--independent of the
# umask setting.

View File

@ -1,14 +0,0 @@
#
# Functions to help checking for a Lua interpreter
#
# Check if a module is available in Lua
function(check_lua_module LUA_PRG_PATH MODULE RESULT_VAR)
execute_process(COMMAND ${LUA_PRG_PATH} -l "${MODULE}" -e ""
RESULT_VARIABLE module_missing)
if(module_missing)
set(${RESULT_VAR} False PARENT_SCOPE)
else()
set(${RESULT_VAR} True PARENT_SCOPE)
endif()
endfunction()

View File

@ -82,7 +82,7 @@ execute_process(
file(GLOB RM_FILES ${BUILD_DIR}/Xtest_*)
file(REMOVE_RECURSE ${RM_FILES})
if(NOT res EQUAL 0)
if(res)
message(STATUS "Tests exited non-zero: ${res}")
if("${err}" STREQUAL "")
message(STATUS "No output to stderr.")

View File

@ -193,3 +193,14 @@ function(set_default_buildtype)
endif()
endif()
endfunction()
# Check if a module is available in Lua
function(check_lua_module LUA_PRG_PATH MODULE RESULT_VAR)
execute_process(COMMAND ${LUA_PRG_PATH} -l "${MODULE}" -e ""
RESULT_VARIABLE module_missing)
if(module_missing)
set(${RESULT_VAR} FALSE PARENT_SCOPE)
else()
set(${RESULT_VAR} TRUE PARENT_SCOPE)
endif()
endfunction()

View File

@ -9,7 +9,7 @@ if(TARGET libuv::uv_a)
else()
# Fall back to find module for older libuv versions that don't provide config file
find_package(Libuv 1.28.0 REQUIRED MODULE)
target_include_directories(libuv SYSTEM BEFORE INTERFACE ${LIBUV_INCLUDE_DIRS})
target_include_directories(libuv SYSTEM BEFORE INTERFACE ${LIBUV_INCLUDE_DIR})
target_link_libraries(libuv INTERFACE ${LIBUV_LIBRARIES})
endif()
@ -21,9 +21,9 @@ elseif(APPLE)
set_target_properties(nlua0 PROPERTIES LINK_FLAGS "-undefined dynamic_lookup")
endif()
find_package(Libluv 1.43.0 REQUIRED)
target_include_directories(main_lib SYSTEM BEFORE INTERFACE ${LIBLUV_INCLUDE_DIR})
target_link_libraries(main_lib INTERFACE ${LIBLUV_LIBRARY})
find_package(Luv 1.43.0 REQUIRED)
target_include_directories(main_lib SYSTEM BEFORE INTERFACE ${LUV_INCLUDE_DIR})
target_link_libraries(main_lib INTERFACE ${LUV_LIBRARY})
find_package(Iconv REQUIRED)
find_package(Lpeg REQUIRED)
@ -61,11 +61,11 @@ if(PREFER_LUA)
find_package(Luajit)
else()
find_package(Luajit REQUIRED)
target_include_directories(main_lib SYSTEM BEFORE INTERFACE ${LUAJIT_INCLUDE_DIRS})
target_link_libraries(main_lib INTERFACE ${LUAJIT_LIBRARIES})
target_include_directories(nlua0 SYSTEM BEFORE PUBLIC ${LUAJIT_INCLUDE_DIRS})
target_include_directories(main_lib SYSTEM BEFORE INTERFACE ${LUAJIT_INCLUDE_DIR})
target_link_libraries(main_lib INTERFACE ${LUAJIT_LIBRARY})
target_include_directories(nlua0 SYSTEM BEFORE PUBLIC ${LUAJIT_INCLUDE_DIR})
if(WIN32)
target_link_libraries(nlua0 PUBLIC ${LUAJIT_LIBRARIES})
target_link_libraries(nlua0 PUBLIC ${LUAJIT_LIBRARY})
endif()
endif()