Lawrence Tang | 1b0b00e | 2022-07-05 10:33:10 +0100 | [diff] [blame] | 1 | cmake_minimum_required(VERSION 3.10) |
| 2 | include(FetchContent) |
Lawrence Tang | d34f2b1 | 2022-07-19 15:36:31 +0100 | [diff] [blame] | 3 | include(GoogleTest) |
Lawrence Tang | 1b0b00e | 2022-07-05 10:33:10 +0100 | [diff] [blame] | 4 | project(CPERParse) |
| 5 | |
Lawrence Tang | d34f2b1 | 2022-07-19 15:36:31 +0100 | [diff] [blame] | 6 | # GoogleTest requires at least C++14. |
| 7 | set(CMAKE_CXX_STANDARD 14) |
| 8 | |
Lawrence Tang | 1b0b00e | 2022-07-05 10:33:10 +0100 | [diff] [blame] | 9 | # Output into subdirectories /lib and /bin. |
| 10 | set(EXECUTABLE_OUTPUT_PATH ${CMAKE_BINARY_DIR}/bin) |
| 11 | set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib) |
| 12 | set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib) |
| 13 | set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin) |
| 14 | |
| 15 | # Fetch json-c from git repository. |
| 16 | FetchContent_Declare( |
| 17 | json-c |
| 18 | GIT_REPOSITORY https://github.com/json-c/json-c.git |
| 19 | GIT_TAG d28ac67dde77566f53a97f22b4ea7cb36afe6582 # 4/6/2022 |
| 20 | ) |
Lawrence Tang | d7e8ca3 | 2022-07-07 10:25:53 +0100 | [diff] [blame] | 21 | |
| 22 | # Fetch b64-c from git repository. |
| 23 | FetchContent_Declare( |
| 24 | b64-c |
| 25 | GIT_REPOSITORY https://github.com/jwerle/b64.c.git |
| 26 | GIT_TAG c33188cd541f19b072ee4988d8224ea6c964bed1 # 9/2/2021 |
| 27 | ) |
Lawrence Tang | d34f2b1 | 2022-07-19 15:36:31 +0100 | [diff] [blame] | 28 | |
| 29 | # Fetch GoogleTest from git repository. |
| 30 | FetchContent_Declare( |
| 31 | googletest |
| 32 | GIT_REPOSITORY https://github.com/google/googletest.git |
| 33 | GIT_TAG release-1.12.1 |
| 34 | ) |
| 35 | FetchContent_MakeAvailable(json-c b64-c googletest) |
Lawrence Tang | 1b0b00e | 2022-07-05 10:33:10 +0100 | [diff] [blame] | 36 | |
| 37 | # Add library and test executable. |
| 38 | file(GLOB SectionSources sections/*.c) |
| 39 | file(GLOB EDKSources edk/*.c) |
Lawrence Tang | 02c801a | 2022-07-18 14:43:52 +0100 | [diff] [blame] | 40 | file(GLOB GeneratorSectionSources generator/sections/*.c) |
Lawrence Tang | b8fa2f7 | 2022-07-18 10:50:19 +0100 | [diff] [blame] | 41 | add_library(cper-parse STATIC cper-parse.c ir-parse.c cper-utils.c json-schema.c json-schema.h ${SectionSources} ${EDKSources}) |
Lawrence Tang | 02c801a | 2022-07-18 14:43:52 +0100 | [diff] [blame] | 42 | add_executable(cper-convert cli-app/cper-convert.c) |
Lawrence Tang | d34f2b1 | 2022-07-19 15:36:31 +0100 | [diff] [blame] | 43 | add_executable(cper-generate |
| 44 | generator/cper-generate-cli.c |
| 45 | generator/cper-generate.c |
| 46 | generator/gen-utils.c |
| 47 | ${GeneratorSectionSources} |
| 48 | ${EDKSources} |
| 49 | ) |
| 50 | add_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 Tang | 1b0b00e | 2022-07-05 10:33:10 +0100 | [diff] [blame] | 58 | |
| 59 | # Link library. |
Lawrence Tang | d34f2b1 | 2022-07-19 15:36:31 +0100 | [diff] [blame] | 60 | target_link_libraries(cper-tests cper-parse json-c GTest::gtest_main) |
Lawrence Tang | b8fa2f7 | 2022-07-18 10:50:19 +0100 | [diff] [blame] | 61 | target_link_libraries(cper-parse json-c b64c) |
| 62 | target_link_libraries(cper-convert cper-parse) |
| 63 | target_compile_options(cper-parse PRIVATE -Wno-address-of-packed-member) |
| 64 | |
| 65 | # Copy required specification JSON for command line application. |
| 66 | add_custom_command(TARGET cper-convert POST_BUILD COMMAND ${CMAKE_COMMAND} -E make_directory bin/specification) |
Lawrence Tang | d34f2b1 | 2022-07-19 15:36:31 +0100 | [diff] [blame] | 67 | add_custom_command(TARGET cper-convert POST_BUILD COMMAND cp -r specification/json/* bin/specification) |
| 68 | |
| 69 | # Add tests to GoogleTest. |
Lawrence Tang | fcb0919 | 2022-07-19 16:30:39 +0100 | [diff] [blame] | 70 | gtest_discover_tests(cper-tests WORKING_DIRECTORY bin/) |