diff options
Diffstat (limited to 'cmake')
-rw-r--r-- | cmake/FindIconv.cmake | 18 | ||||
-rw-r--r-- | cmake/GetCompileFlags.cmake | 58 | ||||
-rw-r--r-- | cmake/InstallHelpers.cmake | 18 |
3 files changed, 87 insertions, 7 deletions
diff --git a/cmake/FindIconv.cmake b/cmake/FindIconv.cmake new file mode 100644 index 0000000000..f3a54e9d6f --- /dev/null +++ b/cmake/FindIconv.cmake @@ -0,0 +1,18 @@ +# - Try to find iconv +# Once done, this will define +# +# Iconv_FOUND - system has iconv +# Iconv_INCLUDE_DIRS - the iconv include directories +# Iconv_LIBRARIES - link these to use iconv + +include(LibFindMacros) + +find_path(ICONV_INCLUDE_DIR NAMES iconv.h) +find_library(ICONV_LIBRARY NAMES iconv) + +set(Iconv_PROCESS_INCLUDES ICONV_INCLUDE_DIR) +if(ICONV_LIBRARY) + set(Iconv_PROCESS_LIBS ICONV_LIBRARY) +endif() + +libfind_process(Iconv) diff --git a/cmake/GetCompileFlags.cmake b/cmake/GetCompileFlags.cmake new file mode 100644 index 0000000000..e0994b67bc --- /dev/null +++ b/cmake/GetCompileFlags.cmake @@ -0,0 +1,58 @@ +function(get_compile_flags _compile_flags) + # Create template akin to CMAKE_C_COMPILE_OBJECT. + set(compile_flags "<CMAKE_C_COMPILER> <CFLAGS> <BUILD_TYPE_CFLAGS> <DEFINITIONS> <INCLUDES>") + + # Get C compiler. + string(REPLACE + "<CMAKE_C_COMPILER>" + "${CMAKE_C_COMPILER}" + compile_flags + "${compile_flags}") + + # Get flags set by add_definition(). + get_directory_property(definitions + DIRECTORY "src/nvim" + DEFINITIONS) + string(REPLACE + "<DEFINITIONS>" + "${definitions}" + compile_flags + "${compile_flags}") + + # Get general C flags. + string(REPLACE + "<CFLAGS>" + "${CMAKE_C_FLAGS}" + compile_flags + "${compile_flags}") + + # Get C flags specific to build type. + string(TOUPPER "${CMAKE_BUILD_TYPE}" build_type) + string(REPLACE + "<BUILD_TYPE_CFLAGS>" + "${CMAKE_C_FLAGS_${build_type}}" + compile_flags + "${compile_flags}") + + # Get include directories. + get_directory_property(include_directories_list + DIRECTORY "src/nvim" + INCLUDE_DIRECTORIES) + foreach(include_directory ${include_directories_list}) + set(include_directories "${include_directories} -I${include_directory}") + endforeach() + string(REPLACE + "<INCLUDES>" + "${include_directories}" + compile_flags + "${compile_flags}") + + # Clean duplicate whitespace. + string(REPLACE + " " + " " + compile_flags + "${compile_flags}") + + set(${_compile_flags} "${compile_flags}" PARENT_SCOPE) +endfunction() diff --git a/cmake/InstallHelpers.cmake b/cmake/InstallHelpers.cmake index a23bf63ab3..763b2a092c 100644 --- a/cmake/InstallHelpers.cmake +++ b/cmake/InstallHelpers.cmake @@ -22,19 +22,21 @@ function(create_install_dir_with_perms) install(CODE " - if(ENV{DESTDIR}) - # TODO(fwalch): Is this branch ever taken (#1381, #1387)? - set(PREFIX \$ENV{DESTDIR}/\${CMAKE_INSTALL_PREFIX}) - else() - set(PREFIX \${CMAKE_INSTALL_PREFIX}) + if(DEFINED ENV{DESTDIR} AND NOT IS_ABSOLUTE \${CMAKE_INSTALL_PREFIX}) + message(FATAL_ERROR \"Install prefix must be absolute when using DESTDIR\") endif() - set(_current_dir \"\${PREFIX}/${_install_dir_DESTINATION}\") + set(_current_dir \"\${CMAKE_INSTALL_PREFIX}/${_install_dir_DESTINATION}\") set(_dir_permissions \"${_install_dir_DIRECTORY_PERMISSIONS}\") set(_parent_dirs) - while(NOT EXISTS \${_current_dir}) + set(_prev_dir) + + # Explicitly prepend DESTDIR when using EXISTS. + # file(INSTALL ...) implicitly respects DESTDIR, but EXISTS does not. + while(NOT EXISTS \$ENV{DESTDIR}\${_current_dir} AND NOT \${_prev_dir} STREQUAL \${_current_dir}) list(APPEND _parent_dirs \${_current_dir}) + set(_prev_dir \${_current_dir}) get_filename_component(_current_dir \${_current_dir} PATH) endwhile() @@ -47,6 +49,8 @@ function(create_install_dir_with_perms) # 3.0.2. foreach(_current_dir \${_parent_dirs}) if(NOT IS_DIRECTORY \${_current_dir}) + # file(INSTALL ...) implicitly respects DESTDIR, so there's no need to + # prepend it here. file(INSTALL DESTINATION \${_current_dir} TYPE DIRECTORY DIR_PERMISSIONS \${_dir_permissions} |