Update action steps
[slib.git] / CMakeLists.txt
blob709f047cb4375661c8f87ae6e161fc92db6c8785
1 cmake_minimum_required(VERSION 3.0)
3 # Extract version from general.h
4 file(READ include/slib/general.h GENERAL_H)
5 string(REGEX MATCH "SBLLIB_VERSION [0-9]+\n" VER_MAJOR ${GENERAL_H})
6 string(REGEX MATCH "[0-9]+" VER_MAJOR ${VER_MAJOR})
7 string(REGEX MATCH "SBLLIB_MINOR [0-9]+\n" VER_MINOR ${GENERAL_H})
8 string(REGEX MATCH "[0-9]+" VER_MINOR ${VER_MINOR})
9 string(REGEX MATCH "SBLLIB_PATCHLEVEL [0-9]+\n" VER_PL ${GENERAL_H})
10 string(REGEX MATCH "[0-9]+" VER_PL ${VER_PL})
12 project(libsbl VERSION ${VER_MAJOR}.${VER_MINOR}.${VER_PL}
13     LANGUAGES "C")
14 set(PROJECT_DESCRIPTION "A C library providing many useful operations")
16 include(GNUInstallDirs)
17 include(CheckIncludeFiles)
18 include(CheckFunctionExists)
19 include(CheckLibraryExists)
20 include(CheckTypeSize)
22 enable_testing()
23 include_directories(include)
24 add_subdirectory(src)
25 add_subdirectory(test)
27 add_executable(sbltool sbltool.c)
28 target_link_libraries(sbltool sbl)
29 check_library_exists(m sin "" HAVE_LIBM)
30 if (HAVE_LIBM)
31     target_link_libraries(sbltool m)
32 endif()
34 # checks
35 check_include_files(alloca.h HAVE_ALLOCA_H)
36 check_include_files(fcntl.h HAVE_FCNTL_H)
37 check_include_files(stdbool.h HAVE_STDBOOL_H)
38 check_include_files(stdint.h HAVE_STDINT_H)
39 check_include_files(termios.h HAVE_TERMIOS_H)
40 check_include_files(unistd.h HAVE_UNISTD_H)
41 check_function_exists(alloca HAVE_ALLOCA)
42 check_type_size(size_t SIZE_T)
43 check_type_size(intptr_t INTPTR_T)
44 if(NOT SIZE_T)
45     set(size_t int)
46 endif()
47 if(NOT INTPTR_T)
48     set(intptr_t int)
49 endif()
51 if(NOABRT)
52     set(S_NOABRT on)
53 else()
54     set(S_NOABRT 0)
55 endif()
57 # pkg-config file
58 configure_file(sbl.pc.in sbl.pc @ONLY)
60 # config.h
61 configure_file(config.h.cm config.h)
62 set(CMAKE_CPP_FLAGS "-DHAVE_CONFIG_H")
64 # distclean target
65 add_custom_target(distclean
66     ${CMAKE_BUILD_TOOL} clean
67     COMMAND ${CMAKE_COMMAND} -D "subdirs=.\;src\;test" -P
68     ${CMAKE_SOURCE_DIR}/cmake/distclean.cmake)
69 # uninstall target    
70 configure_file(
71     "${CMAKE_CURRENT_SOURCE_DIR}/cmake/uninstall.cmake.in"
72     "${CMAKE_CURRENT_BINARY_DIR}/uninstall.cmake"
73     IMMEDIATE @ONLY)
74 add_custom_target(uninstall
75     COMMAND "${CMAKE_COMMAND}" -P "${CMAKE_CURRENT_BINARY_DIR}/uninstall.cmake")
77 install(TARGETS sbltool DESTINATION ${CMAKE_INSTALL_BINDIR})
78 install(FILES include/slib.h DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
79 install(DIRECTORY include/slib DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
80 install(FILES ${CMAKE_BINARY_DIR}/sbl.pc
81     DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)
82 set(CPACK_INSTALL_CMAKE_PROJECT_NAME "libsbl")
83 include(CPack)