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