Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

2x Compile Speed up #157

Merged
merged 6 commits into from
Apr 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
cmake_minimum_required(VERSION 3.13 FATAL_ERROR)

# Make sure that we are using the C++11 ABI, if not then there are some weird
# inconsistencies with our precompiled headers
add_compile_definitions(_GLIBCXX_USE_CXX11_ABI=1)

# Disable in-source builds to prevent source tree corruption.
if(" ${CMAKE_SOURCE_DIR}" STREQUAL " ${CMAKE_BINARY_DIR}")
message(FATAL_ERROR "
Expand Down Expand Up @@ -99,6 +103,12 @@ add_definitions( -DMAGICKCORE_HDRI_ENABLE=0 )

find_package(ImageMagick COMPONENTS Magick++ REQUIRED)
# =============================
# Build speed up

# function to enable unity build for a target
function(set_unity_for_target target_name)
set_target_properties(${target_name} PROPERTIES UNITY_BUILD ON UNITY_BUILD_MODE BATCH UNITY_BUILD_BATCH_SIZE 16 UNITY_BUILD_UNIQUE_ID "MY_UNITY_ID")
endfunction()

# =============================
# obcpp library & executable
Expand Down
15 changes: 15 additions & 0 deletions include/stdafx.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#ifndef INCLUDE_STDAFX_H_
#define INCLUDE_STDAFX_H_

// Commonly used header files to be precompiled in order to speed up compilation
// In reality this doesn't seem to be doing much in speeding it up...
// Leaving the infrastructure here in case someone is able to figure out a way to
// make this actually speed up compilation.

#include <vector>
#include <unordered_map>
#include <optional>
#include <memory>
#include <string>

#endif // INCLUDE_STDAFX_H_
15 changes: 15 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
# DONT REMOVE THE DUMMY FILE!!! IT WILL SEEM LIKE IT IS OKAY BUT IT WILL BREAK THE NEXT TIME
# YOU RECLONE OR RM -RF THE BUILD DIRECTORY!!! DON'T BE A DUMMY!
add_library(obcpp_protos STATIC
${PROJECT_SOURCE_DIR}/build/gen_protos/protos/obc.pb.cc
dummy.c
)

# LOL
# https://stackoverflow.com/questions/68735830/cmake-precompiled-headers-issue-with-mixed-c-c-project
target_precompile_headers(obcpp_protos PUBLIC
"$<$<COMPILE_LANGUAGE:CXX>:\"stdafx.h\">"
"$<$<COMPILE_LANGUAGE:C>:<stddef.h$<ANGLE-R>>")

add_subdirectory(camera)
add_subdirectory(core)
add_subdirectory(cv)
Expand All @@ -8,6 +21,7 @@ add_subdirectory(utilities)

add_library(obcpp_lib INTERFACE)
target_link_libraries(obcpp_lib INTERFACE
obcpp_protos
obcpp_camera
obcpp_core
obcpp_cv
Expand All @@ -20,6 +34,7 @@ target_link_libraries(obcpp_lib INTERFACE
# for use in unit tests
add_library(obcpp_lib_mock INTERFACE)
target_link_libraries(obcpp_lib_mock INTERFACE
obcpp_protos
obcpp_camera
obcpp_core
obcpp_cv
Expand Down
13 changes: 12 additions & 1 deletion src/camera/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,21 @@ set(FILES
mock.cpp
)

add_library(${LIB_NAME} STATIC ${PROJECT_SOURCE_DIR}/build/gen_protos/protos/obc.pb.cc
SET(LIB_DEPS
obcpp_protos
)

add_library(${LIB_NAME} STATIC
${FILES}
)

target_link_libraries(${LIB_NAME} PRIVATE
${LIB_DEPS}
)

target_precompile_headers(${LIB_NAME} REUSE_FROM obcpp_protos)
set_unity_for_target(${LIB_NAME})

target_add_protobuf(${LIB_NAME})
target_add_torch(${LIB_NAME})
# target_add_arena(${LIB_NAME}) # Tyler: currently broken, so we had to comment this out
Expand Down
6 changes: 5 additions & 1 deletion src/core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ set(FILES
)

set(LIB_DEPS
obcpp_protos
obcpp_camera
obcpp_cv
obcpp_network
Expand All @@ -15,14 +16,17 @@ set(LIB_DEPS
obcpp_utilities
)

add_library(${LIB_NAME} STATIC ${PROJECT_SOURCE_DIR}/build/gen_protos/protos/obc.pb.cc
add_library(${LIB_NAME} STATIC
${FILES}
)

target_link_libraries(${LIB_NAME} PRIVATE
${LIB_DEPS}
)

target_precompile_headers(${LIB_NAME} REUSE_FROM obcpp_protos)
set_unity_for_target(${LIB_NAME})

target_add_protobuf(${LIB_NAME})
target_add_torch(${LIB_NAME})
# target_add_arena(${LIB_NAME}) # Tyler: currently broken, so we had to comment this out
Expand Down
12 changes: 10 additions & 2 deletions src/cv/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,22 @@ set(FILES
utilities.cpp
)

add_library(${LIB_NAME} STATIC ${PROJECT_SOURCE_DIR}/build/gen_protos/protos/obc.pb.cc
set(LIB_DEPS
obcpp_protos
obcpp_utilities
)

add_library(${LIB_NAME} STATIC
${FILES}
)

target_link_libraries(${LIB_NAME} PRIVATE
obcpp_utilities
${LIB_DEPS}
)

target_precompile_headers(${LIB_NAME} REUSE_FROM obcpp_protos)
set_unity_for_target(${LIB_NAME})

target_add_protobuf(${LIB_NAME})
target_add_torch(${LIB_NAME})
# target_add_arena(${LIB_NAME}) # Tyler: currently broken, so we had to comment this out
Expand Down
25 changes: 25 additions & 0 deletions src/dummy.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/**
* Try and remove this. Just try it, dummy.
*
* Ok, but seriously. DON'T DELETE THIS FILE. You might think, "there's no fucking way
* this file is actually doing anything." And if you were to remove this file and then
* remove the reference to it in src/CMakeLists.txt and recompile, it would look like you
* were correct! It will be fine!
*
* But if you do do this--and I would encourage you to try!--see what happens if you reclone
* the repo or rm -rf your build directory. You will get some unholy error message complaining
* about some nonexistent file deep in the bowels of the build directory.
* Then you'll come crying back to your daddy and begging for a git restore src/dummy.c,
* like the dummy you are.
*
* Don't be a dummy, and don't delete this file.
*
* (for more information, see the stackoverflow post linked in src/CMakeLists.txt)
*/

int dummy() {
int i = 0;
++i;
--i;
i = 12;
}
9 changes: 8 additions & 1 deletion src/network/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,24 @@ set(MOCK_FILES
)

set(LIB_DEPS
obcpp_protos
obcpp_utilities
obcpp_ticks
obcpp_core
obcpp_pathing
)

add_library(${LIB_NAME} STATIC ${PROJECT_SOURCE_DIR}/build/gen_protos/protos/obc.pb.cc
add_library(${LIB_NAME} STATIC
${FILES}
)

target_link_libraries(${LIB_NAME} PRIVATE
${LIB_DEPS}
)

target_precompile_headers(${LIB_NAME} REUSE_FROM obcpp_protos)
set_unity_for_target(${LIB_NAME})

target_add_protobuf(${LIB_NAME})
target_add_torch(${LIB_NAME})
# target_add_arena(${LIB_NAME}) # Tyler: currently broken, so we had to comment this out
Expand All @@ -57,6 +61,9 @@ target_link_libraries(${LIB_NAME} PRIVATE
${LIB_DEPS}
)

target_precompile_headers(${LIB_NAME} REUSE_FROM obcpp_protos)
set_unity_for_target(${LIB_NAME})

target_add_protobuf(${LIB_NAME})
target_add_torch(${LIB_NAME})
# target_add_arena(${LIB_NAME}) # Tyler: currently broken, so we had to comment this out
Expand Down
6 changes: 5 additions & 1 deletion src/pathing/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,21 @@ set(FILES
)

set (LIB_DEPS
obcpp_protos
obcpp_core
obcpp_network
obcpp_utilities
)

add_library(${LIB_NAME} STATIC ${PROJECT_SOURCE_DIR}/build/gen_protos/protos/obc.pb.cc
add_library(${LIB_NAME} STATIC
${FILES}
)

target_link_libraries(${LIB_NAME} PRIVATE ${LIB_DEPS})

target_precompile_headers(${LIB_NAME} REUSE_FROM obcpp_protos)
set_unity_for_target(${LIB_NAME})

target_add_protobuf(${LIB_NAME})
target_add_torch(${LIB_NAME})
# target_add_arena(${LIB_NAME}) # Tyler: currently broken, so we had to comment this out
Expand Down
6 changes: 5 additions & 1 deletion src/ticks/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,24 @@ set(FILES
)

set(LIB_DEPS
obcpp_protos
obcpp_pathing
obcpp_utilities
obcpp_core
obcpp_network
)

add_library(${LIB_NAME} STATIC ${PROJECT_SOURCE_DIR}/build/gen_protos/protos/obc.pb.cc
add_library(${LIB_NAME} STATIC
${FILES}
)

target_link_libraries(${LIB_NAME} PRIVATE
${LIB_DEPS}
)

target_precompile_headers(${LIB_NAME} REUSE_FROM obcpp_protos)
set_unity_for_target(${LIB_NAME})

target_add_protobuf(${LIB_NAME})
target_add_torch(${LIB_NAME})
# target_add_arena(${LIB_NAME}) # Tyler: currently broken, so we had to comment this out
Expand Down
13 changes: 12 additions & 1 deletion src/utilities/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,21 @@ SET(FILES
rng.cpp
)

add_library(${LIB_NAME} STATIC ${PROJECT_SOURCE_DIR}/build/gen_protos/protos/obc.pb.cc
SET(LIB_DEPS
obcpp_protos
)

add_library(${LIB_NAME} STATIC
${FILES}
)

target_link_libraries(${LIB_NAME} PRIVATE
${LIB_DEPS}
)

target_precompile_headers(${LIB_NAME} REUSE_FROM obcpp_protos)
set_unity_for_target(${LIB_NAME})

target_add_protobuf(${LIB_NAME})
target_add_torch(${LIB_NAME})
# target_add_arena(${LIB_NAME}) # Tyler: currently broken, so we had to comment this out
Expand Down