Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Building the project with cmake #215

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

cmake_minimum_required(VERSION 3.13...3.18)

# Ensures that we do an out of source build

MACRO(MACRO_ENSURE_OUT_OF_SOURCE_BUILD MSG)
STRING(COMPARE EQUAL "${CMAKE_SOURCE_DIR}"
"${CMAKE_BINARY_DIR}" insource)
GET_FILENAME_COMPONENT(PARENTDIR ${CMAKE_SOURCE_DIR} PATH)
STRING(COMPARE EQUAL "${CMAKE_SOURCE_DIR}"
"${PARENTDIR}" insourcesubdir)
IF(insource OR insourcesubdir)
MESSAGE(FATAL_ERROR "${MSG}")
ENDIF(insource OR insourcesubdir)
ENDMACRO(MACRO_ENSURE_OUT_OF_SOURCE_BUILD)

MACRO_ENSURE_OUT_OF_SOURCE_BUILD(
"${CMAKE_PROJECT_NAME} requires an out of source build. Please run cmake from a distinct directory."
)
project(jsmn)

enable_testing()

add_subdirectory(test)
add_subdirectory(example)
36 changes: 0 additions & 36 deletions Makefile

This file was deleted.

18 changes: 18 additions & 0 deletions example/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@

cmake_minimum_required(VERSION 3.13...3.18)

project(examples)

add_executable(simple simple.c ../jsmn.h)

add_executable(jsondump jsondump.c ../jsmn.h)

add_custom_target(fmt clang-format -i jsmn.h test/*.[ch] example/*.[ch])

add_custom_target(lint clang-tidy jsmn.h --checks='*')

set_target_properties(
simple jsondump
PROPERTIES
SUFFIX ".exe"
)
27 changes: 27 additions & 0 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@

cmake_minimum_required(VERSION 3.13...3.18)

project(full_test)

add_executable(test_default tests.c ../jsmn.h)

add_executable(test_strict tests.c ../jsmn.h)
target_compile_definitions(test_strict PUBLIC JSMN_STRICT)

add_executable(test_links tests.c ../jsmn.h)
target_compile_definitions(test_links PUBLIC JSMN_PARENT_LINKS)

add_executable(test_strict_links tests.c ../jsmn.h)
target_compile_definitions(test_strict_links PUBLIC JSMN_STRICT JSMN_PARENT_LINKS)

set_target_properties(
test_default test_strict test_links test_strict_links
PROPERTIES
SUFFIX ".exe"
)

enable_testing()
add_test(NAME running_test_default COMMAND test_default)
add_test(NAME running_test_strict COMMAND test_strict)
add_test(NAME running_test_links COMMAND test_links)
add_test(NAME running_test_strict_links COMMAND test_strict_links)