-
Notifications
You must be signed in to change notification settings - Fork 5
/
CMakeLists.txt
72 lines (61 loc) · 2.69 KB
/
CMakeLists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
cmake_minimum_required(VERSION 3.19)
project(fzf-native C)
# Check compilers
message(STATUS ">>>>>>>> ${CMAKE_CXX_COMPILER_ID}")
message(STATUS ">>>>>>>> ${CMAKE_HOST_SYSTEM_PROCESSOR}")
if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
message(
STATUS "Setting build type to 'RelWithDebInfo' as none was specified.")
set(CMAKE_BUILD_TYPE
"RelWithDebInfo"
CACHE STRING "Choose the type of build." FORCE)
endif()
find_program(EMACS_PROGRAM emacs)
if(EMACS_PROGRAM)
get_filename_component(EMACS_PROGRAM ${EMACS_PROGRAM} REALPATH)
get_filename_component(EMACS_PROGRAM_DIR ${EMACS_PROGRAM} DIRECTORY)
get_filename_component(EMACS_PROGRAM_DIR ${EMACS_PROGRAM_DIR} DIRECTORY)
endif()
if(NOT DEFINED EMACS_INCLUDE_DIR)
set(EMACS_INCLUDE_DIR "")
endif()
# See https://gitlab.kitware.com/cmake/community/-/wikis/doc/tutorials/How-To-Write-Platform-Checks
set(PLATFORM_DIR ${CMAKE_HOST_SYSTEM_NAME})
if(NOT DEFINED FZF_NATIVE_MODULE_OUTPUT_DIR)
if((CMAKE_HOST_SYSTEM_NAME STREQUAL "Darwin") AND (CMAKE_HOST_SYSTEM_PROCESSOR
STREQUAL "arm64"))
# Assume Apple Silicon.
set(FZF_NATIVE_MODULE_OUTPUT_DIR bin/${PLATFORM_DIR}/arm64)
else()
set(FZF_NATIVE_MODULE_OUTPUT_DIR bin/${PLATFORM_DIR})
endif()
endif()
# To build shared libraries in Windows, we set CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS to TRUE.
# See https://cmake.org/cmake/help/v3.4/variable/CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS.html
# See https://blog.kitware.com/create-dlls-on-windows-without-declspec-using-new-cmake-export-all-feature/
set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON)
if(CMAKE_HOST_SYSTEM_NAME STREQUAL "Windows")
# Assume compiler MSVC.
add_library(fzf-native-module SHARED fzf-native-module.c fzf.c fzf.h)
else()
add_library(fzf-native-module MODULE fzf-native-module.c fzf.c fzf.h)
endif()
set(OUTPUT_DIR ${CMAKE_SOURCE_DIR}/${FZF_NATIVE_MODULE_OUTPUT_DIR})
set_target_properties(
fzf-native-module
PROPERTIES C_STANDARD 99
POSITION_INDEPENDENT_CODE ON
PREFIX ""
LIBRARY_OUTPUT_DIRECTORY ${OUTPUT_DIR})
target_include_directories(fzf-native-module PUBLIC ${EMACS_INCLUDE_DIR})
# Set output directory for the library.
# See https://github.com/RoukaVici/LibRoukaVici
set_target_properties(
fzf-native-module
PROPERTIES ARCHIVE_OUTPUT_DIRECTORY ${OUTPUT_DIR}
LIBRARY_OUTPUT_DIRECTORY ${OUTPUT_DIR}
RUNTIME_OUTPUT_DIRECTORY ${OUTPUT_DIR})
# See https://gernotklingler.com/blog/creating-using-shared-libraries-different-compilers-different-operating-systems/
include(GenerateExportHeader)
# generates the export header fzf-native-module_EXPORTS.h automatically.
generate_export_header(fzf-native-module)