Add cmake build system

This commit is contained in:
rexy712 2020-04-04 22:24:10 -07:00
parent e37ead5e9b
commit cb25ad6342
3 changed files with 58 additions and 0 deletions

1
.gitignore vendored
View File

@ -8,3 +8,4 @@ obj
*.d
test.cpp
tester.cpp
pc/librexy.pc

48
CMakeLists.txt Normal file
View File

@ -0,0 +1,48 @@
include(GNUInstallDirs)
cmake_minimum_required(VERSION 3.0.2)
project(librexy)
set(librexy_VERSION_MAJOR 0)
set(librexy_VERSION_MINOR 1)
set(librexy_VERSION_REVISION 0)
set(INCLUDE_PATH ${CMAKE_SOURCE_DIR})
include_directories("${INCLUDE_PATH}")
set(LIBREXY_LIBFLAGS "-lrexy")
option(ENABLE_SHARED "Build shared library" ON)
option(ENABLE_PROFILING "Enable asan" OFF)
mark_as_advanced(ENABLE_PROFILING)
set(SOURCE_LIST "rexy/src/binary.cpp" "rexy/src/string_base.cpp" "rexy/src/filerd.cpp")
if(ENABLE_SHARED)
add_library(rexy SHARED ${SOURCE_LIST})
set_target_properties(rexy PROPERTIES SOVERSION "${librexy_VERSION_MAJOR}.${librexy_VERSION_MINOR}.${librexy_VERSION_REVISION}")
else()
add_library(rexy STATIC ${SOURCE_LIST})
endif()
if(ENABLE_PROFILING)
target_compile_options(rexy PRIVATE -fsanitize=address -fno-omit-frame-pointer -fno-optimize-sibling-calls)
target_link_options(rexy PRIVATE -fsanitize=address -fno-omit-frame-pointer -fno-optimize-sibling-calls)
endif()
set(LIBREXY_PUBLIC_HEADERS "rexy/include/binary.hpp" "rexy/include/string_base.hpp" "rexy/include/string.hpp" "rexy/include/filerd.hpp" "rexy/include/string_base.tpp" "rexy/include/detail/binary_string_conv.hpp" "rexy/include/detail/default_allocator.hpp" "rexy/include/detail/util.hpp")
target_compile_options(rexy PRIVATE -Wall -Wextra -pedantic -std=c++17)
install(TARGETS rexy
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
)
install(FILES "${CMAKE_CURRENT_SOURCE_DIR}/pc/librexy.pc"
DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig"
)
install(FILES ${LIBREXY_PUBLIC_HEADERS} DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/rexy/")
configure_file(
"${CMAKE_CURRENT_SOURCE_DIR}/pc/librexy.pc.cmake.in"
"${CMAKE_CURRENT_SOURCE_DIR}/pc/librexy.pc"
@ONLY
)
add_custom_target(uninstall cat install_manifest.txt | xargs rm)

9
pc/librexy.pc.cmake.in Normal file
View File

@ -0,0 +1,9 @@
libdir=@CMAKE_INSTALL_FULL_LIBDIR@
includedir=@CMAKE_INSTALL_FULL_INCLUDEDIR@
Name: librexy
Description: Rexy's common utilities for C++
URL: https://gitlab.com/rexy712/librexy
Version: @librexy_VERSION_MAJOR@.@librexy_VERSION_MINOR@.@librexy_VERSION_REVISION@
Libs: -L${libdir} @LIBREXY_LIBFLAGS@
Cflags: -I${includedir}