From 55846a0e42d0e19c31f8f6222c883eb01b53e19c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nils=20O=2E=20Sel=C3=A5sdal?= Date: Sun, 2 Oct 2016 21:39:02 +0200 Subject: [PATCH] Initial conversion to CMake --- CMakeLists.txt | 42 ++++++++++++++++++++++++++++++++++++++++++ include/CMakeLists.txt | 1 + src/CMakeLists.txt | 14 ++++++++++++++ src/version.c.in | 8 ++++---- test/CMakeLists.txt | 8 ++++++++ 5 files changed, 69 insertions(+), 4 deletions(-) create mode 100644 CMakeLists.txt create mode 100644 include/CMakeLists.txt create mode 100644 src/CMakeLists.txt create mode 100644 test/CMakeLists.txt diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..0ee71dd --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,42 @@ +project(libucore C) +cmake_minimum_required(VERSION 3.0.0) + +execute_process(COMMAND git -C ${CMAKE_SOURCE_DIR} describe --abbrev=5 --dirty --always OUTPUT_VARIABLE version_revision WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} OUTPUT_STRIP_TRAILING_WHITESPACE) +execute_process(COMMAND hostname OUTPUT_VARIABLE build_host OUTPUT_STRIP_TRAILING_WHITESPACE) + +set(libucore_VERSION_MAJOR 1) +set(libucore_VERSION_MINOR 0) +set(libucore_VERSION_PATCH 0) +set(libucore_VERSION ${libucore_VERSION_MAJOR}.${libucore_VERSION_MINOR}.${libucore_VERSION_PATCH}.${version_revision}) + +set(CMAKE_VERBOSE_MAKEFILE ON) + +set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -pthread") + + +option(CODE_COVERAGE "build with code coverage intrumentation" OFF) +if (CODE_COVERAGE) + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} --coverage") + add_definitions(-DCOVERAGE) +endif() + +option(BUILD_DEBUG "build debug binaries" ON) +if (BUILD_ENVOY_DEBUG) + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O0") + add_definitions(-DDEBUG) +else() + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O2") + add_definitions(-DNDEBUG) +endif() + +option(BUILD_SANITIZE "build with address sanitizer" OFF) +if (BUILD_SANITIZE) + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=address") +endif() + +include_directories(include) + +add_subdirectory(src) +add_subdirectory(test) +add_subdirectory(include) + diff --git a/include/CMakeLists.txt b/include/CMakeLists.txt new file mode 100644 index 0000000..3e8dcd4 --- /dev/null +++ b/include/CMakeLists.txt @@ -0,0 +1 @@ +install(DIRECTORY ucore DESTINATION include) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt new file mode 100644 index 0000000..6f5d553 --- /dev/null +++ b/src/CMakeLists.txt @@ -0,0 +1,14 @@ +configure_file ( +"version.c.in" +"version.c" +) +file(GLOB SOURCE_FILES *.c) + +add_library( +ucore SHARED +${SOURCE_FILES} +"${PROJECT_BINARY_DIR}/src/version.c" +) +set_target_properties(ucore PROPERTIES SOVERSION 1 VERSION 1.0.0) +target_link_libraries(ucore pthread) +install (TARGETS ucore DESTINATION lib) diff --git a/src/version.c.in b/src/version.c.in index ade8110..fe80391 100644 --- a/src/version.c.in +++ b/src/version.c.in @@ -1,11 +1,11 @@ //Various info about the version and build. //The SConscript file substitutes these at build time -const int ucore_version_major = @version_major@; -const int ucore_version_minor = @version_minor@; -const int ucore_version_patch = @version_patch@; +const int ucore_version_major = @libucore_VERSION_MAJOR@; +const int ucore_version_minor = @libucore_VERSION_MINOR@; +const int ucore_version_patch = @libucore_VERSION_PATCH@; -const char ucore_version_str[] = "@version_str@"; +const char ucore_version_str[] = "@libucore_VERSION@"; const char ucore_build_host[] = "@build_host@"; const char ucore_build_type[] = "@build_type@"; diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt new file mode 100644 index 0000000..39d65c7 --- /dev/null +++ b/test/CMakeLists.txt @@ -0,0 +1,8 @@ +file(GLOB TEST_SOURCE_FILES test_*.c) + +add_executable(test_runner ${TEST_SOURCE_FILES}) +target_link_libraries(test_runner check ucore rt) + +add_custom_target(runtest COMMAND test_runner + DEPENDS test_runner + WORKING_DIRECTORY ${CMAKE_PROJECT_DIR})