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}
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)
23 include_directories(include)
25 add_subdirectory(test)
27 add_executable(sbltool sbltool.c)
28 target_link_libraries(sbltool sbl)
29 check_library_exists(m sin "" HAVE_LIBM)
31 target_link_libraries(sbltool m)
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)
58 configure_file(sbl.pc.in sbl.pc @ONLY)
61 configure_file(config.h.cm config.h)
62 set(CMAKE_CPP_FLAGS "-DHAVE_CONFIG_H")
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)
71 "${CMAKE_CURRENT_SOURCE_DIR}/cmake/uninstall.cmake.in"
72 "${CMAKE_CURRENT_BINARY_DIR}/uninstall.cmake"
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")