提交 3209258a 编写于 作者: S Shreedhar Hardikar

Organize codegen source files and unit tests

* Move these into one gpcodegen dynamic library, leaving on
  codegen_wrapper.cc in SUBSYS.o
* Convert simple-gtests to cmockery_gtests since libgpcodegen may have
  references to Postgres symbols

Minor changes
上级 c19b96cc
......@@ -131,11 +131,26 @@ find_package(Clang REQUIRED)
include_directories(${CLANG_INCLUDE_DIRS})
# Core codegen library.
# This builds all the codegen-related C++ sources into one library
add_library(gpcodegen SHARED
utils/clang_compiler.cc
utils/codegen_utils.cc
utils/gp_codegen_utils.cc
codegen_interface.cc
codegen_manager.cc
const_expr_tree_generator.cc
exec_variable_list_codegen.cc
slot_getattr_codegen.cc
exec_eval_expr_codegen.cc
expr_tree_generator.cc
op_expr_tree_generator.cc
pg_date_func_generator.cc
var_expr_tree_generator.cc
advance_aggregates_codegen.cc
${codegen_tmpfile_sources})
if(APPLE)
set(WL_START_GROUP "")
set(WL_END_GROUP "")
......@@ -144,7 +159,16 @@ else()
set(WL_END_GROUP "-Wl,--end-group")
endif()
target_link_libraries(gpcodegen ${WL_START_GROUP} ${CLANG_LIBRARIES} ${WL_END_GROUP})
# By default, the Darwin linker throws an error if there are any undefined
# references in a dynamic library. Instead, it should wait till it's linked
# back with the postgres binary.
if(APPLE)
set(WL_UNDEFINED_DYNLOOKUP "-Wl,-undefined -Wl,dynamic_lookup")
else()
set(WL_UNDEFINED_DYNLOOKUP "")
endif()
target_link_libraries(gpcodegen ${WL_START_GROUP} ${CLANG_LIBRARIES} ${WL_END_GROUP} ${WL_UNDEFINED_DYNLOOKUP})
if (MONOLITHIC_LLVM_LIBRARY)
target_link_libraries(gpcodegen ${LLVM_MONOLITHIC_LIBRARIES})
else()
......@@ -167,27 +191,12 @@ set_target_properties(
INSTALL_NAME_DIR ${full_install_name_dir}
MACOSX_RPATH ON)
set(GPCODEGEN_SRC
codegen_interface.cc
codegen_manager.cc
codegen_wrapper.cc
const_expr_tree_generator.cc
exec_variable_list_codegen.cc
slot_getattr_codegen.cc
exec_eval_expr_codegen.cc
expr_tree_generator.cc
op_expr_tree_generator.cc
pg_date_func_generator.cc
var_expr_tree_generator.cc
advance_aggregates_codegen.cc
)
# Integrate with GPDB build system.
# Here we compile all the GPDB code generators, and link them incrementally
# with the gpcodegen shared library to create a binary SUBSYS.o as expected by
# GPDB make system. We invoke the linker with -nostdlib since we don't really
# want to create a full executable.
add_executable(SUBSYS.o ${GPCODEGEN_SRC})
# Here we compile the GPDB wrappers and link it with the gpcodegen shared
# library to create a binary SUBSYS.o as expected by GPDB make system. We
# invoke the linker with -nostdlib since we don't really want to create a full
# executable.
add_executable(SUBSYS.o codegen_wrapper.cc)
set_target_properties(SUBSYS.o
PROPERTIES
LINK_FLAGS "-Wl,-r -nostdlib")
......@@ -210,9 +219,9 @@ SET(GTEST_DIR ../../../gpAux/extensions/gtest)
add_subdirectory(${GTEST_DIR} ${CMAKE_BINARY_DIR}/gtest EXCLUDE_FROM_ALL)
enable_testing()
SET (TEST_LIB_INC_DIRECTORIES
${TOP_SRC_DIR}/src/test/unit/cmockery
${GTEST_DIR}/include)
set(TEST_LIB_INC_DIRECTORIES
${TOP_SRC_DIR}/src/test/unit/cmockery
${GTEST_DIR}/include)
function(prepend_path var prefix)
SET(listVar "")
......@@ -222,17 +231,6 @@ function(prepend_path var prefix)
SET(${var} "${listVar}" PARENT_SCOPE)
endfunction(prepend_path)
function(add_simple_gtest TEST_NAME TEST_SRC)
add_executable(${TEST_NAME} EXCLUDE_FROM_ALL ${TEST_SRC})
target_include_directories(${TEST_NAME} PUBLIC ${TEST_LIB_INC_DIRECTORIES})
target_link_libraries(${TEST_NAME} gpcodegen gtest)
add_test(${TEST_NAME} ${TEST_NAME})
add_dependencies(check ${TEST_NAME})
endfunction(add_simple_gtest)
add_simple_gtest(clang_compiler_unittest.t tests/clang_compiler_unittest.cc)
add_simple_gtest(codegen_utils_unittest.t tests/codegen_utils_unittest.cc)
add_simple_gtest(instance_method_wrappers_unittest.t tests/instance_method_wrappers_unittest.cc)
# Usage add_cmock_gtest ${TEST_NAME} ${TEST_SOURCES} ${MOCK_DIR}/hello_mock.o ${MOCK_DIR}/world_mock.o)
function(add_cmockery_gtest TEST_NAME TEST_SOURCES)
......@@ -257,7 +255,7 @@ function(add_cmockery_gtest TEST_NAME TEST_SOURCES)
add_executable(${TEST_NAME} EXCLUDE_FROM_ALL
${TEST_SOURCES}
${GPCODEGEN_SRC}
codegen_wrapper.cc
${FILES_TO_LINK}
${MOCK_OBJS}
${CMOCKERY_OBJS}
......@@ -310,14 +308,25 @@ if(EXISTS ${TXT_OBJFILE})
endif()
# Add CMockery tests
# All tests must be linked with postgres, even if they don't need the cmockery
# framework since libgpcodegen may now have references to postgres symbols.
#
# Usage add_cmock_gtest ${TEST_NAME} ${TEST_SOURCES} ${MOCK_DIR}/hello_mock.o ${MOCK_DIR}/world_mock.o)
if(EXISTS ${TXT_OBJFILE})
add_cmockery_gtest(codegen_framework_unittest.t
tests/codegen_framework_unittest.cc
${MOCK_DIR}/backend/postmaster/postmaster_mock.o
)
add_cmockery_gtest(codegen_pg_func_generator_unittest.t
tests/codegen_pg_func_generator_unittest.cc
${MOCK_DIR}/backend/postmaster/postmaster_mock.o
)
add_cmockery_gtest(clang_compiler_unittest.t
tests/clang_compiler_unittest.cc
)
add_cmockery_gtest(instance_method_wrappers_unittest.t
tests/instance_method_wrappers_unittest.cc
)
add_cmockery_gtest(codegen_utils_unittest.t
tests/codegen_utils_unittest.cc
)
endif()
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册