CMake: Add CMake support for Thrift libraries

Currently the following libraries are supported:
- C++
- C_Glib
- Java (using Ant wrapper)

The compilers CMake file is adjusted to work with the new global CMakeLists.txt file.

Signed-off-by: Roger Meier <r.meier@siemens.com>
Signed-off-by: Pascal Bach <pascal.bach@siemens.com>
Also-by: Sergei Nikulov <sergey.nikulov@gmail.com>
diff --git a/lib/c_glib/CMakeLists.txt b/lib/c_glib/CMakeLists.txt
new file mode 100644
index 0000000..b5cb696
--- /dev/null
+++ b/lib/c_glib/CMakeLists.txt
@@ -0,0 +1,69 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+
+
+cmake_minimum_required(VERSION 2.8)
+
+# Find required packages
+find_package(GLIB REQUIRED COMPONENTS gobject)
+include_directories(${GLIB_INCLUDE_DIRS})
+
+include_directories(src)
+
+# SYSLIBS contains libraries that need to be linked to all lib targets
+set(SYSLIBS ${GLIB_LIBRARIES} ${GLIB_GOBJECT_LIBRARIES})
+
+# Create the thrift C glib library
+set(thrift_c_glib_SOURCES
+    src/thrift/c_glib/thrift.c
+    src/thrift/c_glib/thrift_struct.c
+    src/thrift/c_glib/thrift_application_exception.c
+    src/thrift/c_glib/processor/thrift_processor.c
+    src/thrift/c_glib/processor/thrift_dispatch_processor.c
+    src/thrift/c_glib/protocol/thrift_protocol.c
+    src/thrift/c_glib/protocol/thrift_protocol_factory.c
+    src/thrift/c_glib/protocol/thrift_binary_protocol.c
+    src/thrift/c_glib/protocol/thrift_binary_protocol_factory.c
+    src/thrift/c_glib/transport/thrift_transport.c
+    src/thrift/c_glib/transport/thrift_transport_factory.c
+    src/thrift/c_glib/transport/thrift_buffered_transport_factory.c
+    src/thrift/c_glib/transport/thrift_framed_transport_factory.c
+    src/thrift/c_glib/transport/thrift_socket.c
+    src/thrift/c_glib/transport/thrift_server_transport.c
+    src/thrift/c_glib/transport/thrift_server_socket.c
+    src/thrift/c_glib/transport/thrift_buffered_transport.c
+    src/thrift/c_glib/transport/thrift_framed_transport.c
+    src/thrift/c_glib/transport/thrift_memory_buffer.c
+    src/thrift/c_glib/server/thrift_server.c
+    src/thrift/c_glib/server/thrift_simple_server.c
+)
+
+# Contains the thrift specific ADD_LIBRARY_THRIFT and TARGET_LINK_LIBRARIES_THRIFT
+include(ThriftMacros)
+
+ADD_LIBRARY_THRIFT(thrift_c_glib ${thrift_c_glib_SOURCES})
+TARGET_LINK_LIBRARIES_THRIFT(thrift_c_glib ${SYSLIBS})
+
+# Install the headers
+install(DIRECTORY "src/thrift" DESTINATION "${INCLUDE_INSTALL_DIR}"
+    FILES_MATCHING PATTERN "*.h")
+
+if(BUILD_TESTING)
+    add_subdirectory(test)
+endif()
diff --git a/lib/c_glib/test/CMakeLists.txt b/lib/c_glib/test/CMakeLists.txt
new file mode 100644
index 0000000..affa455
--- /dev/null
+++ b/lib/c_glib/test/CMakeLists.txt
@@ -0,0 +1,168 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+
+
+#Make sure gen-cpp and gen-c_glib files can be included
+include_directories("${CMAKE_CURRENT_BINARY_DIR}")
+
+set(TEST_PREFIX "c_glib")
+
+# Create the thrift C++ test library
+set(testgenc_SOURCES
+    gen-c_glib/t_test_debug_proto_test_types.c
+    gen-c_glib/t_test_empty_service.c
+    gen-c_glib/t_test_inherited.c
+    gen-c_glib/t_test_optional_required_test_types.c
+    gen-c_glib/t_test_reverse_order_service.c
+    gen-c_glib/t_test_second_service.c
+    gen-c_glib/t_test_service_for_exception_with_a_map.c
+    gen-c_glib/t_test_srv.c
+    gen-c_glib/t_test_thrift_test.c
+    gen-c_glib/t_test_thrift_test_types.c
+    gen-c_glib/t_test_debug_proto_test_types.h
+    gen-c_glib/t_test_empty_service.h
+    gen-c_glib/t_test_inherited.h
+    gen-c_glib/t_test_optional_required_test_types.h
+    gen-c_glib/t_test_reverse_order_service.h
+    gen-c_glib/t_test_second_service.h
+    gen-c_glib/t_test_service_for_exception_with_a_map.h
+    gen-c_glib/t_test_srv.h
+    gen-c_glib/t_test_thrift_test.h
+    gen-c_glib/t_test_thrift_test_types.h
+)
+
+add_library(testgenc STATIC ${testgenc_SOURCES})
+target_link_libraries(testgenc thrift_c_glib)
+
+
+add_executable(testapplicationexception testapplicationexception.c)
+target_link_libraries(testapplicationexception thrift_c_glib)
+add_test(NAME testapplicationexception COMMAND testapplicationexception)
+
+add_executable(testtransportsocket testtransportsocket.c)
+target_link_libraries(testtransportsocket thrift_c_glib)
+add_test(NAME testtransportsocket COMMAND testtransportsocket)
+
+add_executable(testbinaryprotocol testbinaryprotocol.c)
+target_link_libraries(testbinaryprotocol thrift_c_glib)
+add_test(NAME testbinaryprotocol COMMAND testbinaryprotocol)
+
+add_executable(testbufferedtransport testbufferedtransport.c)
+target_link_libraries(testbufferedtransport thrift_c_glib)
+add_test(NAME testbufferedtransport COMMAND testbufferedtransport)
+
+add_executable(testframedtransport testframedtransport.c)
+target_link_libraries(testframedtransport thrift_c_glib)
+add_test(NAME testframedtransport COMMAND testframedtransport)
+
+add_executable(testmemorybuffer testmemorybuffer.c)
+target_link_libraries(testmemorybuffer thrift_c_glib)
+add_test(NAME testmemorybuffer COMMAND testmemorybuffer)
+
+add_executable(testsimpleserver testsimpleserver.c)
+target_link_libraries(testsimpleserver thrift_c_glib)
+add_test(NAME testsimpleserver COMMAND testsimpleserver)
+
+add_executable(testdebugproto testdebugproto.c)
+target_link_libraries(testdebugproto testgenc)
+add_test(NAME testdebugproto COMMAND testdebugproto)
+
+add_executable(testoptionalrequired testoptionalrequired.c)
+target_link_libraries(testoptionalrequired testgenc)
+add_test(NAME testoptionalrequired COMMAND testoptionalrequired)
+
+add_executable(testthrifttest testthrifttest.c)
+target_link_libraries(testthrifttest testgenc)
+add_test(NAME testthrifttest COMMAND testthrifttest)
+
+
+if(WITH_CPP)
+
+    include_directories("${PROJECT_SOURCE_DIR}/lib/cpp/src")
+
+    # Create the thrift C++ test library
+    set(testgenc_cpp_SOURCES
+        gen-cpp/ThriftTest.cpp
+        gen-cpp/ThriftTest_constants.cpp
+        gen-cpp/ThriftTest_types.cpp
+        gen-cpp/ThriftTest.h
+        gen-cpp/ThriftTest_constants.h
+        gen-cpp/ThriftTest_types.h
+    )
+
+    add_library(testgenc_cpp STATIC ${testgenc_cpp_SOURCES})
+    target_link_libraries(testgenc_cpp thrift)
+
+    #HACK: testthrifttestclient.cpp includes ThriftTest.h without gen-*/ prefixes
+    # so we include it here
+    include_directories("${CMAKE_CURRENT_BINARY_DIR}/gen-cpp" "${CMAKE_CURRENT_BINARY_DIR}/gen-c_glib")
+
+    add_executable(testthrifttestclient testthrifttestclient.cpp)
+    target_link_libraries(testthrifttestclient testgenc testgenc_cpp)
+    add_test(NAME testthrifttestclient COMMAND testthrifttestclient)
+
+endif(WITH_CPP)
+
+#
+# Common thrift code generation rules
+#
+
+add_custom_command(OUTPUT
+    gen-c_glib/t_test_debug_proto_test_types.c
+    gen-c_glib/t_test_debug_proto_test_types.h
+    gen-c_glib/t_test_empty_service.c
+    gen-c_glib/t_test_empty_service.h
+    gen-c_glib/t_test_inherited.c
+    gen-c_glib/t_test_inherited.h
+    gen-c_glib/t_test_reverse_order_service.c
+    gen-c_glib/t_test_reverse_order_service.h
+    gen-c_glib/t_test_service_for_exception_with_a_map.c
+    gen-c_glib/t_test_service_for_exception_with_a_map.h
+    gen-c_glib/t_test_srv.c
+    gen-c_glib/t_test_srv.h
+    COMMAND thrift-compiler --gen c_glib ${PROJECT_SOURCE_DIR}/test/DebugProtoTest.thrift
+)
+
+add_custom_command(OUTPUT
+    gen-c_glib/t_test_optional_required_test_types.c
+    gen-c_glib/t_test_optional_required_test_types.h
+    COMMAND thrift-compiler --gen c_glib ${PROJECT_SOURCE_DIR}/test/OptionalRequiredTest.thrift
+)
+
+add_custom_command(OUTPUT
+    gen-c_glib/t_test_second_service.c
+    gen-c_glib/t_test_thrift_test.c
+    gen-c_glib/t_test_thrift_test_types.c
+    gen-c_glib/t_test_second_service.h
+    gen-c_glib/t_test_thrift_test.h
+    gen-c_glib/t_test_thrift_test_types.h
+    COMMAND thrift-compiler --gen c_glib ${PROJECT_SOURCE_DIR}/test/ThriftTest.thrift
+)
+
+add_custom_command(OUTPUT
+    gen-cpp/ThriftTest.cpp
+    gen-cpp/ThriftTest_constants.cpp
+    gen-cpp/ThriftTest_types.cpp
+    gen-cpp/ThriftTest.h
+    gen-cpp/ThriftTest_constants.h
+    gen-cpp/ThriftTest_types.h
+    COMMAND thrift-compiler --gen cpp ${PROJECT_SOURCE_DIR}/test/ThriftTest.thrift
+)
+
+# TODO: Add memory checks using ctest_memcheck or similar
diff --git a/lib/cpp/CMakeLists.txt b/lib/cpp/CMakeLists.txt
new file mode 100755
index 0000000..cc73f99
--- /dev/null
+++ b/lib/cpp/CMakeLists.txt
@@ -0,0 +1,189 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+
+
+cmake_minimum_required(VERSION 2.8)
+
+# Find required packages
+find_package(Boost 1.53.0 REQUIRED)
+include_directories("${Boost_INCLUDE_DIR}")
+
+include_directories(src)
+
+# SYSLIBS contains libraries that need to be linked to all lib targets
+set(SYSLIBS "")
+
+# Create the thrift C++ library
+set( thriftcpp_SOURCES
+   src/thrift/Thrift.cpp
+   src/thrift/TApplicationException.cpp
+   src/thrift/VirtualProfiling.cpp
+   src/thrift/concurrency/ThreadManager.cpp
+   src/thrift/concurrency/TimerManager.cpp
+   src/thrift/concurrency/Util.cpp
+   src/thrift/protocol/TDebugProtocol.cpp
+   src/thrift/protocol/TDenseProtocol.cpp
+   src/thrift/protocol/TJSONProtocol.cpp
+   src/thrift/protocol/TBase64Utils.cpp
+   src/thrift/protocol/TMultiplexedProtocol.cpp
+   src/thrift/transport/TTransportException.cpp
+   src/thrift/transport/TFDTransport.cpp
+   src/thrift/transport/TSimpleFileTransport.cpp
+   src/thrift/transport/THttpTransport.cpp
+   src/thrift/transport/THttpClient.cpp
+   src/thrift/transport/THttpServer.cpp
+   src/thrift/transport/TSocket.cpp
+   src/thrift/transport/TSocketPool.cpp
+   src/thrift/transport/TServerSocket.cpp
+   src/thrift/transport/TTransportUtils.cpp
+   src/thrift/transport/TBufferTransports.cpp
+   src/thrift/server/TServer.cpp
+   src/thrift/server/TSimpleServer.cpp
+   src/thrift/server/TThreadPoolServer.cpp
+   src/thrift/server/TThreadedServer.cpp
+   src/thrift/async/TAsyncChannel.cpp
+   src/thrift/processor/PeekProcessor.cpp
+)
+
+# This files don't work on Windows CE as there is no pipe support
+# TODO: This files won't work with UNICODE support on windows. If fixed this can be re-added.
+if (NOT WINCE)
+    list(APPEND thriftcpp_SOURCES
+       src/thrift/transport/TPipe.cpp
+       src/thrift/transport/TPipeServer.cpp
+       src/thrift/transport/TFileTransport.cpp
+    )
+endif()
+
+
+if (WIN32)
+    list(APPEND thriftcpp_SOURCES
+        src/thrift/windows/TWinsockSingleton.cpp
+        src/thrift/windows/SocketPair.cpp
+        src/thrift/windows/GetTimeOfDay.cpp
+        src/thrift/windows/WinFcntl.cpp
+    )
+    if(NOT WINCE)
+        # This file uses pipes so it currently won't work on Windows CE
+        list(APPEND thriftcpp_SOURCES
+            src/thrift/windows/OverlappedSubmissionThread.cpp
+        )
+    endif()
+endif()
+
+# If OpenSSL is not found just ignore the OpenSSL stuff
+find_package(OpenSSL)
+if(OPENSSL_FOUND AND WITH_OPENSSL)
+    list( APPEND thriftcpp_SOURCES
+       src/thrift/transport/TSSLSocket.cpp
+       src/thrift/transport/TSSLServerSocket.cpp
+    )
+    include_directories("${OPENSSL_INCLUDE_DIR}")
+    list(APPEND SYSLIBS "${OPENSSL_LIBRARIES}")
+endif()
+
+# WITH_*THREADS selects whicht threading library to use
+if(WITH_BOOSTTHREADS)
+    set( USE_BOOST_THREAD 1)
+    set( thriftcpp_threads_SOURCES
+        src/thrift/concurrency/BoostThreadFactory.cpp
+        src/thrift/concurrency/BoostMonitor.cpp
+        src/thrift/concurrency/BoostMutex.cpp
+    )
+    list(APPEND SYSLIBS "${Boost_LIBRARIES}")
+elseif(UNIX AND NOT WITH_STDTHREADS)
+    list(APPEND SYSLIBS pthread)
+    set( thriftcpp_threads_SOURCES
+        src/thrift/concurrency/PosixThreadFactory.cpp
+        src/thrift/concurrency/Mutex.cpp
+        src/thrift/concurrency/Monitor.cpp
+    )
+else()
+    set( USE_STD_THREAD 1)
+    set( thriftcpp_threads_SOURCES
+        src/thrift/concurrency/StdThreadFactory.cpp
+        src/thrift/concurrency/StdMutex.cpp
+        src/thrift/concurrency/StdMonitor.cpp
+    )
+endif()
+
+# Thrift non blocking server
+set( thriftcppnb_SOURCES
+    src/thrift/server/TNonblockingServer.cpp
+    src/thrift/async/TAsyncProtocolProcessor.cpp
+    src/thrift/async/TEvhttpServer.cpp
+    src/thrift/async/TEvhttpClientChannel.cpp
+)
+
+# Thrift zlib server
+set( thriftcppz_SOURCES
+    src/thrift/transport/TZlibTransport.cpp
+)
+
+# Thrift Qt4 server
+set( thriftcppqt_SOURCES
+    src/thrift/qt/TQIODeviceTransport.cpp
+    src/thrift/qt/TQTcpServer.cpp
+)
+
+# Contains the thrift specific ADD_LIBRARY_THRIFT and TARGET_LINK_LIBRARIES_THRIFT
+include(ThriftMacros)
+
+ADD_LIBRARY_THRIFT(thrift ${thriftcpp_SOURCES} ${thriftcpp_threads_SOURCES})
+TARGET_LINK_LIBRARIES_THRIFT(thrift ${SYSLIBS})
+
+if(WITH_LIBEVENT)
+    find_package(Libevent REQUIRED)  # Libevent comes with CMake support form upstream
+    include_directories(${Libevent_INCLUDE_DIR})
+
+    ADD_LIBRARY_THRIFT(thriftnb ${thriftcppnb_SOURCES})
+    TARGET_LINK_LIBRARIES_THRIFT(thriftnb ${SYSLIBS} ${Libevent_LIBRARIES})
+endif()
+
+if(WITH_ZLIB)
+    find_package(ZLIB REQUIRED)
+    include_directories(${ZLIB_INCLUDE_DIR})
+
+    ADD_LIBRARY_THRIFT(thriftz ${thriftcppz_SOURCES})
+    TARGET_LINK_LIBRARIES_THRIFT(thriftz ${SYSLIBS} ${ZLIB_LIBRARIES})
+endif()
+
+
+if(WITH_QT4)
+    find_package(Qt4 REQUIRED)
+    include_directories(${QT_INCLUDES})
+
+    ADD_LIBRARY_THRIFT(thriftqt ${thriftcppqt_SOURCES})
+    TARGET_LINK_LIBRARIES_THRIFT(thriftz ${SYSLIBS} ${QT_LIBRARIES})
+endif()
+
+if(MSVC)
+    add_definitions("-DUNICODE -D_UNICODE")
+endif()
+
+# Install the headers
+install(DIRECTORY "src/thrift" DESTINATION "${INCLUDE_INSTALL_DIR}"
+    FILES_MATCHING PATTERN "*.h" PATTERN "*.tcc")
+# Copy config.h file
+install(DIRECTORY "${CMAKE_BINARY_DIR}/thrift" DESTINATION "${INCLUDE_INSTALL_DIR}"
+    FILES_MATCHING PATTERN "*.h")
+
+if(BUILD_TESTING)
+    add_subdirectory(test)
+endif()
diff --git a/lib/cpp/test/CMakeLists.txt b/lib/cpp/test/CMakeLists.txt
new file mode 100644
index 0000000..cb68505
--- /dev/null
+++ b/lib/cpp/test/CMakeLists.txt
@@ -0,0 +1,255 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+
+
+# Find required packages
+set(Boost_USE_STATIC_LIBS ON) # Force the use of static boost test framework
+find_package(Boost 1.53.0 REQUIRED COMPONENTS unit_test_framework)
+include_directories("${Boost_INCLUDE_DIR}")
+
+#Make sure gen-cpp files can be included
+include_directories("${CMAKE_CURRENT_BINARY_DIR}")
+
+# Create the thrift C++ test library
+set(testgencpp_SOURCES
+    gen-cpp/DebugProtoTest_types.cpp
+    gen-cpp/DebugProtoTest_types.h
+    gen-cpp/EnumTest_types.cpp
+    gen-cpp/EnumTest_types.h
+    gen-cpp/OptionalRequiredTest_types.cpp
+    gen-cpp/OptionalRequiredTest_types.h
+    gen-cpp/Recursive_types.cpp
+    gen-cpp/Recursive_types.h
+    gen-cpp/ThriftTest_types.cpp
+    gen-cpp/ThriftTest_types.h
+    gen-cpp/TypedefTest_types.cpp
+    gen-cpp/TypedefTest_types.h
+    ThriftTest_extras.cpp
+    DebugProtoTest_extras.cpp
+)
+
+add_library(testgencpp STATIC ${testgencpp_SOURCES})
+target_link_libraries(testgencpp thrift)
+
+set(processortest_SOURCES
+    gen-cpp/ChildService.cpp
+    gen-cpp/ChildService.h
+    gen-cpp/ParentService.cpp
+    gen-cpp/ParentService.h
+    gen-cpp/proc_types.cpp
+    gen-cpp/proc_types.h
+)
+
+
+add_executable(Benchmark Benchmark.cpp)
+target_link_libraries(Benchmark testgencpp)
+add_test(NAME Benchmark COMMAND Benchmark)
+
+set(UnitTest_SOURCES
+    UnitTestMain.cpp
+    TMemoryBufferTest.cpp
+    TBufferBaseTest.cpp
+    Base64Test.cpp
+    ToStringTest.cpp
+    TypedefTest.cpp
+)
+
+if(NOT WITH_BOOSTTHREADS AND NOT WITH_STDTHREADS)
+    list(APPEND UnitTest_SOURCES RWMutexStarveTest.cpp)
+endif()
+
+add_executable(UnitTests ${UnitTest_SOURCES})
+target_link_libraries(UnitTests testgencpp thrift ${Boost_LIBRARIES})
+add_test(NAME UnitTests COMMAND UnitTests)
+
+
+if(WITH_ZLIB)
+add_executable(TransportTest TransportTest.cpp)
+target_link_libraries(TransportTest
+    testgencpp
+    thriftz
+    ${Boost_LIBRARIES}
+    ${ZLIB_LIBRARIES}
+)
+add_test(NAME TransportTest COMMAND TransportTest)
+
+add_executable(ZlibTest ZlibTest.cpp)
+target_link_libraries(ZlibTest
+    testgencpp
+    thriftz
+    ${Boost_LIBRARIES}
+    ${ZLIB_LIBRARIES}
+)
+add_test(NAME ZlibTest COMMAND ZlibTest)
+endif(WITH_ZLIB)
+
+
+add_executable(EnumTest EnumTest.cpp)
+target_link_libraries(EnumTest
+    testgencpp
+    ${Boost_LIBRARIES}
+)
+add_test(NAME EnumTest COMMAND EnumTest)
+
+add_executable(TFileTransportTest TFileTransportTest.cpp)
+target_link_libraries(TFileTransportTest
+    testgencpp
+    ${Boost_LIBRARIES}
+)
+add_test(NAME TFileTransportTest COMMAND TFileTransportTest)
+
+add_executable(TFDTransportTest TFDTransportTest.cpp)
+target_link_libraries(TFDTransportTest
+    thrift
+)
+add_test(NAME TFDTransportTest COMMAND TFDTransportTest)
+
+add_executable(TPipedTransportTest TPipedTransportTest.cpp)
+target_link_libraries(TPipedTransportTest
+    thrift
+)
+add_test(NAME TPipedTransportTest COMMAND TPipedTransportTest)
+
+set(AllProtocolsTest_SOURCES
+    AllProtocolTests.cpp
+    AllProtocolTests.tcc
+    GenericHelpers
+    )
+
+add_executable(AllProtocolsTest ${AllProtocolsTest_SOURCES})
+target_link_libraries(AllProtocolsTest
+    testgencpp
+)
+add_test(NAME AllProtocolsTest COMMAND AllProtocolsTest)
+
+add_executable(DebugProtoTest DebugProtoTest.cpp)
+target_link_libraries(DebugProtoTest
+    testgencpp
+)
+add_test(NAME DebugProtoTest COMMAND DebugProtoTest)
+
+add_executable(JSONProtoTest JSONProtoTest.cpp)
+target_link_libraries(JSONProtoTest
+    testgencpp
+)
+add_test(NAME JSONProtoTest COMMAND JSONProtoTest)
+
+add_executable(OptionalRequiredTest OptionalRequiredTest.cpp)
+target_link_libraries(OptionalRequiredTest
+    testgencpp
+)
+add_test(NAME OptionalRequiredTest COMMAND OptionalRequiredTest)
+
+add_executable(RecursiveTest RecursiveTest.cpp)
+target_link_libraries(RecursiveTest
+    testgencpp
+)
+add_test(NAME RecursiveTest COMMAND RecursiveTest)
+
+add_executable(SpecializationTest SpecializationTest.cpp)
+target_link_libraries(SpecializationTest
+    testgencpp
+)
+add_test(NAME SpecializationTest COMMAND SpecializationTest)
+
+set(concurrency_test_SOURCES
+    concurrency/Tests.cpp
+    concurrency/ThreadFactoryTests.h
+    concurrency/ThreadManagerTests.h
+    concurrency/TimerManagerTests.h
+)
+add_executable(concurrency_test ${concurrency_test_SOURCES})
+target_link_libraries(concurrency_test
+    thrift
+)
+add_test(NAME concurrency_test COMMAND concurrency_test)
+
+set(link_test_SOURCES
+    link/LinkTest.cpp
+    link/TemplatedService1.cpp
+    link/TemplatedService2.cpp
+    gen-cpp/ParentService.h
+)
+add_executable(link_test ${link_test_SOURCES})
+add_test(NAME link_test COMMAND link_test)
+
+if(WITH_LIBEVENT)
+set(processor_test_SOURCES
+    processor/ProcessorTest.cpp
+    processor/EventLog.cpp
+    processor/ServerThread.cpp
+    processor/EventLog.h
+    processor/Handlers.h
+    processor/ServerThread.h
+)
+add_executable(processor_test ${processor_test_SOURCES})
+target_link_libraries(processor_test
+    thrift
+    thriftnb
+    ${Boost_LIBRARIES}
+)
+add_test(NAME processor_test COMMAND processor_test)
+endif()
+
+if(OPENSSL_FOUND AND WITH_OPENSSL)
+add_executable(OpenSSLManualInitTest OpenSSLManualInitTest.cpp)
+target_link_libraries(OpenSSLManualInitTest
+    thrift
+    ${OPENSSL_LIBRARIES}
+    ${Boost_LIBRARIES}
+)
+add_test(NAME OpenSSLManualInitTest COMMAND OpenSSLManualInitTest)
+endif()
+
+#
+# Common thrift code generation rules
+#
+
+
+add_custom_command(OUTPUT gen-cpp/DebugProtoTest_types.cpp gen-cpp/DebugProtoTest_types.h
+    COMMAND thrift-compiler --gen cpp:dense ${PROJECT_SOURCE_DIR}/test/DebugProtoTest.thrift
+)
+
+add_custom_command(OUTPUT gen-cpp/EnumTest_types.cpp gen-cpp/EnumTest_types.h
+    COMMAND thrift-compiler --gen cpp ${PROJECT_SOURCE_DIR}/test/EnumTest.thrift
+)
+
+add_custom_command(OUTPUT gen-cpp/TypedefTest_types.cpp gen-cpp/TypedefTest_types.h
+    COMMAND thrift-compiler --gen cpp ${PROJECT_SOURCE_DIR}/test/TypedefTest.thrift
+)
+
+add_custom_command(OUTPUT gen-cpp/OptionalRequiredTest_types.cpp gen-cpp/OptionalRequiredTest_types.h
+    COMMAND thrift-compiler --gen cpp:dense ${PROJECT_SOURCE_DIR}/test/OptionalRequiredTest.thrift
+)
+
+add_custom_command(OUTPUT gen-cpp/Recursive_types.cpp gen-cpp/Recursive_types.h
+    COMMAND thrift-compiler --gen cpp ${PROJECT_SOURCE_DIR}/test/Recursive.thrift
+)
+
+add_custom_command(OUTPUT gen-cpp/Service.cpp gen-cpp/StressTest_types.cpp
+    COMMAND thrift-compiler --gen cpp:dense ${PROJECT_SOURCE_DIR}/test/StressTest.thrift
+)
+
+add_custom_command(OUTPUT gen-cpp/SecondService.cpp gen-cpp/ThriftTest_constants.cpp gen-cpp/ThriftTest.cpp gen-cpp/ThriftTest_types.cpp gen-cpp/ThriftTest_types.h
+    COMMAND thrift-compiler --gen cpp:dense ${PROJECT_SOURCE_DIR}/test/ThriftTest.thrift
+)
+
+add_custom_command(OUTPUT gen-cpp/ChildService.cpp gen-cpp/ChildService.h gen-cpp/ParentService.cpp gen-cpp/ParentService.h gen-cpp/proc_types.cpp gen-cpp/proc_types.h
+    COMMAND thrift-compiler --gen cpp:templates,cob_style ${CMAKE_CURRENT_SOURCE_DIR}/processor/proc.thrift
+)
diff --git a/lib/java/CMakeLists.txt b/lib/java/CMakeLists.txt
new file mode 100644
index 0000000..8306318
--- /dev/null
+++ b/lib/java/CMakeLists.txt
@@ -0,0 +1,54 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+
+
+cmake_minimum_required(VERSION 2.8)
+
+# Find required packages
+find_package(Ant REQUIRED)
+
+if(IS_ABSOLUTE "${LIB_INSTALL_DIR}")
+    set(JAVA_INSTALL_DIR "${LIB_INSTALL_DIR}/java")
+else()
+    set(JAVA_INSTALL_DIR "${CMAKE_INSTALL_PREFIX}/${LIB_INSTALL_DIR}/java")
+endif()
+
+if(IS_ABSOLUTE "${DOC_INSTALL_DIR}")
+    set(JAVA_DOC_INSTALL_DIR "${DOC_INSTALL_DIR}/java")
+else()
+    set(JAVA_DOC_INSTALL_DIR "${CMAKE_INSTALL_PREFIX}/${DOC_INSTALL_DIR}/java")
+endif()
+
+add_custom_target(ant_build ALL
+    COMMAND ${Ant_EXECUTABLE} ${ANT_FLAGS} -Dbuild.dir=${CMAKE_CURRENT_BINARY_DIR} -Dworking.dir=${work_dir} -f build.xml
+    WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
+    COMMENT "Building Java library using Ant"
+)
+
+# Hook the ant install task into CMake install
+install(CODE "execute_process(
+    COMMAND ${Ant_EXECUTABLE} ${ANT_FLAGS} install
+    -Dbuild.dir=${CMAKE_CURRENT_BINARY_DIR} -Dworking.dir=${work_dir}
+    -Dinstall.path=${JAVA_INSTALL_DIR} -Dinstall.javadoc.path=${JAVA_DOC_INSTALL_DIR} -f build.xml
+    WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
+)")
+
+if(BUILD_TESTING)
+    #add_subdirectory(test)
+endif()