blob: 9362f8e27e2b1e6d623b54724d1f379fb2553e6a [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 Tangd34f2b12022-07-19 15:36:31 +010073target_link_libraries(cper-tests cper-parse json-c GTest::gtest_main)
Lawrence Tangb8fa2f72022-07-18 10:50:19 +010074target_link_libraries(cper-parse json-c b64c)
75target_link_libraries(cper-convert cper-parse)
76target_compile_options(cper-parse PRIVATE -Wno-address-of-packed-member)
77
78# Copy required specification JSON for command line application.
79add_custom_command(TARGET cper-convert POST_BUILD COMMAND ${CMAKE_COMMAND} -E make_directory bin/specification)
Lawrence Tangd34f2b12022-07-19 15:36:31 +010080add_custom_command(TARGET cper-convert POST_BUILD COMMAND cp -r specification/json/* bin/specification)
81
82# Add tests to GoogleTest.
Lawrence Tang12042d72022-07-21 13:34:13 +010083gtest_discover_tests(cper-tests WORKING_DIRECTORY bin/)
84
85# Generate Python bindings with SWIG.
86include_directories(cperparse_pylib ${PYTHON_INCLUDE_PATH} ${CMAKE_CURRENT_SOURCE_DIR})
87swig_add_library(cperparse_pylib
88 TYPE STATIC
89 LANGUAGE python
90 SOURCES cper-parse.i
91 OUTPUT_DIR lib/
92)
93swig_link_libraries(cperparse_pylib
94 cper-parse
95 json-c
96 ${PYTHON_LIBRARIES}
97)