diff --git a/bolt/CMakeLists.txt b/bolt/CMakeLists.txt index 25c49cfc2..c10488e5d 100644 --- a/bolt/CMakeLists.txt +++ b/bolt/CMakeLists.txt @@ -93,12 +93,21 @@ function(bolt_add_library target_name) set(SHUFFLE_COMP_LIST "shuffle") - set(EXTENSIONS_COMP_LIST "torch" "cudf" "python") + set(BOLT_EXTENSION_COMP_LIST "cudf" "torch" "python") if (BOLT_INTERFACE) add_library(${target_name} INTERFACE ${ARGN}) return() endif() + if (BOLT_OBJECT) + add_library(${target_name} OBJECT ${ARGN}) + return() + endif() + + if(FIRST_LEVEL_DIR IN_LIST BOLT_EXTENSION_COMP_LIST) + add_library(${target_name} ${ARGN}) + return() + endif() # OBJECT libraries are used to aggregate source files without creating a library file. add_library(${target_name} OBJECT ${ARGN}) @@ -148,12 +157,6 @@ function(bolt_add_library target_name) return() endif() - if(FIRST_LEVEL_DIR IN_LIST EXTENSIONS_COMP_LIST) - list(APPEND EXTENSIONS_OBJECT_TARGETS $) - set(EXTENSIONS_OBJECT_TARGETS ${EXTENSIONS_OBJECT_TARGETS} CACHE INTERNAL "") - return() - endif() - message(FATAL_ERROR "New component ${target_name} in ${CURRENT_RELATIVE_PATH}?") endfunction() diff --git a/bolt/connectors/fuzzer/CMakeLists.txt b/bolt/connectors/fuzzer/CMakeLists.txt index 3e39332ba..add58f1c0 100644 --- a/bolt/connectors/fuzzer/CMakeLists.txt +++ b/bolt/connectors/fuzzer/CMakeLists.txt @@ -25,7 +25,7 @@ # This modified file is released under the same license. # -------------------------------------------------------------------------- -bolt_add_library(bolt_fuzzer_connector OBJECT FuzzerConnector.cpp) +bolt_add_library(bolt_fuzzer_connector FuzzerConnector.cpp) target_link_libraries(bolt_fuzzer_connector bolt_connector bolt_vector_fuzzer) diff --git a/bolt/core/CMakeLists.txt b/bolt/core/CMakeLists.txt index 760b19fe0..eae14be6c 100644 --- a/bolt/core/CMakeLists.txt +++ b/bolt/core/CMakeLists.txt @@ -30,7 +30,7 @@ if(${BOLT_BUILD_TESTING}) endif() bolt_add_library(bolt_config Config.cpp Context.cpp) -target_link_libraries(bolt_config bolt_exception Folly::folly) +target_link_libraries(bolt_config Folly::folly) bolt_add_library( bolt_core Expressions.cpp PlanFragment.cpp PlanNode.cpp QueryConfig.cpp QueryCtx.cpp diff --git a/bolt/cudf/exec/CMakeLists.txt b/bolt/cudf/exec/CMakeLists.txt index 64ef8ab4b..47b3f01f4 100644 --- a/bolt/cudf/exec/CMakeLists.txt +++ b/bolt/cudf/exec/CMakeLists.txt @@ -13,7 +13,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -add_library(bolt_cudf_exec HashAggregation.cpp InterOp.cpp OrderBy.cpp) +bolt_add_library(bolt_cudf_exec HashAggregation.cpp InterOp.cpp OrderBy.cpp) target_include_directories(bolt_cudf_exec PRIVATE ${cudf_INCLUDE_DIRS}) diff --git a/bolt/torch/CMakeLists.txt b/bolt/torch/CMakeLists.txt index 8b3a06918..825300ec6 100644 --- a/bolt/torch/CMakeLists.txt +++ b/bolt/torch/CMakeLists.txt @@ -13,7 +13,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -add_library(bolt_torch Compatibility.cpp Operator.cpp PlanNode.cpp Tensor.cpp Utils.cpp) +bolt_add_library(bolt_torch Compatibility.cpp Operator.cpp PlanNode.cpp Tensor.cpp Utils.cpp) target_include_directories( bolt_torch diff --git a/doc/do-cmake-right.md b/doc/do-cmake-right.md new file mode 100644 index 000000000..490724277 --- /dev/null +++ b/doc/do-cmake-right.md @@ -0,0 +1,23 @@ +## Do CMake Right + +Please write CMake scripts in a modern style, and follow the best practices in [Effective Modern CMake](https://gist.github.com/mbinna/c61dbb39bca0e4fb7d1f73b0d66a4fd1). + +## Adding a new CMake target in Bolt + +### Adding a CMake target into Bolt engine, +Use the `bolt_add_library` command to add CMake target. It is a wrapper of the `add_library` command(see [here](https://github.com/bytedance/bolt/issues/139). +It will turn this target into an `OBJECT` target, and categorize and assemble it into the correct Bolt's sub-components. + +Take this CMake target `bolt_config` for example: +``` +# Step 1: turn bolt_config into an OBJECT target. +# Step 2: add bolt_config into bolt_engine sub-component according to its directory hierarchy. +bolt_add_library(bolt_config Config.cpp Context.cpp) + +target_link_libraries(bolt_config PUBLIC Folly::folly) +``` + +## References +- [Effective Modern CMake](https://gist.github.com/mbinna/c61dbb39bca0e4fb7d1f73b0d66a4fd1) +- [Advanced Dependencies Model in Conan 2.0](https://www.youtube.com/watch?v=kKGglzm5ous) +- [CMake: Public VS Private VS Interface](https://leimao.github.io/blog/CMake-Public-Private-Interface/)