Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make libdict using cmake #38

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
BasedOnStyle: None
44 changes: 44 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
cmake_minimum_required(VERSION 2.8)
set(_ECLIPSE_VERSION 4.5)
project(libdict)

enable_language(C)
add_definitions(-std=c11)

set(LIBDICT_SOURCES
src/dict.c
src/hashtable.c
src/hashtable2.c
src/hashtable_common.c
src/hb_tree.c
src/pr_tree.c
src/rb_tree.c
src/skiplist.c
src/sp_tree.c
src/tr_tree.c
src/tree_common.c
src/wb_tree.c
)

include_directories(include)
include_directories(src)

add_library(dict STATIC ${LIBDICT_SOURCES})
if(CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64" )
set_target_properties(dict PROPERTIES COMPILE_FLAGS "-fPIC")
endif(CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64" )
set_target_properties(dict PROPERTIES PREFIX "lib")

list(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}")
find_package(CUnit REQUIRED)
enable_testing()
add_executable(dict_test unit_tests.c)
target_include_directories(dict_test PRIVATE ${CUNIT_INCLUDE_DIRS})
target_link_libraries (dict_test dict)
target_link_libraries(dict_test ${CUNIT_LIBRARIES})

add_test(
NAME dict_test
COMMAND dict_test
WORKING_DIRECTORY ${CMAKE_BINARY_DIR})

19 changes: 19 additions & 0 deletions FindCUnit.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# CUNIT_INCLUDE_DIRS - where to find <CUnit/CUnit.h>, etc.
# CUNIT_LIBRARIES - List of libraries when using libcunit.
# CUNIT_FOUND - True if libcunit found.
if(CUNIT_INCLUDE_DIRS)
# Already in cache, be silent
set(CUNIT_FIND_QUIETLY YES)
endif()

find_path(CUNIT_INCLUDE_DIRS CUnit/CUnit.h)
find_library(CUNIT_LIBRARY NAMES cunit libcunit)

# handle the QUIETLY and REQUIRED arguments and set CUNIT_FOUND to TRUE if
# all listed variables are TRUE
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(CUNIT DEFAULT_MSG CUNIT_LIBRARY CUNIT_INCLUDE_DIRS)

if(CUNIT_FOUND)
set(CUNIT_LIBRARIES ${CUNIT_LIBRARY})
endif()