Skip to content

Update CMake build and dlib version #221

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

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
72 changes: 72 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
cmake_minimum_required(VERSION 3.10)
project(mitie_project)


option(BUILD_SHARED_LIBS "mitie: build shared libraries" ON)
option(MITIE_INTEGRATED_DLIB "mitie: build and statically link integrated dlib as shipped with MITIE codebase (otherwise look for system dlib)" ON)
option(MITIE_INTEGRATED_DLIB_DISABLE_OPT_COMPONENTS "mitie: disable optional components not required for MITIE when building integrated dlib (image libraries, FFmpeg, SQLite3)" ON)
option(MITIE_BUILD_TOOLS "mitie: build tools" ON)
option(MITIE_BUILD_C_EXAMPLES "mitie: build C examples" ON)
option(MITIE_BUILD_CPP_EXAMPLES "mitie: build C++ examples" ON)
option(MITIE_APPLY_EXECUTABLES_PREFIX "mitie: add 'mitie-' prefix to executables" OFF)
option(MITIE_APPLY_EXAMPLES_SUFFIX "mitie: add '_example' suffix to executables for C and C++ examples" ON)


set(CMAKE_EXPORT_COMPILE_COMMANDS ON)


if(MITIE_APPLY_EXECUTABLES_PREFIX)
set(MITIE_EXECUTABLES_PREFIX "mitie-")
else()
set(MITIE_EXECUTABLES_PREFIX "")
endif()

if(MITIE_APPLY_EXAMPLES_SUFFIX)
set(MITIE_EXAMPLES_SUFFIX "_example")
else()
set(MITIE_EXAMPLES_SUFFIX "")
endif()


# Build integrated dlib if requested
if(MITIE_INTEGRATED_DLIB)
if(MITIE_INTEGRATED_DLIB_DISABLE_OPT_COMPONENTS)
set(DLIB_PNG_SUPPORT OFF CACHE STRING "not needed by MITIE" FORCE)
set(DLIB_JPEG_SUPPORT OFF CACHE STRING "not needed by MITIE" FORCE)
set(DLIB_JXL_SUPPORT OFF CACHE STRING "not needed by MITIE" FORCE)
set(DLIB_GIF_SUPPORT OFF CACHE STRING "not needed by MITIE" FORCE)
set(DLIB_WEBP_SUPPORT OFF CACHE STRING "not needed by MITIE" FORCE)
set(DLIB_USE_FFMPEG OFF CACHE STRING "not needed by MITIE" FORCE)
set(DLIB_LINK_WITH_SQLITE3 OFF CACHE STRING "not needed by MITIE" FORCE)
endif()

add_subdirectory(dlib)
endif()


# MITIE core library
add_subdirectory(mitielib)

# MITIE tools
if(MITIE_BUILD_TOOLS)
add_subdirectory(tools/ner_conll)
add_subdirectory(tools/ner_stream)
add_subdirectory(tools/train_freebase_relation_detector)
add_subdirectory(tools/wordrep)
endif()

# MITIE examples
if(MITIE_BUILD_C_EXAMPLES)
add_subdirectory(examples/C/ner)
add_subdirectory(examples/C/relation_extraction)
endif()

if(MITIE_BUILD_CPP_EXAMPLES)
add_subdirectory(examples/cpp/ner)
add_subdirectory(examples/cpp/relation_extraction)
add_subdirectory(examples/cpp/text_categorizer)
add_subdirectory(examples/cpp/train_ner)
add_subdirectory(examples/cpp/train_relation_extraction)
add_subdirectory(examples/cpp/train_text_categorizer)
add_subdirectory(examples/cpp/train_text_categorizer_BoW)
endif()
6 changes: 4 additions & 2 deletions examples/C/ner/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
# information about it at http://www.cmake.org
#

cmake_minimum_required(VERSION 2.6)
cmake_minimum_required(VERSION 3.10)



set(project_name ner_example)
set(project_name "${MITIE_EXECUTABLES_PREFIX}ner_c${MITIE_EXAMPLES_SUFFIX}")
set(source
ner_example.c
)
Expand All @@ -23,3 +23,5 @@ ADD_EXECUTABLE(${project_name} ${source})
TARGET_LINK_LIBRARIES(${project_name} mitie)


include(GNUInstallDirs)
install(TARGETS ${project_name})
6 changes: 4 additions & 2 deletions examples/C/relation_extraction/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
# information about it at http://www.cmake.org
#

cmake_minimum_required(VERSION 2.6)
cmake_minimum_required(VERSION 3.10)



set(project_name relation_extraction_example)
set(project_name "${MITIE_EXECUTABLES_PREFIX}relation_extraction_c${MITIE_EXAMPLES_SUFFIX}")
set(source
relation_extraction_example.c
)
Expand All @@ -23,3 +23,5 @@ ADD_EXECUTABLE(${project_name} ${source})
TARGET_LINK_LIBRARIES(${project_name} mitie)


include(GNUInstallDirs)
install(TARGETS ${project_name})
6 changes: 4 additions & 2 deletions examples/cpp/ner/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
# information about it at http://www.cmake.org
#

cmake_minimum_required(VERSION 2.6)
cmake_minimum_required(VERSION 3.10)



set(project_name ner_example)
set(project_name "${MITIE_EXECUTABLES_PREFIX}ner${MITIE_EXAMPLES_SUFFIX}")
set(source
ner_example.cpp
)
Expand All @@ -23,3 +23,5 @@ ADD_EXECUTABLE(${project_name} ${source})
TARGET_LINK_LIBRARIES(${project_name} mitie)


include(GNUInstallDirs)
install(TARGETS ${project_name})
6 changes: 4 additions & 2 deletions examples/cpp/relation_extraction/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
# information about it at http://www.cmake.org
#

cmake_minimum_required(VERSION 2.6)
cmake_minimum_required(VERSION 3.10)



set(project_name relation_extraction_example)
set(project_name "${MITIE_EXECUTABLES_PREFIX}relation_extraction${MITIE_EXAMPLES_SUFFIX}")
set(source
relation_extraction_example.cpp
)
Expand All @@ -23,3 +23,5 @@ ADD_EXECUTABLE(${project_name} ${source})
TARGET_LINK_LIBRARIES(${project_name} mitie)


include(GNUInstallDirs)
install(TARGETS ${project_name})
6 changes: 4 additions & 2 deletions examples/cpp/text_categorizer/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
# information about it at http://www.cmake.org
#

cmake_minimum_required(VERSION 2.6)
cmake_minimum_required(VERSION 3.10)



set(project_name text_categorizer_example)
set(project_name "${MITIE_EXECUTABLES_PREFIX}text_categorizer${MITIE_EXAMPLES_SUFFIX}")
set(source
text_categorizer_example.cpp
)
Expand All @@ -23,3 +23,5 @@ ADD_EXECUTABLE(${project_name} ${source})
TARGET_LINK_LIBRARIES(${project_name} mitie)


include(GNUInstallDirs)
install(TARGETS ${project_name})
6 changes: 4 additions & 2 deletions examples/cpp/train_ner/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
# information about it at http://www.cmake.org
#

cmake_minimum_required(VERSION 2.6)
cmake_minimum_required(VERSION 3.10)



set(project_name train_ner_example)
set(project_name "${MITIE_EXECUTABLES_PREFIX}train_ner${MITIE_EXAMPLES_SUFFIX}")
set(source
train_ner_example.cpp
)
Expand All @@ -23,3 +23,5 @@ ADD_EXECUTABLE(${project_name} ${source})
TARGET_LINK_LIBRARIES(${project_name} mitie)


include(GNUInstallDirs)
install(TARGETS ${project_name})
6 changes: 4 additions & 2 deletions examples/cpp/train_relation_extraction/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
# information about it at http://www.cmake.org
#

cmake_minimum_required(VERSION 2.6)
cmake_minimum_required(VERSION 3.10)



set(project_name train_relation_extraction_example)
set(project_name "${MITIE_EXECUTABLES_PREFIX}train_relation_extraction${MITIE_EXAMPLES_SUFFIX}")
set(source
train_relation_extraction_example.cpp
)
Expand All @@ -23,3 +23,5 @@ ADD_EXECUTABLE(${project_name} ${source})
TARGET_LINK_LIBRARIES(${project_name} mitie)


include(GNUInstallDirs)
install(TARGETS ${project_name})
6 changes: 4 additions & 2 deletions examples/cpp/train_text_categorizer/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
# information about it at http://www.cmake.org
#

cmake_minimum_required(VERSION 2.6)
cmake_minimum_required(VERSION 3.10)



set(project_name train_text_categorizer_example)
set(project_name "${MITIE_EXECUTABLES_PREFIX}train_text_categorizer${MITIE_EXAMPLES_SUFFIX}")
set(source
train_text_categorizer_example.cpp
)
Expand All @@ -23,3 +23,5 @@ ADD_EXECUTABLE(${project_name} ${source})
TARGET_LINK_LIBRARIES(${project_name} mitie)


include(GNUInstallDirs)
install(TARGETS ${project_name})
6 changes: 4 additions & 2 deletions examples/cpp/train_text_categorizer_BoW/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
# information about it at http://www.cmake.org
#

cmake_minimum_required(VERSION 2.6)
cmake_minimum_required(VERSION 3.10)



set(project_name train_text_categorizer_BoW_example)
set(project_name "${MITIE_EXECUTABLES_PREFIX}train_text_categorizer_BoW${MITIE_EXAMPLES_SUFFIX}")
set(source
train_text_categorizer_BoW_example.cpp
)
Expand All @@ -23,3 +23,5 @@ ADD_EXECUTABLE(${project_name} ${source})
TARGET_LINK_LIBRARIES(${project_name} mitie)


include(GNUInstallDirs)
install(TARGETS ${project_name})
10 changes: 9 additions & 1 deletion merge_changes_from_dlib
Original file line number Diff line number Diff line change
@@ -1 +1,9 @@
git subtree pull --prefix dlib https://github.com/davisking/dlib.git master --squash
#!/bin/sh

DLIB_LATEST_TAG=$(git ls-remote --tags https://github.com/davisking/dlib.git | \
awk '/refs\/tags\/v/ {print $2}' | \
sed 's|refs/tags/||' | \
sort -V | \
tail -n 1)

git subtree pull --prefix dlib https://github.com/davisking/dlib.git $DLIB_LATEST_TAG --squash
94 changes: 69 additions & 25 deletions mitielib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,33 +2,18 @@
# This is a CMake makefile. You can find the cmake utility and
# information about it at http://www.cmake.org
#
cmake_minimum_required(VERSION 3.12)
project(mitie VERSION 0.7 LANGUAGES C CXX)

# setting this makes CMake allow normal looking if else statements
SET(CMAKE_ALLOW_LOOSE_LOOP_CONSTRUCTS true)

cmake_minimum_required(VERSION 2.4)

# Suppress cmake warnings about changes in new versions.
if(COMMAND cmake_policy)
cmake_policy(SET CMP0003 NEW)
endif()

set(CMAKE_POSITION_INDEPENDENT_CODE True)
include(tell_visual_studio_to_use_static_runtime.cmake)


if (NOT TARGET mitie)
if (NOT DEFINED BUILD_SHARED_LIBS)
set(BUILD_SHARED_LIBS 1)
set(BUILD_SHARED_LIBS ON)
endif()

set(DLIB_LINK_WITH_LIBPNG OFF CACHE STRING "not needed by MITIE" FORCE)
set(DLIB_LINK_WITH_LIBJPEG OFF CACHE STRING "not needed by MITIE" FORCE)
set(DLIB_LINK_WITH_SQLITE3 OFF CACHE STRING "not needed by MITIE" FORCE)


include(../dlib/dlib/cmake)
include_directories(include)

set(source_files
src/stemmer.cpp
src/ner_feature_extraction.cpp
Expand All @@ -45,12 +30,71 @@ if (NOT TARGET mitie)
)

add_library(mitie ${source_files})
target_link_libraries(mitie dlib)
set_target_properties(mitie PROPERTIES POSITION_INDEPENDENT_CODE ON)
target_compile_definitions(mitie PRIVATE MITIE_BUILD)

if(BUILD_SHARED_LIBS)
target_compile_definitions(mitie PUBLIC MITIE_SHARED)
endif()

target_include_directories(mitie PUBLIC include)

if(MITIE_INTEGRATED_DLIB)
target_link_libraries(mitie dlib)
else()
find_package(dlib REQUIRED)
if (NOT dlib_FOUND)
message(FATAL_ERROR "System-installed dlib not found.")
endif()
target_link_libraries(mitie dlib::dlib)
endif()

# Omit lib prefix on Windows MinGW
if (WIN32)
set(CMAKE_STATIC_LIBRARY_PREFIX "")
set(CMAKE_SHARED_LIBRARY_PREFIX "")
set(CMAKE_SHARED_MODULE_PREFIX "")
endif()


include(GNUInstallDirs)
install(TARGETS mitie)
install(DIRECTORY include/
TYPE INCLUDE
FILES_MATCHING REGEX ".*\.h(pp)?$"
)


include(CMakePackageConfigHelpers)

#
# Generate metadata for pkg-config
#
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/mitie.pc.in"
"${CMAKE_CURRENT_BINARY_DIR}/mitie.pc"
@ONLY)

install(FILES "${CMAKE_CURRENT_BINARY_DIR}/mitie.pc"
DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig")

#
# Generate metadata for CMake package
#
configure_package_config_file(
${CMAKE_CURRENT_SOURCE_DIR}/mitie-config.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/mitie-config.cmake
INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/mitie
)

write_basic_package_version_file(
${CMAKE_CURRENT_BINARY_DIR}/mitie-version.cmake
VERSION ${MITIE_VERSION}
COMPATIBILITY SameMajorVersion
)

# Determine the path to our CMakeLists.txt file.
string(REGEX REPLACE "CMakeLists.txt$" "" base_path ${CMAKE_CURRENT_LIST_FILE})
install(TARGETS mitie
DESTINATION ${base_path}
)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/mitie-config.cmake
${CMAKE_CURRENT_BINARY_DIR}/mitie-version.cmake
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/mitie
)

endif()
Loading