Skip to content

Commit

Permalink
Update build system
Browse files Browse the repository at this point in the history
  • Loading branch information
christoph2 committed Feb 21, 2022
1 parent 64ecf49 commit c0b3f7a
Show file tree
Hide file tree
Showing 2 changed files with 106 additions and 1 deletion.
17 changes: 16 additions & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,24 @@ repos:
language: python
types_or: [c, c++, python]
stages: [commit]
- id: clang-format
name: clang-format
entry: clang-format -i
types_or: [c, c++]
stages: [commit]
language: system
types_or: [c, c++, python]
exclude: ".*py"
- id: clang-tidy
name: clang-tidy
entry: clang-tidy --extra-arg="-Iinc" -extra-arg="-I." -extra-arg="-DETHER"
types_or: [c, c++]
stages: [commit]
language: python
types_or: [c, c++, python]
- id: splint
name: Splint
entry: splint -f checker/cxcp.lcl
entry: splint -f cxcp.lcl
types_or: [c, c++]
stages: [commit]
language: system
Expand Down
90 changes: 90 additions & 0 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
cmake_minimum_required(VERSION 3.10)
project(xcpsim LANGUAGES C)

if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Release)
message(STATUS "Build type not specified: defaulting to release.")
endif()

IF(CMAKE_C_COMPILER_ID STREQUAL "GNU")
SET(CMAKE_C_STANDARD 11)
ELSEIF(CMAKE_C_COMPILER_ID MATCHES "Clang")
SET(CMAKE_C_STANDARD 11)
ELSE()
message(WARNING "C standard could not be set because compiler is not GNU or Clang.")
ENDIF()

option(PROFILE "Enable profiling" ON)

set(SOURCES
checksum_mocks.c
xcp_init.c
../src/xcp_checksum.c
../src/xcp_daq.c
../src/xcp_util.c
../flsemu/common.c
fls_mocks.c
xcp_mocks.c
)

set(INCLUDES
.
../inc
../flsemu
)

if(WIN32)
set(ADD_LIBS
"ws2_32"
)
elseif(UNIX)
set(ADD_LIBS
"pthread"
"rt"
)
endif(WIN32)

IF(CMAKE_C_COMPILER_ID MATCHES "Clang")
add_link_options("-fuse-ld=lld")
ENDIF()

add_definitions(-D_GNU_SOURCE)

set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -Wno-unused-parameter -Wno-unused-function -Wno-unused-variable -ffunction-sections")

if ("${PROFILE}" STREQUAL "ON")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -pg -fprofile-arcs -ftest-coverage --coverage")
endif()

if (CMAKE_BUILD_TYPE STREQUAL "DEBUG")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -ggdb -D_DEBUG -Og -fno-omit-frame-pointer -fno-optimize-sibling-calls")
if (NOT WIN32)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DFORTIFY_SOURCE=2 -fstack-protector-all --param=ssp-buffer-size=4 -fstack-check -fsanitize=address -fsanitize=undefined ")
if(CMAKE_C_COMPILER_ID MATCHES "Clang")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wthread-safety")
endif()
endif()
else()
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DNDEBUG -O3 -flto ")
endif()

if (CMAKE_SIZEOF_VOID_P EQUAL 8)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -m32")
endif()


if (WIN32)
add_library(xcp_test SHARED ${SOURCES})
target_compile_definitions(xcp_test PUBLIC TP_ETHER)
target_include_directories(xcp_test PUBLIC ${INCLUDES})
target_link_libraries(xcp_test ${ADD_LIBS})
target_compile_features(xcp_test PRIVATE c_std_11)

elseif(UNIX)
add_library(xcp_test SHARED ${SOURCES})
target_compile_definitions(xcp_test PUBLIC TP_ETHER)
target_include_directories(xcp_test PUBLIC ${INCLUDES})
target_link_libraries(xcp_test ${ADD_LIBS})
target_compile_features(xcp_test PRIVATE c_std_11)
endif()

0 comments on commit c0b3f7a

Please sign in to comment.