Skip to content

Commit

Permalink
Move all config handling into a single place – a config.h file, do no…
Browse files Browse the repository at this point in the history
…t clutter

the command line with these additional project-wide defines.

Signed-off-by: Anton Korobeynikov <[email protected]>
  • Loading branch information
asl committed Jan 16, 2025
1 parent 1bae920 commit 7d667af
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 6 deletions.
9 changes: 6 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ set (P4C_DRIVER_NAME "p4c" CACHE STRING "Customize the name of the driver script

set(MAX_LOGGING_LEVEL 10 CACHE STRING "Control the maximum logging level for -T logs")
set_property(CACHE MAX_LOGGING_LEVEL PROPERTY STRINGS 0 1 2 3 4 5 6 7 8 9 10)
add_definitions(-DMAX_LOGGING_LEVEL=${MAX_LOGGING_LEVEL})

if (NOT CMAKE_BUILD_TYPE)
set (CMAKE_BUILD_TYPE "Release")
Expand Down Expand Up @@ -198,6 +197,10 @@ find_package (BISON 3.0 REQUIRED)
if (ENABLE_GTESTS)
include(GoogleTest)
p4c_obtain_googletest()
# Some P4C source files include gtest files. This will be propagated to the
# definition in config.h We need this definition to guard against compilation
# errors.
set(P4C_GTEST_ENABLED ON)
endif ()
include(Abseil)
p4c_obtain_abseil()
Expand Down Expand Up @@ -373,8 +376,8 @@ include_directories (
${P4C_BINARY_DIR}
${P4C_SOURCE_DIR}/extensions
)
add_definitions (-DCONFIG_PREFIX="${CMAKE_INSTALL_PREFIX}")
add_definitions (-DCONFIG_PKGDATADIR="${CMAKE_INSTALL_PREFIX}/${P4C_ARTIFACTS_OUTPUT_DIRECTORY}")
set(CONFIG_PREFIX ${CMAKE_INSTALL_PREFIX})
set(CONFIG_PKGDATADIR ${CMAKE_INSTALL_PREFIX}/${P4C_ARTIFACTS_OUTPUT_DIRECTORY})

set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${P4C_CXX_FLAGS}")
set (CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} ${P4C_CXX_FLAGS}")
Expand Down
3 changes: 0 additions & 3 deletions cmake/GoogleTest.cmake
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
macro(p4c_obtain_googletest)
# Some P4C source files include gtest files.
# We need this definition to guard against compilation errors.
add_definitions(-DP4C_GTEST_ENABLED)
# Print download state while setting up GTest.
set(FETCHCONTENT_QUIET_PREV ${FETCHCONTENT_QUIET})
set(FETCHCONTENT_QUIET OFF)
Expand Down
9 changes: 9 additions & 0 deletions cmake/config.h.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,12 @@

/* Define to 1 if you have the mm_malloc.h header */
#cmakedefine HAVE_MM_MALLOC_H 1

#cmakedefine CONFIG_PKGDATADIR "@CONFIG_PKGDATADIR@"

#cmakedefine CONFIG_PREFIX "@CONFIG_PREFIX@"

/* The maximum logging level for -T logs */
#cmakedefine MAX_LOGGING_LEVEL @MAX_LOGGING_LEVEL@

#cmakedefine P4C_GTEST_ENABLED 1
1 change: 1 addition & 0 deletions lib/json.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ limitations under the License.
#include <type_traits>
#include <vector>

#include "config.h"
#ifdef P4C_GTEST_ENABLED
#include "gtest/gtest_prod.h"
#endif
Expand Down
1 change: 1 addition & 0 deletions lib/source_file.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ limitations under the License.
#include "absl/strings/str_format.h"
#include "cstring.h"
#include "stringify.h"
#include "config.h"

// GTest
#ifdef P4C_GTEST_ENABLED
Expand Down

0 comments on commit 7d667af

Please sign in to comment.