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 | 12042d7 | 2022-07-21 13:34:13 +0100 | [diff] [blame] | 4 | include(FindSWIG) |
| 5 | include(UseSWIG) |
| 6 | find_package(PythonLibs 3 REQUIRED) |
| 7 | find_package(PythonInterp ${PYTHONLIBS_VERSION_STRING} REQUIRED) |
Lawrence Tang | 1b0b00e | 2022-07-05 10:33:10 +0100 | [diff] [blame] | 8 | project(CPERParse) |
| 9 | |
Lawrence Tang | d34f2b1 | 2022-07-19 15:36:31 +0100 | [diff] [blame] | 10 | # GoogleTest requires at least C++14. |
| 11 | set(CMAKE_CXX_STANDARD 14) |
| 12 | |
Lawrence Tang | 1b0b00e | 2022-07-05 10:33:10 +0100 | [diff] [blame] | 13 | # Output into subdirectories /lib and /bin. |
| 14 | set(EXECUTABLE_OUTPUT_PATH ${CMAKE_BINARY_DIR}/bin) |
| 15 | set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib) |
| 16 | set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib) |
| 17 | set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin) |
| 18 | |
| 19 | # Fetch json-c from git repository. |
| 20 | FetchContent_Declare( |
| 21 | json-c |
| 22 | GIT_REPOSITORY https://github.com/json-c/json-c.git |
| 23 | GIT_TAG d28ac67dde77566f53a97f22b4ea7cb36afe6582 # 4/6/2022 |
| 24 | ) |
Lawrence Tang | d7e8ca3 | 2022-07-07 10:25:53 +0100 | [diff] [blame] | 25 | |
| 26 | # Fetch b64-c from git repository. |
| 27 | FetchContent_Declare( |
| 28 | b64-c |
| 29 | GIT_REPOSITORY https://github.com/jwerle/b64.c.git |
| 30 | GIT_TAG c33188cd541f19b072ee4988d8224ea6c964bed1 # 9/2/2021 |
| 31 | ) |
Lawrence Tang | d34f2b1 | 2022-07-19 15:36:31 +0100 | [diff] [blame] | 32 | |
| 33 | # Fetch GoogleTest from git repository. |
| 34 | FetchContent_Declare( |
| 35 | googletest |
| 36 | GIT_REPOSITORY https://github.com/google/googletest.git |
| 37 | GIT_TAG release-1.12.1 |
| 38 | ) |
| 39 | FetchContent_MakeAvailable(json-c b64-c googletest) |
Lawrence Tang | 1b0b00e | 2022-07-05 10:33:10 +0100 | [diff] [blame] | 40 | |
| 41 | # Add library and test executable. |
| 42 | file(GLOB SectionSources sections/*.c) |
| 43 | file(GLOB EDKSources edk/*.c) |
Lawrence Tang | 02c801a | 2022-07-18 14:43:52 +0100 | [diff] [blame] | 44 | file(GLOB GeneratorSectionSources generator/sections/*.c) |
Lawrence Tang | aacf0e2 | 2022-07-20 13:28:52 +0100 | [diff] [blame] | 45 | add_library(cper-parse STATIC |
| 46 | cper-parse.c |
| 47 | ir-parse.c |
| 48 | cper-utils.c |
| 49 | common-utils.c |
| 50 | json-schema.c |
| 51 | ${SectionSources} |
| 52 | ${EDKSources} |
| 53 | ) |
Lawrence Tang | 02c801a | 2022-07-18 14:43:52 +0100 | [diff] [blame] | 54 | add_executable(cper-convert cli-app/cper-convert.c) |
Lawrence Tang | d34f2b1 | 2022-07-19 15:36:31 +0100 | [diff] [blame] | 55 | add_executable(cper-generate |
| 56 | generator/cper-generate-cli.c |
| 57 | generator/cper-generate.c |
| 58 | generator/gen-utils.c |
Lawrence Tang | aacf0e2 | 2022-07-20 13:28:52 +0100 | [diff] [blame] | 59 | common-utils.c |
Lawrence Tang | d34f2b1 | 2022-07-19 15:36:31 +0100 | [diff] [blame] | 60 | ${GeneratorSectionSources} |
| 61 | ${EDKSources} |
| 62 | ) |
| 63 | add_executable(cper-tests |
| 64 | tests/ir-tests.cpp |
| 65 | tests/test-utils.cpp |
| 66 | generator/cper-generate.c |
| 67 | generator/gen-utils.c |
| 68 | ${GeneratorSectionSources} |
| 69 | ${EDKSources} |
| 70 | ) |
Lawrence Tang | 1b0b00e | 2022-07-05 10:33:10 +0100 | [diff] [blame] | 71 | |
| 72 | # Link library. |
Lawrence Tang | d34f2b1 | 2022-07-19 15:36:31 +0100 | [diff] [blame] | 73 | target_link_libraries(cper-tests cper-parse json-c GTest::gtest_main) |
Lawrence Tang | b8fa2f7 | 2022-07-18 10:50:19 +0100 | [diff] [blame] | 74 | target_link_libraries(cper-parse json-c b64c) |
| 75 | target_link_libraries(cper-convert cper-parse) |
| 76 | target_compile_options(cper-parse PRIVATE -Wno-address-of-packed-member) |
| 77 | |
| 78 | # Copy required specification JSON for command line application. |
| 79 | 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] | 80 | add_custom_command(TARGET cper-convert POST_BUILD COMMAND cp -r specification/json/* bin/specification) |
| 81 | |
| 82 | # Add tests to GoogleTest. |
Lawrence Tang | 12042d7 | 2022-07-21 13:34:13 +0100 | [diff] [blame] | 83 | gtest_discover_tests(cper-tests WORKING_DIRECTORY bin/) |
| 84 | |
| 85 | # Generate Python bindings with SWIG. |
| 86 | include_directories(cperparse_pylib ${PYTHON_INCLUDE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}) |
| 87 | swig_add_library(cperparse_pylib |
| 88 | TYPE STATIC |
| 89 | LANGUAGE python |
| 90 | SOURCES cper-parse.i |
| 91 | OUTPUT_DIR lib/ |
| 92 | ) |
| 93 | swig_link_libraries(cperparse_pylib |
| 94 | cper-parse |
| 95 | json-c |
| 96 | ${PYTHON_LIBRARIES} |
| 97 | ) |