blob: d967a677f39027da2b6c8fdb0068b6b8b5f05aa1 [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 Tang12042d72022-07-21 13:34:13 +01004include(FindSWIG)
5include(UseSWIG)
6find_package(PythonLibs 3 REQUIRED)
7find_package(PythonInterp ${PYTHONLIBS_VERSION_STRING} REQUIRED)
Lawrence Tang1b0b00e2022-07-05 10:33:10 +01008project(CPERParse)
9
Lawrence Tangd34f2b12022-07-19 15:36:31 +010010# GoogleTest requires at least C++14.
11set(CMAKE_CXX_STANDARD 14)
12
Lawrence Tang1b0b00e2022-07-05 10:33:10 +010013# Output into subdirectories /lib and /bin.
14set(EXECUTABLE_OUTPUT_PATH ${CMAKE_BINARY_DIR}/bin)
15set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
16set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
17set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
18
19# Fetch json-c from git repository.
20FetchContent_Declare(
21 json-c
22 GIT_REPOSITORY https://github.com/json-c/json-c.git
Lawrence Tang9aaf8352022-08-08 09:53:39 +010023 GIT_TAG 9021cdcdd01fc9dbcbe1f06391848c2ac915212f # 0.15
Lawrence Tang1b0b00e2022-07-05 10:33:10 +010024)
Lawrence Tangd7e8ca32022-07-07 10:25:53 +010025
26# Fetch b64-c from git repository.
27FetchContent_Declare(
28 b64-c
29 GIT_REPOSITORY https://github.com/jwerle/b64.c.git
30 GIT_TAG c33188cd541f19b072ee4988d8224ea6c964bed1 # 9/2/2021
31)
Lawrence Tangd34f2b12022-07-19 15:36:31 +010032
33# Fetch GoogleTest from git repository.
34FetchContent_Declare(
35 googletest
36 GIT_REPOSITORY https://github.com/google/googletest.git
37 GIT_TAG release-1.12.1
38)
39FetchContent_MakeAvailable(json-c b64-c googletest)
Lawrence Tang1b0b00e2022-07-05 10:33:10 +010040
41# Add library and test executable.
42file(GLOB SectionSources sections/*.c)
43file(GLOB EDKSources edk/*.c)
Lawrence Tang02c801a2022-07-18 14:43:52 +010044file(GLOB GeneratorSectionSources generator/sections/*.c)
Lawrence Tangaacf0e22022-07-20 13:28:52 +010045add_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 Tang02c801a2022-07-18 14:43:52 +010054add_executable(cper-convert cli-app/cper-convert.c)
Lawrence Tangd34f2b12022-07-19 15:36:31 +010055add_executable(cper-generate
56 generator/cper-generate-cli.c
57 generator/cper-generate.c
58 generator/gen-utils.c
Lawrence Tangaacf0e22022-07-20 13:28:52 +010059 common-utils.c
Lawrence Tangd34f2b12022-07-19 15:36:31 +010060 ${GeneratorSectionSources}
61 ${EDKSources}
62)
63add_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 Tang1b0b00e2022-07-05 10:33:10 +010071
72# Link library.
Lawrence Tang3b0eff72022-08-08 10:56:47 +010073target_link_directories(cper-tests PUBLIC ${GTEST_LIBRARY_DIRS} ${GMOCK_LDFLAGS})
Lawrence Tangd34f2b12022-07-19 15:36:31 +010074target_link_libraries(cper-tests cper-parse json-c GTest::gtest_main)
Lawrence Tangb8fa2f72022-07-18 10:50:19 +010075target_link_libraries(cper-parse json-c b64c)
76target_link_libraries(cper-convert cper-parse)
77target_compile_options(cper-parse PRIVATE -Wno-address-of-packed-member)
78
79# Copy required specification JSON for command line application.
80add_custom_command(TARGET cper-convert POST_BUILD COMMAND ${CMAKE_COMMAND} -E make_directory bin/specification)
Lawrence Tangd34f2b12022-07-19 15:36:31 +010081add_custom_command(TARGET cper-convert POST_BUILD COMMAND cp -r specification/json/* bin/specification)
82
83# Add tests to GoogleTest.
Lawrence Tang12042d72022-07-21 13:34:13 +010084gtest_discover_tests(cper-tests WORKING_DIRECTORY bin/)
85
86# Generate Python bindings with SWIG.
87include_directories(cperparse_pylib ${PYTHON_INCLUDE_PATH} ${CMAKE_CURRENT_SOURCE_DIR})
88swig_add_library(cperparse_pylib
89 TYPE STATIC
90 LANGUAGE python
91 SOURCES cper-parse.i
92 OUTPUT_DIR lib/
93)
94swig_link_libraries(cperparse_pylib
95 cper-parse
96 json-c
97 ${PYTHON_LIBRARIES}
98)