Merge pull request #35 from DevManu-de/dev-redirect-handle
[psh.git] / CMakeLists.txt
blob650419e2f179a9544942bca1ba12dca86a4c4aad
1 cmake_minimum_required(VERSION 3.12)
3 include(CheckIncludeFiles)
4 include(CheckTypeSize)
5 include(CheckSymbolExists)
7 project(psh VERSION 0.18.0
8     LANGUAGES "C")
9 set(PROJECT_DESCRIPTION "P Shell")
10 #enable_testing()
11 include_directories(./include)
13 # checks
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})
20 endif()
21 if(HAVE_READLINE_GNU)
22         set(HAVE_READLINE ${HAVE_READLINE_GNU})
23 endif()
24 if(HAVE_READLINE_READLINE_H)
25     string(REPLACE "readline/readline.h" "" INCLUDE_READLINE ${HAVE_READLINE_READLINE_H})
26         include_directories(${INCLUDE_READLINE})
27 endif()
28 if(NOT HAVE_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")
30 endif()
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})
38 endif()
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)
44 endif()
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")
47 endif()
49 check_type_size(size_t SIZE_T)
50 check_type_size(intptr_t INTPTR_T)
51 if(NOT SIZE_T)
52     set(size_t int)
53 endif()
54 if(NOT INTPTR_T)
55     set(intptr_t long)
56 endif()
58 # pkg-config file
59 configure_file(psh.pc.in psh.pc @ONLY)
61 # config.h
62 configure_file(config.h.cm config.h)
63 set(CMAKE_C_FLAGS "-I${CMAKE_BINARY_DIR} -DHAVE_CONFIG_H ${CMAKE_C_FLAGS}")
65 add_subdirectory(lib)
66 add_subdirectory(src)
68 # distclean target
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)
73 # uninstall target
74 configure_file(
75     "${CMAKE_CURRENT_SOURCE_DIR}/cmake/uninstall.cmake.in"
76     "${CMAKE_CURRENT_BINARY_DIR}/uninstall.cmake"
77     IMMEDIATE @ONLY)
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)