From 203501c14afaf6704d965de0ae7de3474424d166 Mon Sep 17 00:00:00 2001 From: "Hoa V. DINH" Date: Tue, 25 Nov 2014 15:22:09 -0800 Subject: Refactored CMakefiles, unit tests for Linux enabled --- CMakeLists.txt | 178 +++++++++++++++++++++++++++++++++++++++++++++++ scripts/travis/script.sh | 2 + src/CMakeLists.txt | 169 -------------------------------------------- tests/CMakeLists.txt | 23 ++---- unittest/CMakeLists.txt | 16 +++++ unittest/unittest.cpp | 4 ++ 6 files changed, 207 insertions(+), 185 deletions(-) create mode 100644 unittest/CMakeLists.txt diff --git a/CMakeLists.txt b/CMakeLists.txt index 7e66aa16..369819f2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4,12 +4,190 @@ project (mailcore2) IF(APPLE) set(CMAKE_CXX__FLAGS "-std=c++11 -stdlib=libc++") set(CMAKE_EXE_LINKER_FLAGS "-lc++ -stdlib=libc++") + + set(additional_lib_searchpath + "${CMAKE_CURRENT_SOURCE_DIR}/Externals/ctemplate-osx/lib" + "${CMAKE_CURRENT_SOURCE_DIR}/Externals/uchardet-osx/lib" + "${CMAKE_CURRENT_SOURCE_DIR}/Externals/libetpan-osx/lib" + ) + + set(additional_includes + "${CMAKE_CURRENT_SOURCE_DIR}/Externals/ctemplate-osx/include" + "${CMAKE_CURRENT_SOURCE_DIR}/Externals/uchardet-osx/include" + "${CMAKE_CURRENT_SOURCE_DIR}/Externals/libetpan-osx/include" + /usr/include/tidy + /usr/include/libxml2 + ) + + set(mac_libraries iconv) + +ELSEIF(${CMAKE_SYSTEM_NAME} MATCHES "Linux") + set(CMAKE_CXX_FLAGS "-std=gnu++0x") + + set(additional_includes + /usr/include/libxml2 + ) + + #set(icu_libraries icudata icui18n icuio icule iculx icutest icutu icuuc) + set(linux_libraries pthread uuid) ENDIF() + IF(${CMAKE_SYSTEM_NAME} MATCHES "Linux") find_package(PkgConfig) + pkg_check_modules (GLIB2 glib-2.0) ENDIF() +IF(APPLE) + find_library(FOUNDATIONFRAMEWORK NAMES Foundation) + find_library(SECURITYFRAMEWORK NAMES Security) + find_library(CORESERVICESFRAMEWORK NAMES CoreServices) +ENDIF() + +if(NOT APPLE) + + # detect icu + + find_path(ICU4C_INCLUDE_DIR + NAMES unicode/utf8.h + PATHS ${additional_includes} + ) + find_library(ICU4C_LIBRARY + NAMES icudata icui18n icuio icule iculx icutest icutu icuuc + PATHS ${additional_lib_searchpath} + ) + + if(NOT ICU4C_INCLUDE_DIR OR NOT ICU4C_LIBRARY) + message(FATAL_ERROR "ERROR: Could not find icu4c") + else() + message(STATUS "Found icu4c") + endif() + +endif() + + +# detect ctemplate + +find_path(CTEMPLATE_INCLUDE_DIR + NAMES ctemplate/template.h + PATHS ${additional_includes} +) +find_library(CTEMPLATE_LIBRARY + NAMES ctemplate + PATHS ${additional_lib_searchpath} +) + +if(NOT CTEMPLATE_INCLUDE_DIR OR NOT CTEMPLATE_LIBRARY) + message(FATAL_ERROR "ERROR: Could not find ctemplate") +else() + message(STATUS "Found ctemplate") +endif() + + +# detect uchardet + +find_path(UCHARDET_INCLUDE_DIR + NAMES uchardet/uchardet.h + PATHS ${additional_includes} +) +find_library(UCHARDET_LIBRARY + NAMES uchardet + PATHS ${additional_lib_searchpath} +) + +if(NOT UCHARDET_INCLUDE_DIR OR NOT UCHARDET_LIBRARY) + message(FATAL_ERROR "ERROR: Could not find uchardet") +else() + message(STATUS "Found uchardet") +endif() + + +# detect libetpan + +find_path(LIBETPAN_INCLUDE_DIR + NAMES libetpan/libetpan.h + PATHS ${additional_includes} +) +find_library(LIBETPAN_LIBRARY + NAMES etpan + PATHS ${additional_lib_searchpath} +) + +if(NOT LIBETPAN_INCLUDE_DIR OR NOT LIBETPAN_LIBRARY) + message(FATAL_ERROR "ERROR: Could not find libetpan") +else() + message(STATUS "Found libetpan") +endif() + + +# detect tidy + +find_path(TIDY_INCLUDE_DIR + NAMES tidy/tidy.h + PATHS ${additional_includes} +) +find_library(TIDY_LIBRARY + NAMES tidy + PATHS ${additional_lib_searchpath} +) + +if(NOT TIDY_INCLUDE_DIR OR NOT TIDY_LIBRARY) + message(FATAL_ERROR "ERROR: Could not find tidy") +else() + message(STATUS "Found tidy") +endif() + + +# detect uuid + +find_path(UUID_INCLUDE_DIR + NAMES uuid/uuid.h + PATHS ${additional_includes} +) + +if(NOT UUID_INCLUDE_DIR) + message(FATAL_ERROR "ERROR: Could not find uuid") +else() + message(STATUS "Found uuid") +endif() + + +# detect libxml2 + +find_path(LIBXML_INCLUDE_DIR + NAMES libxml/xmlreader.h + PATHS ${additional_includes} +) +find_library(LIBXML_LIBRARY + NAMES xml2 + PATHS ${additional_lib_searchpath} +) + +if(NOT LIBXML_INCLUDE_DIR OR NOT LIBXML_LIBRARY) + message(FATAL_ERROR "ERROR: Could not find libxml2") +else() + message(STATUS "Found libxml2") +endif() + + +# detect zlib + +find_path(ZLIB_INCLUDE_DIR + NAMES zlib.h + PATHS ${additional_includes} +) +find_library(ZLIB_LIBRARY + NAMES z + PATHS ${additional_lib_searchpath} +) + +if(NOT ZLIB_INCLUDE_DIR OR NOT ZLIB_LIBRARY) + message(FATAL_ERROR "ERROR: Could not find zlib") +else() + message(STATUS "Found zlib") +endif() + add_subdirectory (src) add_subdirectory (tests) +add_subdirectory (unittest) diff --git a/scripts/travis/script.sh b/scripts/travis/script.sh index 41348f41..8482eca8 100755 --- a/scripts/travis/script.sh +++ b/scripts/travis/script.sh @@ -41,3 +41,5 @@ mkdir -p build-cmake cd build-cmake cmake .. make +cd unittest +./unittestcpp ../../unittest/data diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index dd506d27..858d796d 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,9 +1,4 @@ set(CMAKE_INCLUDE_CURRENT_DIR ON) -IF(APPLE) - set(CMAKE_CXX_FLAGS "-std=c++11 -stdlib=libc++") -ELSE() - set(CMAKE_CXX_FLAGS "-std=gnu++0x") -ENDIF() set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake") include(public-headers) @@ -13,170 +8,8 @@ include(objc) include(LibFindMacros) IF(APPLE) - set(additional_includes - "${CMAKE_CURRENT_SOURCE_DIR}/../Externals/ctemplate-osx/include" - "${CMAKE_CURRENT_SOURCE_DIR}/../Externals/uchardet-osx/include" - "${CMAKE_CURRENT_SOURCE_DIR}/../Externals/libetpan-osx/include" - /usr/include/tidy - /usr/include/libxml2 - ) - - set(additional_lib_searchpath - "${CMAKE_CURRENT_SOURCE_DIR}/../Externals/ctemplate-osx/lib" - "${CMAKE_CURRENT_SOURCE_DIR}/../Externals/uchardet-osx/lib" - "${CMAKE_CURRENT_SOURCE_DIR}/../Externals/libetpan-osx/lib" - ) - execute_process(COMMAND "${CMAKE_CURRENT_SOURCE_DIR}/../scripts/get-mac.sh" WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/../scripts") -ELSE() - set(additional_includes - /usr/include/libxml2 - ) -ENDIF() - -# detect ctemplate - -find_path(CTEMPLATE_INCLUDE_DIR - NAMES ctemplate/template.h - PATHS ${additional_includes} -) -find_library(CTEMPLATE_LIBRARY - NAMES ctemplate - PATHS ${additional_lib_searchpath} -) - -if(NOT CTEMPLATE_INCLUDE_DIR OR NOT CTEMPLATE_LIBRARY) - message(FATAL_ERROR "ERROR: Could not find ctemplate") -else() - message(STATUS "Found ctemplate") -endif() - -# detect uchardet - -find_path(UCHARDET_INCLUDE_DIR - NAMES uchardet/uchardet.h - PATHS ${additional_includes} -) -find_library(UCHARDET_LIBRARY - NAMES uchardet - PATHS ${additional_lib_searchpath} -) - -if(NOT UCHARDET_INCLUDE_DIR OR NOT UCHARDET_LIBRARY) - message(FATAL_ERROR "ERROR: Could not find uchardet") -else() - message(STATUS "Found uchardet") -endif() - -if(NOT APPLE) - - # detect icu - - find_path(ICU4C_INCLUDE_DIR - NAMES unicode/utf8.h - PATHS ${additional_includes} - ) - find_library(ICU4C_LIBRARY - NAMES icuuc - PATHS ${additional_lib_searchpath} - ) - - if(NOT ICU4C_INCLUDE_DIR OR NOT ICU4C_LIBRARY) - message(FATAL_ERROR "ERROR: Could not find icu4c") - else() - message(STATUS "Found icu4c") - endif() - -endif() - -# detect libetpan - -find_path(LIBETPAN_INCLUDE_DIR - NAMES libetpan/libetpan.h - PATHS ${additional_includes} -) -find_library(LIBETPAN_LIBRARY - NAMES etpan - PATHS ${additional_lib_searchpath} -) - -if(NOT LIBETPAN_INCLUDE_DIR OR NOT LIBETPAN_LIBRARY) - message(FATAL_ERROR "ERROR: Could not find libetpan") -else() - message(STATUS "Found libetpan") -endif() - - -# detect tidy - -find_path(TIDY_INCLUDE_DIR - NAMES tidy/tidy.h - PATHS ${additional_includes} -) -find_library(TIDY_LIBRARY - NAMES tidy - PATHS ${additional_lib_searchpath} -) - -if(NOT TIDY_INCLUDE_DIR OR NOT TIDY_LIBRARY) - message(FATAL_ERROR "ERROR: Could not find tidy") -else() - message(STATUS "Found tidy") -endif() - - -# detect uuid - -find_path(UUID_INCLUDE_DIR - NAMES uuid/uuid.h - PATHS ${additional_includes} -) - -if(NOT UUID_INCLUDE_DIR) - message(FATAL_ERROR "ERROR: Could not find uuid") -else() - message(STATUS "Found uuid") -endif() - - -# detect libxml2 - -find_path(LIBXML_INCLUDE_DIR - NAMES libxml/xmlreader.h - PATHS ${additional_includes} -) -find_library(LIBXML_LIBRARY - NAMES xml2 - PATHS ${additional_lib_searchpath} -) - -if(NOT LIBXML_INCLUDE_DIR OR NOT LIBXML_LIBRARY) - message(FATAL_ERROR "ERROR: Could not find libxml2") -else() - message(STATUS "Found libxml2") -endif() - - -# detect zlib - -find_path(ZLIB_INCLUDE_DIR - NAMES zlib.h - PATHS ${additional_includes} -) -find_library(ZLIB_LIBRARY - NAMES z - PATHS ${additional_lib_searchpath} -) - -if(NOT ZLIB_INCLUDE_DIR OR NOT ZLIB_LIBRARY) - message(FATAL_ERROR "ERROR: Could not find zlib") -else() - message(STATUS "Found zlib") -endif() - -IF(${CMAKE_SYSTEM_NAME} MATCHES "Linux") -pkg_check_modules(GLIB2 glib-2.0) ENDIF() file(GLOB_RECURSE @@ -203,8 +36,6 @@ include_directories("${CMAKE_CURRENT_BINARY_DIR}/include" ${core_includes} ${objc_includes} ${additional_includes} - /usr/include/tidy - /usr/include/libxml2 ${GLIB2_INCLUDE_DIRS} ) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index e2ea3f54..fd07abba 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -1,30 +1,21 @@ -IF(${CMAKE_SYSTEM_NAME} MATCHES "Linux") -pkg_check_modules (GLIB2 glib-2.0) -set(icu_libraries icudata icui18n icuio icule iculx icutest icutu icuuc) -set(linux_libraries ${icu_libraries} pthread uuid) -ENDIF() - include_directories( ${CMAKE_CURRENT_BINARY_DIR}/../src/include ${GLIB2_INCLUDE_DIRS} ) + link_directories( - ${CMAKE_CURRENT_SOURCE_DIR}/../Externals/ctemplate-osx/lib - ${CMAKE_CURRENT_SOURCE_DIR}/../Externals/uchardet-osx/lib - ${CMAKE_CURRENT_SOURCE_DIR}/../Externals/libetpan-osx/lib + ${additional_lib_searchpath} ) IF(APPLE) - find_library(FOUNDATIONFRAMEWORK NAMES Foundation) - find_library(SECURITYFRAMEWORK NAMES Security) - find_library(CORESERVICESFRAMEWORK NAMES CoreServices) set(test_mac_files test-all-mac.mm) set(mac_libraries iconv) ENDIF() add_executable (tests main.cpp test-all.cpp ${test_mac_files}) target_link_libraries ( - tests MailCore z etpan xml2 uchardet sasl2 tidy ctemplate ssl crypto - ${mac_libraries} ${linux_libraries} - ${GLIB2_LIBRARIES} ${FOUNDATIONFRAMEWORK} ${SECURITYFRAMEWORK} ${CORESERVICESFRAMEWORK}) - + tests MailCore + ${ZLIB_LIBRARY} ${LIBETPAN_LIBRARY} ${LIBXML_LIBRARY} ${UCHARDET_LIBRARY} sasl2 + ${TIDY_LIBRARY} ${CTEMPLATE_LIBRARY} ssl crypto ${linux_libraries} ${mac_libraries} ${ICU4C_LIBRARY} + ${GLIB2_LIBRARIES} ${FOUNDATIONFRAMEWORK} ${SECURITYFRAMEWORK} ${CORESERVICESFRAMEWORK} +) diff --git a/unittest/CMakeLists.txt b/unittest/CMakeLists.txt new file mode 100644 index 00000000..3437518a --- /dev/null +++ b/unittest/CMakeLists.txt @@ -0,0 +1,16 @@ +include_directories( + ${CMAKE_CURRENT_BINARY_DIR}/../src/include + ${GLIB2_INCLUDE_DIRS} +) + +link_directories( + ${additional_lib_searchpath} +) + +add_executable (unittestcpp unittest.cpp) +target_link_libraries ( + unittestcpp MailCore + ${ZLIB_LIBRARY} ${LIBETPAN_LIBRARY} ${LIBXML_LIBRARY} ${UCHARDET_LIBRARY} sasl2 + ${TIDY_LIBRARY} ${CTEMPLATE_LIBRARY} ssl crypto ${linux_libraries} ${mac_libraries} ${ICU4C_LIBRARY} + ${GLIB2_LIBRARIES} ${FOUNDATIONFRAMEWORK} ${SECURITYFRAMEWORK} ${CORESERVICESFRAMEWORK} +) diff --git a/unittest/unittest.cpp b/unittest/unittest.cpp index a96a82e2..f79397f4 100644 --- a/unittest/unittest.cpp +++ b/unittest/unittest.cpp @@ -319,5 +319,9 @@ int main(int argc, char ** argv) pool->release(); + if (global_failure > 0) { + exit(EXIT_FAILURE); + } + exit(EXIT_SUCCESS); } \ No newline at end of file -- cgit v1.2.3