Skip to content

Commit

Permalink
rearrange things so we can include logging in the PCH
Browse files Browse the repository at this point in the history
  • Loading branch information
ewanwm committed Jul 24, 2024
1 parent c1a42be commit 6674458
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 36 deletions.
32 changes: 2 additions & 30 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,21 +1,18 @@
cmake_minimum_required(VERSION 3.18 FATAL_ERROR)
set(CMAKE_CXX_STANDARD 17)

project(nuTens)

OPTION(TEST_COVERAGE "TEST_COVERAGE" OFF)

IF(TEST_COVERAGE)
message("Adding flags to check test coverage")
#SET(CMAKE_CXX_FLAGS "--coverage -g -O0")
#SET(CMAKE_C_FLAGS "--coverage -g -O0")
#SET(CMAKE_EXE_LINKER_FLAGS "--coverage -g -O0")
add_compile_options("--coverage")
add_link_options("--coverage")
ELSE()
message("Won't check test coverage")
ENDIF()


project(nuTens)
enable_testing()

# add dependencies
Expand All @@ -35,30 +32,5 @@ find_package(Protobuf REQUIRED)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${TORCH_CXX_FLAGS}")


## if user wants to use pch then we use the pch
## people, especially if developing, might want to use this as including tensor related things
## can be excruciatingly sloow when building
OPTION(USE_PCH "USE_PCH" OFF)
IF(USE_PCH)
message("Using precompiled header")

add_library(nuTens-pch nuTens-pch.hpp)

## the headers included in the PCH will (at some point) depend on which tensor library is being used
IF(TORCH_FOUND)
message( "Including PyTorch includes in the PCH")
message( "TORCH_LIBRARIES = ")
message( "${TORCH_LIBRARIES}")

target_compile_definitions(nuTens-pch PUBLIC USE_PYTORCH)
SET(PCH_LIBS "${TORCH_LIBRARIES}")
ENDIF()

target_link_libraries(nuTens-pch PUBLIC "${PCH_LIBS}")
target_precompile_headers(nuTens-pch PUBLIC nuTens-pch.hpp)
set_target_properties(nuTens-pch PROPERTIES LINKER_LANGUAGE CXX)

ENDIF() ## end USE_PCH block

add_subdirectory(nuTens)
add_subdirectory(tests)
37 changes: 36 additions & 1 deletion nuTens/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## set up logging
add_library(logging logging.hpp)
target_link_libraries(logging spdlog::spdlog)
set_target_properties(logging PROPERTIES LINKER_LANGUAGE CXX)

set( LOG_LEVEL "INFO" CACHE STRING "the level of detail to log to the console" )
Expand All @@ -19,7 +20,41 @@ else()
endif()

## set the log level that will be used inside the logging.hpp file
target_compile_definitions(logging PUBLIC NT_LOG_LEVEL="NT_LOG_LEVEL_${LOG_LEVEL_UPPER}")
target_compile_definitions(logging PUBLIC NT_LOG_LEVEL=NT_LOG_LEVEL_${LOG_LEVEL_UPPER})




## if user wants to use pch then we use the pch
## people, especially if developing, might want to use this as including tensor related things
## can be excruciatingly sloow when building
OPTION(USE_PCH "USE_PCH" OFF)
IF(USE_PCH)
message("Using precompiled header")

add_library(nuTens-pch nuTens-pch.hpp)

SET(PCH_LIBS "${PCH_LIBS};logging")

## the headers included in the PCH will (at some point) depend on which tensor library is being used
IF(TORCH_FOUND)
message( "Including PyTorch includes in the PCH")
message( "TORCH_LIBRARIES = ")
message( "${TORCH_LIBRARIES}")

target_compile_definitions(nuTens-pch PUBLIC USE_PYTORCH)
SET(PCH_LIBS "${PCH_LIBS};${TORCH_LIBRARIES}")
ENDIF()

target_link_libraries(nuTens-pch PUBLIC "${PCH_LIBS}")
target_precompile_headers(nuTens-pch PUBLIC nuTens-pch.hpp)
set_target_properties(nuTens-pch PROPERTIES LINKER_LANGUAGE CXX)

ENDIF() ## end USE_PCH block





add_subdirectory(tensors)
add_subdirectory(propagator)
12 changes: 7 additions & 5 deletions nuTens/logging.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,13 @@
static std::once_flag once;

/// @brief Set up the logger at runtime, should only be invoked once the very first time any of the logging macros below are called
void setup_logging() {
std::call_once(once, [](){
std::cout << ":::::::: INFO: Setting default spdlog logging level to " << spdlog::level::to_string_view(runtimeLogLevel).data() << " ::::::::" << std::endl;
spdlog::set_level(runtimeLogLevel);
});
inline void setup_logging() {
std::call_once(
once, [](){
std::cout << ":::::::: INFO: Setting default spdlog logging level to " << spdlog::level::to_string_view(runtimeLogLevel).data() << " ::::::::" << std::endl;
spdlog::set_level(runtimeLogLevel);
}
);
}

/// @brief Trace message that will only be displayed if NT_LOG_LEVEL == NT_LOG_LEVEL_TRACE
Expand Down
2 changes: 2 additions & 0 deletions nuTens-pch.hpp → nuTens/nuTens-pch.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
#include <variant>
#include <complex>

#include <nuTens/logging.hpp>

#if USE_PYTORCH
#include <torch/torch.h>
#endif

0 comments on commit 6674458

Please sign in to comment.