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

Add CMake building system support #28

Closed
inkooboo opened this issue May 25, 2011 · 2 comments
Closed

Add CMake building system support #28

inkooboo opened this issue May 25, 2011 · 2 comments

Comments

@inkooboo
Copy link

Hi Petri =))

CMake building system going to be more popular. It will be good to add this build system support.

I wrote working example code for this project, which should be place in "src" directory into file CMakeLists.txt

include_directories(${CMAKE_CURRENT_SOURCE_DIR})

set(janson_SOURCES
dump.c
error.c
hashtable.c
hashtable.h
jansson_private.h
load.c
memory.c
pack_unpack.c
strbuffer.c
strbuffer.h
utf.c
utf.h
value.c)

add_library(janson STATIC ${janson_SOURCES})

This code builds jansson as a static libary.

@akheron
Copy link
Owner

akheron commented May 26, 2011

Hi, and thanks for the suggestion. However, I'm not willing to support two different build systems. Autotools works fine for me (and for others), and if it cannot be used for some reason, it's quite straightforward just to take all .c files and compile them as a library by hand.

@akheron akheron closed this as completed May 26, 2011
@quarnster
Copy link

For anyone else wanting CMake support, here's the CMakeLists.txt I wrote which properly configures jansson_config.h and sets up a install target:

cmake_minimum_required(VERSION 2.8)

include(CheckSymbolExists)
include(CheckCSourceCompiles)
check_symbol_exists(localeconv locale.h json_have_localeconv)
if(NOT json_have_localeconv)
    set(json_have_localeconv 0)
endif()
check_c_source_compiles("int main() { long long test = 0; return test; }" json_have_long_long)
if(NOT json_have_long_long)
    set(json_have_long_long 0)
endif()
check_c_source_compiles("inline int test() { return 0; }\nint main() { return test(); }" json_inline)
if(json_inline)
    set(json_inline inline)
endif()
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/src/jansson_config.h.in ${CMAKE_CURRENT_BINARY_DIR}/jansson_config.h)
set(json_have_long_long 0)
include_directories(${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/src)
add_library(jansson STATIC
    src/dump.c
    src/error.c
    src/hashtable.c
    src/load.c
    src/memory.c
    src/pack_unpack.c
    src/strbuffer.c
    src/strconv.c
    src/utf.c
    src/value.c)


install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/src/jansson.h ${CMAKE_CURRENT_BINARY_DIR}/jansson_config.h DESTINATION include)
install(TARGETS jansson ARCHIVE DESTINATION lib)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants