Skip to content

Commit

Permalink
build: move dependency handling of build and test targets into cmake …
Browse files Browse the repository at this point in the history
…targets
  • Loading branch information
Richard Pospesel committed Feb 18, 2024
1 parent 55b63f1 commit 60be767
Show file tree
Hide file tree
Showing 17 changed files with 183 additions and 166 deletions.
90 changes: 20 additions & 70 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -36,76 +36,59 @@ config-min-size-rel:

# build debug target
debug: config-debug
@$(MAKE) -C out/debug
@$(MAKE) build_target -C out/debug

# build release target
release: config-release
@$(MAKE) -C out/release
@$(MAKE) build_target -C out/release

# build release target
rel-with-deb-info: config-rel-with-deb-info
@$(MAKE) -C out/rel-with-deb-info
@$(MAKE) build_target -C out/rel-with-deb-info

# build release target
min-size-rel: config-min-size-rel
@$(MAKE) -C out/min-size-rel
@$(MAKE) build_target -C out/min-size-rel

#
# Online Test Targets (invokes real tor)
#

define test
@$(MAKE) honk_rpc_cargo_test -C out/$(1)
@$(MAKE) tor_interface_cargo_test -C out/$(1)
@$(MAKE) gosling_cargo_test -C out/$(1)
@$(MAKE) cgosling_cargo_test -C out/$(1)
@$(MAKE) gosling_functional_test -C out/$(1)
@$(MAKE) gosling_unit_test -C out/$(1)
endef

# build and run debug target tests
test-debug: config-debug
@$(call test,"debug")
@$(MAKE) test_target -C out/debug

# build and run release target tests
test-release: config-release
@$(call test,"release")
@$(MAKE) test_target -C out/release

# build and run rel-with-deb-info target tests
test-rel-with-deb-info: config-rel-with-deb-info
@$(call test,"rel-with-deb-info")
@$(MAKE) test_target -C out/rel-with-deb-info

# build and run min-size-rel target tests
test-min-size-rel: config-min-size-rel
@$(call test,"min-size-rel")
@$(MAKE) test_target -C out/min-size-rel

#
# Offline Test targets (mock tor)
#

define test-offline
@$(MAKE) honk_rpc_cargo_test -C out/$(1)
@$(MAKE) tor_interface_cargo_test_offline -C out/$(1)
@$(MAKE) gosling_cargo_test_offline -C out/$(1)
@$(MAKE) cgosling_cargo_test_offline -C out/$(1)
@$(MAKE) gosling_unit_test -C out/$(1)
endef

# debug tests which do not require access to the tor network
test-offline-debug: config-debug
@$(call test-offline,"debug")
@$(MAKE) test_offline_target -C out/debug

# release tests which do not require access to the tor network
test-offline-release: config-release
@$(call test-offline,"release")
@$(MAKE) test_offline_target -C out/release

# release tests which do not require access to the tor network
test-offline-rel-with-deb-info: config-rel-with-deb-info
@$(call test-offline,"rel-with-deb-info")
@$(MAKE) test_offline_target -C out/rel-with-deb-info

# release tests which do not require access to the tor network
test-offline-min-size-rel: config-min-size-rel
@$(call test-offline,"min-size-rel")
@$(MAKE) test_offline_target -C out/min-size-rel

#
# Rust Code Coverage Targets
Expand Down Expand Up @@ -151,69 +134,36 @@ lint: config-debug
--include=out/debug/bindings/cpp/include/cgosling.hpp\
--project=out/debug/compile_commands.sans-catch2.json

define install_pages
@$(MAKE) install_pages -C out/$(1)
@$(MAKE) install_crate_docs -C out/$(1)
@$(MAKE) install_gosling_code_coverage -C out/$(1)
@$(MAKE) install_doxygen_output -C out/$(1)
endef

#
# Website Install Targets
#

# debug build the website, code coverage, c/c++ apis, and rust docs
install-pages-debug: config-debug
@$(call install_pages,"debug")
website-debug: config-debug
@$(MAKE) website_target -C out/debug

# release build the website, code coverage, c/c++ apis, and rust docs
install-pages-rel-with-deb-info: config-rel-with-deb-info
@$(call install_pages,"rel-with-deb-info")
website-rel-with-deb-info: config-rel-with-deb-info
@$(MAKE) website_target -C out/rel-with-deb-info

#
# Library Install Targets
#

# debug build everything and deploy to dist
install-debug: config-debug
install-debug: debug
@$(MAKE) install -C out/debug

# release build everything and deploy to dist
install-release: config-release
install-release: release
@$(MAKE) install -C out/release

# rel-with-deb-info build everything and deploy to dist
install-rel-with-deb-info: config-rel-with-deb-info
install-rel-with-deb-info: rel-with-deb-info
@$(MAKE) install -C out/rel-with-deb-info

# min-size-rel build everything and deploy to dist
install-min-size-rel: config-min-size-rel
install-min-size-rel: min-size-rel
@$(MAKE) install -C out/min-size-rel

#
# Example Programs Install Targets
#

define install_examples
@$(MAKE) install_hello_world_cpp -C out/$(1)
endef

# debug build examples and deploy to dist
install-examples-debug: config-debug
@$(call install_examples,"debug")

# release build everything and deploy to dist
install-examples-release: config-release
@$(call install_examples,"release")

# rel-with-deb-info build everything and deploy to dist
install-examples-rel-with-deb-info: config-rel-with-deb-info
@$(call install_examples,"rel-with-deb-info")

# min-size-rel build everything and deploy to dist
install-examples-min-size-rel: config-min-size-rel
@$(call install_examples,"min-size-rel")

#
# Fuzzing targets
#
Expand Down
9 changes: 2 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ The **fuzz-** make targets have the following additional dependencies:
- [cargo-fuzz](https://github.com/rust-fuzz/cargo-fuzz)
- [libfuzzer](https://www.llvm.org/docs/LibFuzzer.html)

The **pages-** make target has the following additional dependencies:
The **website-** make target has the following additional dependencies:

- [doxygen](https://www.doxygen.nl/)
- [graphviz](https://www.graphviz.org/)
Expand Down Expand Up @@ -95,16 +95,11 @@ The following make targets are supported:
- **release**
- **rel-with-deb-info**
- **min-size-rel**
- **Install Targets:** build and deploy `cgosling` headers and static+shared libraries to `dist/*`
- **Install Targets:** build and deploy `cgosling` headers, static+shared libraries, bindings, and examples to `dist/*`
- **install-debug**
- **install-release**
- **install-rel-with-deb-info**
- **install-min-size-rel**
- **Install Examples Targets::** build and deploy the example projects to `dist/*`
- **install-examples-debug**
- **install-examples-release**
- **install-examples-rel-with-deb-info**
- **install-examples-min-size-rel**
- **Test Targets:** build and run all tests using real tor daemon
- **test-debug**
- **test-release**
Expand Down
9 changes: 9 additions & 0 deletions source/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,15 @@ endif()

set(CARGO_TARGET_DIR ${CMAKE_CURRENT_BINARY_DIR}/gosling)

# main build target needed for install
add_custom_target(build_target)
# runs all tests (requires internet access)
add_custom_target(test_target)
# runs the offline tests using mock tor provider
add_custom_target(test_offline_target)
# builds the documentation website
add_custom_target(website_target)

add_subdirectory(gosling)
add_subdirectory(extern)
add_subdirectory(test)
Expand Down
10 changes: 9 additions & 1 deletion source/bindings/c/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ foreach(src dest IN ZIP_LISTS gosling_c_bindings_sources gosling_c_bindings_outp
COMMAND cp ${src} ${dest})
endforeach()

add_custom_target(gosling_c_bindings_target ALL
add_custom_target(gosling_c_bindings_target
DEPENDS ${gosling_c_bindings_outputs})
add_dependencies(gosling_c_bindings_target cgosling_target)

Expand Down Expand Up @@ -70,6 +70,10 @@ if(WINDOWS)
target_link_libraries(gosling_c_static_bindings INTERFACE ntdll)
endif()

add_custom_target(gosling_c_static_bindings_target)
add_dependencies(gosling_c_static_bindings_target gosling_c_static_bindings)
add_dependencies(build_target gosling_c_static_bindings_target)

#
# Shared Library
#
Expand All @@ -87,6 +91,10 @@ if ((DEFINED CMAKE_IMPORT_LIBRARY_SUFFIX))
)
endif()

add_custom_target(gosling_c_shared_bindings_target)
add_dependencies(gosling_c_shared_bindings_target gosling_c_shared_bindings)
add_dependencies(build_target gosling_c_shared_bindings_target)

#
# Install
#
Expand Down
15 changes: 12 additions & 3 deletions source/bindings/cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ add_custom_command(
COMMAND env CARGO_TARGET_DIR=${CARGO_TARGET_DIR} RUSTFLAGS=${RUSTFLAGS} RUST_BACKTRACE=full cargo run ${CARGO_FLAGS} --bin build_cpp_bindings ${CARGO_TARGET_DIR}/cgosling.json cgosling.hpp.handlebars ${GOSLING_INCLUDE_DIR}/cgosling.hpp
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
)
add_custom_target(gosling_cpp_bindings_target ALL
add_custom_target(gosling_cpp_bindings_target
DEPENDS ${gosling_cpp_bindings_outputs} gosling_c_bindings_target)

#
Expand All @@ -33,6 +33,10 @@ add_dependencies(gosling_cpp_static_bindings gosling_cpp_bindings_target)
target_include_directories(gosling_cpp_static_bindings INTERFACE ${GOSLING_INCLUDE_DIR})
target_link_libraries(gosling_cpp_static_bindings INTERFACE gosling_c_static_bindings)

add_custom_target(gosling_cpp_static_bindings_target)
add_dependencies(gosling_cpp_static_bindings_target gosling_cpp_static_bindings)
add_dependencies(build_target gosling_cpp_static_bindings_target)

#
# Shared Library
#
Expand All @@ -43,6 +47,10 @@ add_dependencies(gosling_cpp_shared_bindings gosling_cpp_bindings_target)
target_include_directories(gosling_cpp_shared_bindings INTERFACE ${GOSLING_INCLUDE_DIR})
target_link_libraries(gosling_cpp_shared_bindings INTERFACE gosling_c_shared_bindings)

add_custom_target(gosling_cpp_shared_bindings_target)
add_dependencies(gosling_cpp_shared_bindings_target gosling_cpp_shared_bindings)
add_dependencies(build_target gosling_cpp_shared_bindings_target)

#
# Install C++ Header
#
Expand Down Expand Up @@ -79,15 +87,16 @@ else()
add_dependencies(gosling_cpp_doxygen_target gosling_cpp_bindings_target)

#
# Install C/C++ Doxygen documentation
# Deploy C/C++ Doxygen documentation
#
add_custom_command(
DEPENDS gosling_cpp_doxygen_target
OUTPUT ${CMAKE_INSTALL_PREFIX}/website/cgosling
COMMAND mkdir -p ${CMAKE_INSTALL_PREFIX}/website/cgosling
COMMAND cp -r ${CMAKE_CURRENT_BINARY_DIR}/html/* ${CMAKE_INSTALL_PREFIX}/website/cgosling/.
)
add_custom_target(install_doxygen_output
add_custom_target(deploy_doxygen_website_target
DEPENDS ${CMAKE_INSTALL_PREFIX}/website/cgosling
)
add_dependencies(website_target deploy_doxygen_website_target)
endif()
15 changes: 12 additions & 3 deletions source/bindings/java/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,16 @@ else()
target_link_libraries(goslingjni PRIVATE gosling_cpp_static_bindings)
target_compile_features(goslingjni PRIVATE cxx_std_17)

add_custom_target(gosling_java_bindings_target ALL
DEPENDS goslingjni
)
add_custom_target(gosling_java_bindings_target)
add_dependencies(gosling_java_bindings_target goslingjni)
add_dependencies(build_target gosling_java_bindings_target)

#
# Install
#

install(TARGETS goslingjni)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/Gosling.jar
DESTINATION bindings/java)

endif()
7 changes: 7 additions & 0 deletions source/bindings/python/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,10 @@ add_custom_command(
)
add_custom_target(gosling_python_bindings_target ALL
DEPENDS ${gosling_python_bindings_outputs})

#
# Install
#

install(FILES ${CMAKE_CURRENT_BINARY_DIR}/cgosling.py
DESTINATION bindings/python)
17 changes: 11 additions & 6 deletions source/examples/cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,14 @@ else()

target_compile_features(hello_world_cpp PRIVATE cxx_std_17)

add_custom_target(install_hello_world_cpp
DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/hello_world_cpp${CMAKE_EXECUTABLE_SUFFIX}
COMMAND mkdir -p ${CMAKE_INSTALL_PREFIX}/examples
COMMAND cp ${CMAKE_CURRENT_BINARY_DIR}/hello_world_cpp${CMAKE_EXECUTABLE_SUFFIX} ${CMAKE_INSTALL_PREFIX}/examples/
)
endif()
add_custom_target(hello_world_cpp_target)
add_dependencies(hello_world_cpp_target hello_world_cpp)
add_dependencies(build_target hello_world_cpp_target)

#
# Install hello world example binary
#

install(TARGETS hello_world_cpp
DESTINATION examples/hello_world_cpp)
endif()
Loading

0 comments on commit 60be767

Please sign in to comment.