blob: ae125da4d64cb0503ec256e2f2e856a6c4110c31 [file] [log] [blame]
Lawrence Tang1b0b00e2022-07-05 10:33:10 +01001cmake_minimum_required(VERSION 3.10)
2include(FetchContent)
Lawrence Tangd34f2b12022-07-19 15:36:31 +01003include(GoogleTest)
Lawrence Tang1b0b00e2022-07-05 10:33:10 +01004project(CPERParse)
5
Lawrence Tangd34f2b12022-07-19 15:36:31 +01006# GoogleTest requires at least C++14.
7set(CMAKE_CXX_STANDARD 14)
8
Lawrence Tang1b0b00e2022-07-05 10:33:10 +01009# Output into subdirectories /lib and /bin.
10set(EXECUTABLE_OUTPUT_PATH ${CMAKE_BINARY_DIR}/bin)
11set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
12set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
13set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
14
15# Fetch json-c from git repository.
16FetchContent_Declare(
17 json-c
18 GIT_REPOSITORY https://github.com/json-c/json-c.git
19 GIT_TAG d28ac67dde77566f53a97f22b4ea7cb36afe6582 # 4/6/2022
20)
Lawrence Tangd7e8ca32022-07-07 10:25:53 +010021
22# Fetch b64-c from git repository.
23FetchContent_Declare(
24 b64-c
25 GIT_REPOSITORY https://github.com/jwerle/b64.c.git
26 GIT_TAG c33188cd541f19b072ee4988d8224ea6c964bed1 # 9/2/2021
27)
Lawrence Tangd34f2b12022-07-19 15:36:31 +010028
29# Fetch GoogleTest from git repository.
30FetchContent_Declare(
31 googletest
32 GIT_REPOSITORY https://github.com/google/googletest.git
33 GIT_TAG release-1.12.1
34)
35FetchContent_MakeAvailable(json-c b64-c googletest)
Lawrence Tang1b0b00e2022-07-05 10:33:10 +010036
37# Add library and test executable.
38file(GLOB SectionSources sections/*.c)
39file(GLOB EDKSources edk/*.c)
Lawrence Tang02c801a2022-07-18 14:43:52 +010040file(GLOB GeneratorSectionSources generator/sections/*.c)
Lawrence Tangb8fa2f72022-07-18 10:50:19 +010041add_library(cper-parse STATIC cper-parse.c ir-parse.c cper-utils.c json-schema.c json-schema.h ${SectionSources} ${EDKSources})
Lawrence Tang02c801a2022-07-18 14:43:52 +010042add_executable(cper-convert cli-app/cper-convert.c)
Lawrence Tangd34f2b12022-07-19 15:36:31 +010043add_executable(cper-generate
44 generator/cper-generate-cli.c
45 generator/cper-generate.c
46 generator/gen-utils.c
47 ${GeneratorSectionSources}
48 ${EDKSources}
49)
50add_executable(cper-tests
51 tests/ir-tests.cpp
52 tests/test-utils.cpp
53 generator/cper-generate.c
54 generator/gen-utils.c
55 ${GeneratorSectionSources}
56 ${EDKSources}
57)
Lawrence Tang1b0b00e2022-07-05 10:33:10 +010058
59# Link library.
Lawrence Tangd34f2b12022-07-19 15:36:31 +010060target_link_libraries(cper-tests cper-parse json-c GTest::gtest_main)
Lawrence Tangb8fa2f72022-07-18 10:50:19 +010061target_link_libraries(cper-parse json-c b64c)
62target_link_libraries(cper-convert cper-parse)
63target_compile_options(cper-parse PRIVATE -Wno-address-of-packed-member)
64
65# Copy required specification JSON for command line application.
66add_custom_command(TARGET cper-convert POST_BUILD COMMAND ${CMAKE_COMMAND} -E make_directory bin/specification)
Lawrence Tangd34f2b12022-07-19 15:36:31 +010067add_custom_command(TARGET cper-convert POST_BUILD COMMAND cp -r specification/json/* bin/specification)
68
69# Add tests to GoogleTest.
Lawrence Tangfcb09192022-07-19 16:30:39 +010070gtest_discover_tests(cper-tests WORKING_DIRECTORY bin/)