Browse Source

build: optimize cmake structure

legacy
Dnomd343 1 month ago
parent
commit
1d2c1742ad
  1. 9
      src/core/CMakeLists.txt
  2. 27
      src/core_ffi/CMakeLists.txt
  3. 16
      src/core_ffi/c_ffi/CMakeLists.txt
  4. 8
      src/core_ffi/python_ffi/CMakeLists.txt
  5. 0
      src/core_ffi/python_ffi/binder/cases.cc
  6. 0
      src/core_ffi/python_ffi/binder/common_code.cc
  7. 0
      src/core_ffi/python_ffi/binder/fast_cal.cc
  8. 0
      src/core_ffi/python_ffi/binder/group.cc
  9. 0
      src/core_ffi/python_ffi/binder/group_union.cc
  10. 0
      src/core_ffi/python_ffi/binder/short_code.cc
  11. 0
      src/core_ffi/python_ffi/include/binder.h
  12. 0
      src/core_ffi/python_ffi/include/exception.h
  13. 0
      src/core_ffi/python_ffi/include/py_ffi/cases.h
  14. 0
      src/core_ffi/python_ffi/include/py_ffi/common_code.h
  15. 0
      src/core_ffi/python_ffi/include/py_ffi/fast_cal.h
  16. 0
      src/core_ffi/python_ffi/include/py_ffi/group.h
  17. 0
      src/core_ffi/python_ffi/include/py_ffi/short_code.h
  18. 0
      src/core_ffi/python_ffi/klotski.cc
  19. 0
      src/core_ffi/python_ffi/packing/CMakeLists.txt
  20. 4
      src/core_ffi/python_ffi/packing/MANIFEST.in
  21. 0
      src/core_ffi/python_ffi/packing/README.md
  22. 0
      src/core_ffi/python_ffi/packing/pyproject.toml
  23. 0
      src/core_ffi/python_ffi/packing/setup.py
  24. 0
      src/core_ffi/python_ffi/packing/src/CMakeLists.txt
  25. 0
      src/core_ffi/python_ffi/packing/src/core
  26. 0
      src/core_ffi/python_ffi/packing/src/core_ffi
  27. 0
      src/core_ffi/python_ffi/packing/src/klotski/__init__.py
  28. 0
      src/core_ffi/python_ffi/packing/third_party
  29. 0
      src/core_ffi/python_ffi/wrapper/cases.cc
  30. 0
      src/core_ffi/python_ffi/wrapper/common_codec.cc
  31. 0
      src/core_ffi/python_ffi/wrapper/fast_cal.cc
  32. 0
      src/core_ffi/python_ffi/wrapper/group.cc
  33. 0
      src/core_ffi/python_ffi/wrapper/group_union.cc
  34. 0
      src/core_ffi/python_ffi/wrapper/short_code.cc
  35. 23
      src/core_ffi/rust_ffi/CMakeLists.txt
  36. 23
      src/core_ffi/rust_ffi/build.rs
  37. 1
      src/core_ffi/rust_ffi/klotski/src/core_ffi/rust_ffi/CMakeLists.txt
  38. 2
      src/core_test/CMakeLists.txt

9
src/core/CMakeLists.txt

@ -1,9 +1,9 @@
cmake_minimum_required(VERSION 3.12)
project(core VERSION 0.0.1 LANGUAGES CXX)
project(klotski_core VERSION 0.0.1 LANGUAGES CXX)
set(CMAKE_CXX_STANDARD 23)
set(KLOTSKI_CORE_SRC
set(KLSK_CORE_SRC
ranges/internal/spawn.cc
ranges/internal/ranges.cc
ranges/internal/derive.cc
@ -31,16 +31,15 @@ set(KLOTSKI_CORE_SRC
fast_cal/internal/fast_cal.cc
)
add_library(klotski_core STATIC ${KLOTSKI_CORE_SRC})
add_library(klotski_core STATIC ${KLSK_CORE_SRC})
target_compile_options(klotski_core PRIVATE -fno-rtti -fno-exceptions) # option for `-fvisibility=hidden`
target_include_directories(klotski_core PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
target_link_libraries(klotski_core PUBLIC phmap::phmap)
add_library(klotski::core ALIAS klotski_core)
# TODO: just for dev testing
if (KLSK_DEV_MODE)
add_executable(klotski_core_bin main.cc)
target_link_libraries(klotski_core_bin PRIVATE klotski_core)
target_link_libraries(klotski_core_bin PRIVATE klotski::core)
endif()
if (KLSK_ENABLE_BENCHMARK)

27
src/core_ffi/CMakeLists.txt

@ -1,31 +1,14 @@
cmake_minimum_required(VERSION 3.12)
project(core_ffi)
set(CMAKE_CXX_STANDARD 23)
if (KLSK_C_FFI)
add_library(klotski_c c_ffi/all_cases.cc)
target_include_directories(klotski_c PUBLIC c_ffi/include)
target_link_libraries(klotski_c PRIVATE klotski::core)
set_target_properties(klotski_c PROPERTIES OUTPUT_NAME klotski)
add_subdirectory(c_ffi)
endif()
if (KLSK_PYTHON_FFI)
add_subdirectory(py_ffi)
if (KLSK_RUST_FFI)
add_subdirectory(rust_ffi)
endif()
if (KLSK_RUST_FFI)
if (CARGO_BUILD)
install(TARGETS klotski_core DESTINATION .)
else()
# just for IDE highlight
add_library(klotski_rs
rust_ffi/adapter/short_code.cc
rust_ffi/adapter/common_code.cc
rust_ffi/target/cxxbridge/rust_ffi/src/bridge.rs.cc
)
target_include_directories(klotski_rs PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})
target_include_directories(klotski_rs PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/rust_ffi/target/cxxbridge)
target_link_libraries(klotski_rs PRIVATE klotski_core)
endif()
if (KLSK_PYTHON_FFI)
add_subdirectory(python_ffi)
endif()

16
src/core_ffi/c_ffi/CMakeLists.txt

@ -0,0 +1,16 @@
cmake_minimum_required(VERSION 3.12)
project(klotski_c LANGUAGES CXX)
set(CMAKE_CXX_STANDARD 23)
set(KLSK_C_FFI_SRC
all_cases.cc
)
# TODO: add `-fno-rtti -fno-exceptions -fvisibility=hidden`
add_library(klotski_c STATIC ${KLSK_C_FFI_SRC}) # TODO: allow shared lib
target_include_directories(klotski_c PUBLIC include)
target_link_libraries(klotski_c PRIVATE klotski::core)
set_target_properties(klotski_c PROPERTIES OUTPUT_NAME klotski)
add_library(klotski::c_ffi ALIAS klotski_c)

8
src/core_ffi/py_ffi/CMakeLists.txt → src/core_ffi/python_ffi/CMakeLists.txt

@ -1,9 +1,9 @@
cmake_minimum_required(VERSION 3.12)
project(py_ffi)
project(klotski_py LANGUAGES CXX)
set(CMAKE_CXX_STANDARD 23)
pybind11_add_module(klotski_py
set(KLSK_PYTHON_FFI_SRC
klotski.cc
binder/cases.cc
@ -20,9 +20,13 @@ pybind11_add_module(klotski_py
wrapper/group.cc
wrapper/fast_cal.cc
)
pybind11_add_module(klotski_py ${KLSK_PYTHON_FFI_SRC})
target_include_directories(klotski_py PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include)
target_link_libraries(klotski_py PRIVATE klotski::core)
set_target_properties(klotski_py PROPERTIES OUTPUT_NAME _klotski)
add_library(klotski::py_ffi ALIAS klotski_py)
if (SKBUILD)
install(TARGETS klotski_py DESTINATION .)

0
src/core_ffi/py_ffi/binder/cases.cc → src/core_ffi/python_ffi/binder/cases.cc

0
src/core_ffi/py_ffi/binder/common_code.cc → src/core_ffi/python_ffi/binder/common_code.cc

0
src/core_ffi/py_ffi/binder/fast_cal.cc → src/core_ffi/python_ffi/binder/fast_cal.cc

0
src/core_ffi/py_ffi/binder/group.cc → src/core_ffi/python_ffi/binder/group.cc

0
src/core_ffi/py_ffi/binder/group_union.cc → src/core_ffi/python_ffi/binder/group_union.cc

0
src/core_ffi/py_ffi/binder/short_code.cc → src/core_ffi/python_ffi/binder/short_code.cc

0
src/core_ffi/py_ffi/include/binder.h → src/core_ffi/python_ffi/include/binder.h

0
src/core_ffi/py_ffi/include/exception.h → src/core_ffi/python_ffi/include/exception.h

0
src/core_ffi/py_ffi/include/py_ffi/cases.h → src/core_ffi/python_ffi/include/py_ffi/cases.h

0
src/core_ffi/py_ffi/include/py_ffi/common_code.h → src/core_ffi/python_ffi/include/py_ffi/common_code.h

0
src/core_ffi/py_ffi/include/py_ffi/fast_cal.h → src/core_ffi/python_ffi/include/py_ffi/fast_cal.h

0
src/core_ffi/py_ffi/include/py_ffi/group.h → src/core_ffi/python_ffi/include/py_ffi/group.h

0
src/core_ffi/py_ffi/include/py_ffi/short_code.h → src/core_ffi/python_ffi/include/py_ffi/short_code.h

0
src/core_ffi/py_ffi/klotski.cc → src/core_ffi/python_ffi/klotski.cc

0
src/core_ffi/py_ffi/packing/CMakeLists.txt → src/core_ffi/python_ffi/packing/CMakeLists.txt

4
src/core_ffi/py_ffi/packing/MANIFEST.in → src/core_ffi/python_ffi/packing/MANIFEST.in

@ -10,8 +10,8 @@ include src/CMakeLists.txt
include src/core_ffi/CMakeLists.txt
recursive-include src/core *
recursive-include src/core_ffi/py_ffi *
recursive-exclude src/core_ffi/py_ffi/packing *
recursive-include src/core_ffi/python_ffi *
recursive-exclude src/core_ffi/python_ffi/packing *
include third_party/ThirdParty.cmake
recursive-include third_party/pybind11 *

0
src/core_ffi/py_ffi/packing/README.md → src/core_ffi/python_ffi/packing/README.md

0
src/core_ffi/py_ffi/packing/pyproject.toml → src/core_ffi/python_ffi/packing/pyproject.toml

0
src/core_ffi/py_ffi/packing/setup.py → src/core_ffi/python_ffi/packing/setup.py

0
src/core_ffi/py_ffi/packing/src/CMakeLists.txt → src/core_ffi/python_ffi/packing/src/CMakeLists.txt

0
src/core_ffi/py_ffi/packing/src/core → src/core_ffi/python_ffi/packing/src/core

0
src/core_ffi/py_ffi/packing/src/core_ffi → src/core_ffi/python_ffi/packing/src/core_ffi

0
src/core_ffi/py_ffi/packing/src/klotski/__init__.py → src/core_ffi/python_ffi/packing/src/klotski/__init__.py

0
src/core_ffi/py_ffi/packing/third_party → src/core_ffi/python_ffi/packing/third_party

0
src/core_ffi/py_ffi/wrapper/cases.cc → src/core_ffi/python_ffi/wrapper/cases.cc

0
src/core_ffi/py_ffi/wrapper/common_codec.cc → src/core_ffi/python_ffi/wrapper/common_codec.cc

0
src/core_ffi/py_ffi/wrapper/fast_cal.cc → src/core_ffi/python_ffi/wrapper/fast_cal.cc

0
src/core_ffi/py_ffi/wrapper/group.cc → src/core_ffi/python_ffi/wrapper/group.cc

0
src/core_ffi/py_ffi/wrapper/group_union.cc → src/core_ffi/python_ffi/wrapper/group_union.cc

0
src/core_ffi/py_ffi/wrapper/short_code.cc → src/core_ffi/python_ffi/wrapper/short_code.cc

23
src/core_ffi/rust_ffi/CMakeLists.txt

@ -0,0 +1,23 @@
cmake_minimum_required(VERSION 3.12)
project(klotski_rs LANGUAGES CXX)
set(CMAKE_CXX_STANDARD 23)
if (KLSK_DEV_MODE)
set(KLSK_RUST_FFI_SRC
adapter/short_code.cc
adapter/common_code.cc
target/cxxbridge/rust_ffi/src/bridge.rs.cc
)
add_library(klotski_rs STATIC ${KLSK_RUST_FFI_SRC}) # just for IDE highlight
target_include_directories(klotski_rs PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../)
target_include_directories(klotski_rs PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/target/cxxbridge)
target_link_libraries(klotski_rs PRIVATE klotski::core)
set_target_properties(klotski_rs PROPERTIES OUTPUT_NAME klotski)
add_library(klotski::rs_ffi ALIAS klotski_rs)
endif()
if (CARGO_BUILD)
install(TARGETS klotski_core DESTINATION .)
endif()

23
src/core_ffi/rust_ffi/build.rs

@ -1,27 +1,23 @@
extern crate cmake;
// NOTE: add the following environment variables for using llvm toolchain
// CC=clang-20
// CXX=clang++-20
// CXXSTDLIB="c++"
// CXXFLAGS="-stdlib=libc++"
// RUSTFLAGS="-Clinker=clang-20 -Clink-arg=-fuse-ld=lld-20 -Clink-arg=-stdlib=libc++"
use cxx_build::CFG;
// NOTE: add `CC=clang-20 CXX=clang++-20 CXXFLAGS="-stdlib=libc++"` for cargo command
// we should keep cxx crate using clang for `cxx.cc`
// NOTE: also, `RUSTFLAGS="-C linker=clang-20"` should be added to cargo env for using lld
// NOTE: add `CC=clang-20 CXX=clang++-20 CXXFLAGS="-stdlib=libc++" RUSTFLAGS="-C linker=clang-20 -C link-arg=-fuse-ld=lld-20 -C link-arg=-stdlib=libc++"` for using llvm toolchain
// NOTE: it seems that cxx_build link `libstdc++` on linux, we can add `-C link-arg=-lc++ -C link-arg=-lc++abi` for workaround, but it should be fixed in the future.
fn main() {
let dst = cmake::Config::new("klotski")
cmake::Config::new("klotski")
.define("CARGO_BUILD:BOOL", "ON")
.define("KLSK_ENABLE_TESTING:BOOL", "OFF")
.define("KLSK_ENABLE_BENCHMARK:BOOL", "OFF")
.define("KLSK_C_FFI:BOOL", "OFF")
.define("KLSK_PYTHON_FFI:BOOL", "OFF")
.build();
println!("cargo:rustc-link-lib=static=klotski_core");
CFG.include_prefix = "rust_ffi";
cxx_build::bridge("src/bridge.rs")
.file("adapter/short_code.cc")
.file("adapter/common_code.cc")
@ -31,9 +27,6 @@ fn main() {
.flag("-fno-exceptions")
.compile("klotski");
println!("cargo:rustc-link-search=native={}", dst.display());
println!("cargo:rustc-link-lib=static=klotski_core");
println!("cargo:rerun-if-changed=src/bridge.rs");
println!("cargo:rerun-if-changed=adapter/short_code.cc");
println!("cargo:rerun-if-changed=adapter/common_code.cc");

1
src/core_ffi/rust_ffi/klotski/src/core_ffi/rust_ffi/CMakeLists.txt

@ -0,0 +1 @@
../../../../CMakeLists.txt

2
src/core_test/CMakeLists.txt

@ -1,5 +1,5 @@
cmake_minimum_required(VERSION 3.5 FATAL_ERROR)
project(core-test LANGUAGES CXX)
project(klotski_test LANGUAGES CXX)
set(CMAKE_CXX_STANDARD 23)

Loading…
Cancel
Save