diff --git a/CMakeLists.txt b/CMakeLists.txt index 7c2204d4..59829a04 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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 " @@ -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 diff --git a/include/stdafx.h b/include/stdafx.h new file mode 100644 index 00000000..7b21f312 --- /dev/null +++ b/include/stdafx.h @@ -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 +#include +#include +#include +#include + +#endif // INCLUDE_STDAFX_H_ diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 3afe542a..c873e17b 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -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 + "$<$:\"stdafx.h\">" + "$<$:>") + add_subdirectory(camera) add_subdirectory(core) add_subdirectory(cv) @@ -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 @@ -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 diff --git a/src/camera/CMakeLists.txt b/src/camera/CMakeLists.txt index f55a1335..726bb19b 100644 --- a/src/camera/CMakeLists.txt +++ b/src/camera/CMakeLists.txt @@ -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 diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt index 5945142c..365fa864 100644 --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt @@ -7,6 +7,7 @@ set(FILES ) set(LIB_DEPS + obcpp_protos obcpp_camera obcpp_cv obcpp_network @@ -15,7 +16,7 @@ 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} ) @@ -23,6 +24,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 diff --git a/src/cv/CMakeLists.txt b/src/cv/CMakeLists.txt index d3a531a1..480c3b02 100644 --- a/src/cv/CMakeLists.txt +++ b/src/cv/CMakeLists.txt @@ -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 diff --git a/src/dummy.c b/src/dummy.c new file mode 100644 index 00000000..63f4a42e --- /dev/null +++ b/src/dummy.c @@ -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; +} diff --git a/src/network/CMakeLists.txt b/src/network/CMakeLists.txt index 5cf6e371..7851b09a 100644 --- a/src/network/CMakeLists.txt +++ b/src/network/CMakeLists.txt @@ -19,13 +19,14 @@ 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} ) @@ -33,6 +34,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 @@ -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 diff --git a/src/pathing/CMakeLists.txt b/src/pathing/CMakeLists.txt index 1cf512c1..89017fbc 100644 --- a/src/pathing/CMakeLists.txt +++ b/src/pathing/CMakeLists.txt @@ -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 diff --git a/src/ticks/CMakeLists.txt b/src/ticks/CMakeLists.txt index d9994a53..06cc68c0 100644 --- a/src/ticks/CMakeLists.txt +++ b/src/ticks/CMakeLists.txt @@ -17,13 +17,14 @@ 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} ) @@ -31,6 +32,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 diff --git a/src/utilities/CMakeLists.txt b/src/utilities/CMakeLists.txt index 67ce45af..0a4c58c7 100644 --- a/src/utilities/CMakeLists.txt +++ b/src/utilities/CMakeLists.txt @@ -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