aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDamjan Marion <damarion@cisco.com>2021-05-10 14:51:44 +0200
committerDamjan Marion <damarion@cisco.com>2021-05-11 12:36:11 +0200
commit0d39cbac6d688fb98d05c32acec699b25a599ead (patch)
tree310b33f4b48b6aa342b0f1d398678b1e78ace81b
parent033e6ef52473aa3a87b1fe6db64114258106304b (diff)
build: compiler flags handling cleanup
Type: make Change-Id: I51f30edb91e09525ba116fe3941f2e43f9718da7 Signed-off-by: Damjan Marion <damarion@cisco.com>
-rwxr-xr-xconfigure2
-rw-r--r--src/CMakeLists.txt87
-rw-r--r--src/cmake/cpu.cmake6
-rw-r--r--src/cmake/exec.cmake1
-rw-r--r--src/cmake/library.cmake2
-rw-r--r--src/cmake/plugin.cmake2
6 files changed, 50 insertions, 50 deletions
diff --git a/configure b/configure
index 369adedaab8..7d9b017252d 100755
--- a/configure
+++ b/configure
@@ -80,6 +80,7 @@ cmake \
-B ${build_dir} \
-DCMAKE_PREFIX_PATH=${prefix_path} \
-DCMAKE_INSTALL_PREFIX=${install_dir} \
+ -DCMAKE_EXPORT_COMPILE_COMMANDS:BOOL=ON \
-DCMAKE_BUILD_TYPE:STRING=${build_type}
cat << __EOF__
@@ -89,7 +90,6 @@ cmake \
ninja Build VPP
ninja set-build-type-* Change build type to <debug|release|gcov|...>
ninja config Start build configuration TUI
- ninja compdb Generate compile_commands.json
ninja run Runs VPP using startup.conf in the build directory
ninja debug Runs VPP inside GDB using startup.conf in the build directory
ninja pkg-deb Create .deb packages
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 635b663252c..ebf03bdad61 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -25,7 +25,13 @@ set(CMAKE_C_COMPILER_NAMES
project(vpp C)
-set(CMAKE_EXPORT_COMPILE_COMMANDS on)
+if(CMAKE_VERSION VERSION_LESS 3.12)
+ macro(add_compile_definitions defs)
+ foreach(d ${defs})
+ add_compile_options(-D${d})
+ endforeach()
+ endmacro()
+endif()
include(CheckCCompilerFlag)
include(CheckIPOSupported)
@@ -69,49 +75,35 @@ set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/${VPP_LIBRARY_DIR})
set(VPP_BINARY_DIR ${CMAKE_BINARY_DIR}/CMakeFiles)
if (CMAKE_BUILD_TYPE)
- set(CMAKE_C_FLAGS "-g -fPIC -Werror -Wall ${CMAKE_C_FLAGS}")
+ add_compile_options(-g -fPIC -Werror -Wall)
endif()
if (compiler_flag_no_address_of_packed_member)
- set(CMAKE_C_FLAGS "-Wno-address-of-packed-member ${CMAKE_C_FLAGS}")
+ add_compile_options(-Wno-address-of-packed-member)
endif()
-# release
-list(APPEND BUILD_TYPES "release")
-string(CONCAT CMAKE_C_FLAGS_RELEASE
- "-O3 "
- "-fstack-protector "
- "-D_FORTIFY_SOURCE=2 "
- "-fno-common "
-)
-
-string(CONCAT CMAKE_EXE_LINKER_FLAGS_RELEASE "-pie")
-
-# debug
-list(APPEND BUILD_TYPES "debug")
-string(CONCAT CMAKE_C_FLAGS_DEBUG
- "-O0 "
- "-DCLIB_DEBUG "
- "-fstack-protector "
- "-fno-common "
-)
-
-# coverity
-list(APPEND BUILD_TYPES "coverity")
-string(CONCAT CMAKE_C_FLAGS_COVERITY "-O2 -D__COVERITY__")
-
-# gcov
-list(APPEND BUILD_TYPES "gcov")
-string(CONCAT CMAKE_C_FLAGS_GCOV
- "-O0 "
- "-DCLIB_DEBUG "
- "-DCLIB_GCOV "
- "-fprofile-arcs "
- "-ftest-coverage ")
-
+string(TOLOWER "${CMAKE_BUILD_TYPE}" CMAKE_BUILD_TYPE_LC)
string(TOUPPER "${CMAKE_BUILD_TYPE}" CMAKE_BUILD_TYPE_UC)
+set(CMAKE_C_FLAGS_RELEASE "")
+set(CMAKE_C_FLAGS_DEBUG "")
+
+if (${CMAKE_BUILD_TYPE_LC} MATCHES "release")
+ add_compile_options(-O3 -fstack-protector -fno-common)
+ add_compile_definitions(_FORTIFY_SOURCE=2)
+ string(CONCAT CMAKE_EXE_LINKER_FLAGS_RELEASE "-pie")
+elseif (${CMAKE_BUILD_TYPE_LC} MATCHES "debug")
+ add_compile_options(-O0 -fstack-protector -fno-common)
+ add_compile_definitions(CLIB_DEBUG)
+elseif (${CMAKE_BUILD_TYPE_LC} MATCHES "coverity")
+ add_compile_options(-O0)
+ add_compile_definitions(__COVERITY__)
+elseif (${CMAKE_BUILD_TYPE_LC} MATCHES "gcov")
+ add_compile_options(-O0 -fprofile-arcs -ftest-coverage)
+ add_compile_definitions(CLIB_DEBUG CLIB_GCOV)
+endif()
+set(BUILD_TYPES release debug coverity gcov)
string(REPLACE ";" " " BUILD_TYPES_STR "${BUILD_TYPES}")
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY
HELPSTRING "Build type - valid options are: ${BUILD_TYPES_STR}")
@@ -138,7 +130,8 @@ set(VPP_SANITIZE_ADDR_OPTIONS
)
if (VPP_ENABLE_SANITIZE_ADDR)
- set(CMAKE_C_FLAGS "-fsanitize=address -DCLIB_SANITIZE_ADDR ${CMAKE_C_FLAGS}")
+ add_compile_options(-fsanitize=address)
+ add_compile_definitions(CLIB_SANITIZE_ADDR)
set(CMAKE_EXE_LINKER_FLAGS "-fsanitize=address ${CMAKE_EXE_LINKER_FLAGS}")
set(CMAKE_SHARED_LINKER_FLAGS "-fsanitize=address ${CMAKE_SHARED_LINKER_FLAGS}")
endif (VPP_ENABLE_SANITIZE_ADDR)
@@ -149,7 +142,7 @@ endif (VPP_ENABLE_SANITIZE_ADDR)
option(VPP_ENABLE_TRAJECTORY_TRACE "Build vpp with trajectory tracing enabled" OFF)
if(VPP_ENABLE_TRAJECTORY_TRACE)
- set(CMAKE_C_FLAGS "-DVLIB_BUFFER_TRACE_TRAJECTORY=1 ${CMAKE_C_FLAGS}")
+ add_compile_definitions(VLIB_BUFFER_TRACE_TRAJECTORY=1)
endif()
##############################################################################
@@ -239,14 +232,6 @@ add_custom_target(config
USES_TERMINAL
)
-add_custom_target(compdb
- COMMAND ninja -C ${CMAKE_BINARY_DIR} -t compdb |
- ${CMAKE_SOURCE_DIR}/scripts/compdb_cleanup.py >
- ${CMAKE_BINARY_DIR}/compile_commands.json
- COMMENT "Generating compile_commands.json"
- USES_TERMINAL
-)
-
foreach(bt ${BUILD_TYPES})
add_custom_target(set-build-type-${bt}
COMMAND cmake -DCMAKE_BUILD_TYPE:STRING=${bt} .
@@ -255,6 +240,16 @@ foreach(bt ${BUILD_TYPES})
)
endforeach()
+mark_as_advanced(CLEAR
+ CMAKE_C_FLAGS
+ CMAKE_C_COMPILER
+ CMAKE_EXPORT_COMPILE_COMMANDS
+ CMAKE_INSTALL_PREFIX
+ CMAKE_LINKER
+ CMAKE_SHARED_LINKER_FLAGS
+ CMAKE_VERBOSE_MAKEFILE
+)
+
##############################################################################
# print configuration
##############################################################################
diff --git a/src/cmake/cpu.cmake b/src/cmake/cpu.cmake
index 539f7c803a9..f4a57a34281 100644
--- a/src/cmake/cpu.cmake
+++ b/src/cmake/cpu.cmake
@@ -115,7 +115,7 @@ macro(add_vpp_march_variant v)
endmacro()
if(CMAKE_SYSTEM_PROCESSOR MATCHES "amd64.*|x86_64.*|AMD64.*")
- set(CMAKE_C_FLAGS "-march=corei7 -mtune=corei7-avx ${CMAKE_C_FLAGS}")
+ set(VPP_DEFAULT_MARCH_FLAGS -march=corei7 -mtune=corei7-avx)
add_vpp_march_variant(hsw
FLAGS -march=haswell -mtune=haswell
@@ -138,7 +138,7 @@ if(CMAKE_SYSTEM_PROCESSOR MATCHES "amd64.*|x86_64.*|AMD64.*")
)
endif()
elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^(aarch64.*|AARCH64.*)")
- set(CMAKE_C_FLAGS "-march=armv8-a+crc ${CMAKE_C_FLAGS}")
+ set(VPP_DEFAULT_MARCH_FLAGS -march=armv8-a+crc)
add_vpp_march_variant(qdf24xx
FLAGS -march=armv8-a+crc+crypto -mtune=qdf24xx
@@ -198,7 +198,7 @@ macro(vpp_library_set_multiarch_sources lib)
add_dependencies(${l} ${ARG_DEPENDS})
endif()
set_target_properties(${l} PROPERTIES POSITION_INDEPENDENT_CODE ON)
- target_compile_options(${l} PUBLIC "-DCLIB_MARCH_VARIANT=${VARIANT}")
+ target_compile_definitions(${l} PUBLIC CLIB_MARCH_VARIANT=${VARIANT})
separate_arguments(VARIANT_FLAGS)
target_compile_options(${l} PUBLIC ${VARIANT_FLAGS})
target_sources(${lib} PRIVATE $<TARGET_OBJECTS:${l}>)
diff --git a/src/cmake/exec.cmake b/src/cmake/exec.cmake
index 7bfd5751c83..3ccbeee751c 100644
--- a/src/cmake/exec.cmake
+++ b/src/cmake/exec.cmake
@@ -20,6 +20,7 @@ macro(add_vpp_executable exec)
)
add_executable(${exec} ${ARG_SOURCES})
+ target_compile_options(${exec} PUBLIC ${VPP_DEFAULT_MARCH_FLAGS})
if(ARG_LINK_LIBRARIES)
target_link_libraries(${exec} ${ARG_LINK_LIBRARIES})
endif()
diff --git a/src/cmake/library.cmake b/src/cmake/library.cmake
index 5a7d2cdfef7..560b2c97d5c 100644
--- a/src/cmake/library.cmake
+++ b/src/cmake/library.cmake
@@ -22,6 +22,7 @@ macro(add_vpp_library lib)
set (lo ${lib}_objs)
add_library(${lo} OBJECT ${ARG_SOURCES})
set_target_properties(${lo} PROPERTIES POSITION_INDEPENDENT_CODE ON)
+ target_compile_options(${lo} PUBLIC ${VPP_DEFAULT_MARCH_FLAGS})
add_library(${lib} SHARED)
target_sources(${lib} PRIVATE $<TARGET_OBJECTS:${lo}>)
@@ -118,6 +119,7 @@ macro(add_vpp_test_library lib)
get_filename_component(name ${file} NAME_WE)
set(test_lib ${lib}_${name}_plugin)
add_library(${test_lib} SHARED ${file}_test2.c)
+ target_compile_options(${test_lib} PUBLIC ${VPP_DEFAULT_MARCH_FLAGS})
if(NOT VPP_EXTERNAL_PROJECT)
add_dependencies(${test_lib} api_headers)
endif()
diff --git a/src/cmake/plugin.cmake b/src/cmake/plugin.cmake
index 8038dfa1981..b399470db02 100644
--- a/src/cmake/plugin.cmake
+++ b/src/cmake/plugin.cmake
@@ -45,6 +45,7 @@ macro(add_vpp_plugin name)
)
endforeach()
add_library(${plugin_name} SHARED ${api_includes} ${PLUGIN_SOURCES})
+ target_compile_options(${plugin_name} PUBLIC ${VPP_DEFAULT_MARCH_FLAGS})
set_target_properties(${plugin_name} PROPERTIES NO_SONAME 1)
target_compile_options(${plugin_name} PRIVATE "-fvisibility=hidden")
target_compile_options (${plugin_name} PRIVATE "-ffunction-sections")
@@ -90,6 +91,7 @@ macro(add_vpp_plugin name)
set(test_plugin_name ${name}_test_plugin)
add_library(${test_plugin_name} SHARED ${PLUGIN_API_TEST_SOURCES}
${api_includes})
+ target_compile_options(${test_plugin_name} PUBLIC ${VPP_DEFAULT_MARCH_FLAGS})
set_target_properties(${test_plugin_name} PROPERTIES NO_SONAME 1)
if(NOT VPP_EXTERNAL_PROJECT)
add_dependencies(${test_plugin_name} api_headers)