1 cmake_minimum_required(VERSION 3.12)
3 include(CheckIncludeFiles)
5 include(CheckSymbolExists)
7 project(psh VERSION 0.18.0
9 set(PROJECT_DESCRIPTION "P Shell")
11 include_directories(./include)
14 # Check for libreadline
15 find_file(HAVE_READLINE_READLINE_H readline/readline.h)
16 find_library(HAVE_READLINE_GNU NAMES readline)
17 find_library(HAVE_READLINE_ALTS NAMES edit)
18 if(HAVE_READLINE_ALTS)
19 set(HAVE_READLINE ${HAVE_READLINE_ALTS})
22 set(HAVE_READLINE ${HAVE_READLINE_GNU})
24 if(HAVE_READLINE_READLINE_H)
25 string(REPLACE "readline/readline.h" "" INCLUDE_READLINE ${HAVE_READLINE_READLINE_H})
26 include_directories(${INCLUDE_READLINE})
29 message(WARNING "No libreadline or libedit, disabling readline. If you think this is a mistake, try adding -DCMAKE_INCLUDE_PATH=$location/include -DCMAKE_LIBRARY_PATH=$location/lib to the cmake command")
32 # Check for libhistory
33 find_file(HAVE_READLINE_HISTORY_H readline/history.h)
34 find_library(HAVE_HISTORY NAMES history edit)
35 if(HAVE_READLINE_HISTORY_H)
36 string(REPLACE "readline/history.h" "" INCLUDE_HISTORY ${HAVE_READLINE_HISTORY_H})
37 include_directories(${INCLUDE_HISTORY})
39 # Check if libhistory has history_list()
40 if(HAVE_READLINE_HISTORY_H AND HAVE_HISTORY)
41 set(CMAKE_REQUIRED_LIBRARIES "${HAVE_HISTORY}")
42 set(CMAKE_REQUIRED_INCLUDES ${INCLUDE_HISTORY})
43 check_symbol_exists("history_list" "stdio.h;readline/history.h" HAVE_WORKING_HISTORY)
45 if(NOT HAVE_WORKING_HISTORY)
46 message(WARNING "No libhistory, disabling history. If you think this is a mistake, try adding -DCMAKE_INCLUDE_PATH=$location/include -DCMAKE_LIBRARY_PATH=$location/lib to the cmake command")
49 check_type_size(size_t SIZE_T)
50 check_type_size(intptr_t INTPTR_T)
59 configure_file(psh.pc.in psh.pc @ONLY)
62 configure_file(config.h.cm config.h)
63 set(CMAKE_C_FLAGS "-I${CMAKE_BINARY_DIR} -DHAVE_CONFIG_H ${CMAKE_C_FLAGS}")
69 add_custom_target(distclean
70 ${CMAKE_BUILD_TOOL} clean
71 COMMAND ${CMAKE_COMMAND} -D "subdirs=.\;src\;lib\;src/backends/posix2" -P
72 ${CMAKE_SOURCE_DIR}/cmake/distclean.cmake)
75 "${CMAKE_CURRENT_SOURCE_DIR}/cmake/uninstall.cmake.in"
76 "${CMAKE_CURRENT_BINARY_DIR}/uninstall.cmake"
78 add_custom_target(uninstall
79 COMMAND "${CMAKE_COMMAND}" -P "${CMAKE_CURRENT_BINARY_DIR}/uninstall.cmake")
82 install(FILES ${CMAKE_BINARY_DIR}/psh.pc
83 DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)