Skip to content

Commit

Permalink
[CMake] Introduce POLLY_BUNDLED_JSONCPP.
Browse files Browse the repository at this point in the history
Allow using a system's install jsoncpp library instead of the bundled
one with the setting POLLY_BUNDLED_JSONCPP=OFF.

This fixes llvm.org/PR32929

Differential Revision: https://reviews.llvm.org/D32922

llvm-svn: 302336
  • Loading branch information
Meinersbur committed May 6, 2017
1 parent 6c5e22a commit 2a8f6f8
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 8 deletions.
16 changes: 15 additions & 1 deletion polly/CMakeLists.txt
Expand Up @@ -179,11 +179,25 @@ else()
set(ISL_TARGET PollyISL)
endif()

option(POLLY_BUNDLED_JSONCPP "Use the bundled version of jsoncpp included in Polly" ON)
if (POLLY_BUNDLED_JSONCPP)
set(JSONCPP_INCLUDE_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/lib/External/JSON/include")
set(JSONCPP_LIBRARIES)
set(POLLY_JSON_FILES
External/JSON/json_reader.cpp
External/JSON/json_value.cpp
External/JSON/json_writer.cpp
)
else ()
find_package(Jsoncpp REQUIRED)
set(POLLY_JSON_FILES)
endif ()

include_directories(
BEFORE
${CMAKE_CURRENT_SOURCE_DIR}/include
${ISL_INCLUDE_DIRS}
${CMAKE_CURRENT_SOURCE_DIR}/lib/External/JSON/include
${JSONCPP_INCLUDE_DIRS}
${CMAKE_CURRENT_SOURCE_DIR}/lib/External/pet/include
${CMAKE_CURRENT_SOURCE_DIR}/lib/External
${CMAKE_CURRENT_BINARY_DIR}/include
Expand Down
58 changes: 58 additions & 0 deletions polly/cmake/FindJsoncpp.cmake
@@ -0,0 +1,58 @@
find_package(PkgConfig QUIET)
if (PkgConfig_FOUND)
pkg_search_module(JSONCPP jsoncpp QUIET)

# Get the libraries full paths, to be consistent with find_library().
set(fulllibs)
foreach (libname IN LISTS JSONCPP_LIBRARIES)
find_library(lib NAMES ${libname}
HINTS ${JSONCPP_LIBDIR} ${JSONCPP_LIBRARY_DIRS}
NO_DEFAULT_PATH
)
if (lib)
list(APPEND fulllibs ${lib})
else ()
list(APPEND fulllibs ${libname})
endif ()
endforeach ()
set(JSONCPP_LIBRARIES ${fulllibs})

set(JSONCPP_DEFINITIONS ${JSONCPP_CFLAGS})
else ()
set(JSONCPP_DEFINITIONS)

find_path(JSONCPP_INCLUDE_DIR json/json.h
PATHS ENV JSONCPP_INCLUDE ENV JSONCPP_DIR
PATH_SUFFIXES jsoncpp
NO_DEFAULT_PATH
)
find_path(JSONCPP_INCLUDE_DIR json/json.h
PATH_SUFFIXES jsoncpp
)
mark_as_advanced(JSONCPP_INCLUDE_DIR)
set(JSONCPP_INCLUDE_DIRS "${JSONCPP_INCLUDE_DIR}")

find_library(JSONCPP_LIBRARY NAMES jsoncpp
HINTS ENV JSONCPP_LIB ENV JSONCPP_DIR
NO_DEFAULT_PATH
)
find_library(JSONCPP_LIBRARY NAMES jsoncpp)
mark_as_advanced(JSONCPP_LIBRARY)
set(JSON_LIBRARIES ${JSON_LIBRARY})
endif ()

include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(Jsoncpp DEFAULT_MSG JSONCPP_INCLUDE_DIRS JSONCPP_LIBRARIES JSONCPP_DEFINITIONS)

if (Jsoncpp_FOUND)
add_library(jsoncpp INTERFACE IMPORTED)
foreach (incl IN LISTS JSONCPP_INCLUDE_DIRS)
set_property(TARGET jsoncpp APPEND PROPERTY INTERFACE_INCLUDE_DIRECTORIES ${incl})
endforeach ()
foreach (libname IN LISTS JSONCPP_LIBRARIES)
set_property(TARGET jsoncpp APPEND PROPERTY INTERFACE_LINK_LIBRARIES ${lib})
endforeach ()
foreach (opt IN LISTS JSONCPP_DEFINITIONS)
set_property(TARGET jsoncpp APPEND PROPERTY INTERFACE_COMPILE_OPTIONS ${opt})
endforeach ()
endif ()
2 changes: 2 additions & 0 deletions polly/cmake/PollyConfig.cmake.in
Expand Up @@ -5,6 +5,7 @@ find_package(LLVM REQUIRED CONFIG

set(Polly_CMAKE_DIR ${CMAKE_CURRENT_LIST_DIR})
set(Polly_BUNDLED_ISL @POLLY_BUNDLED_ISL@)
set(Polly_BUNDLED_JSONCPP @POLLY_BUNDLED_JSONCPP@)
set(Polly_ENABLE_GPGPU_CODEGEN @POLLY_ENABLE_GPGPU_CODEGEN@)

set(Polly_DEFINITIONS ${LLVM_DEFINITIONS})
Expand All @@ -27,6 +28,7 @@ if (NOT TARGET Polly)
if (Polly_ENABLE_GPGPU_CODEGEN)
set_property(TARGET Polly APPEND PROPERTY INTERFACE_LINK_LIBRARIES PollyPPCG)
endif()
set_property(TARGET Polly APPEND PROPERTY INTERFACE_LINK_LIBRARIES @JSONCPP_LIBRARIES@)
endif()

if (NOT TARGET LLVMPolly)
Expand Down
9 changes: 2 additions & 7 deletions polly/lib/CMakeLists.txt
@@ -1,11 +1,5 @@
set(LLVM_NO_RTTI 1)

set(POLLY_JSON_FILES
External/JSON/json_reader.cpp
External/JSON/json_value.cpp
External/JSON/json_writer.cpp
)

set(ISL_CODEGEN_FILES
CodeGen/IslAst.cpp
CodeGen/IslExprBuilder.cpp
Expand Down Expand Up @@ -77,6 +71,7 @@ set_target_properties(PollyCore PROPERTIES FOLDER "Polly")
add_polly_library(Polly $<TARGET_OBJECTS:PollyCore>)
target_link_libraries(Polly
${ISL_TARGET}
${JSONCPP_LIBRARIES}
)

# Additional dependencies for Polly-ACC.
Expand Down Expand Up @@ -158,7 +153,7 @@ else ()
# hosts. This is not the case for bugpoint. Use LLVM_POLLY_LINK_INTO_TOOLS=ON
# instead which will automatically resolve the additional dependencies by
# Polly.
target_link_libraries(LLVMPolly ${ISL_TARGET})
target_link_libraries(LLVMPolly ${ISL_TARGET} ${JSONCPP_LIBRARIES})
if (GPU_CODEGEN)
target_link_libraries(LLVMPolly PollyPPCG)
endif ()
Expand Down

0 comments on commit 2a8f6f8

Please sign in to comment.