Skip to content

Commit

Permalink
Merge pull request google#7 from eile/master
Browse files Browse the repository at this point in the history
Integrate PkgConfig work from @biddisco, allows sub project use
  • Loading branch information
eile committed Jan 7, 2015
2 parents 2e50f09 + 1130768 commit 194c1c1
Show file tree
Hide file tree
Showing 3 changed files with 107 additions and 65 deletions.
57 changes: 0 additions & 57 deletions CMake/FindFlatBuffers.cmake

This file was deleted.

41 changes: 41 additions & 0 deletions CMake/FlatBuffersConfig.cmake.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#-----------------------------------------------------------------------------
# Include target definitions :
# Skip them if flatc is already defined - this can be because it was compiled
# as part of the same project using add_subdirectory
#-----------------------------------------------------------------------------
if(NOT TARGET flatc)
include ("${CMAKE_CURRENT_LIST_DIR}/FlatBuffersTargets.cmake")
endif ()

#-----------------------------------------------------------------------------
# Include directories
#-----------------------------------------------------------------------------
set(FlatBuffers_INCLUDE_DIRS @FLATBUFFERS_INCLUDE_DIRS@)
set(FlatBuffers_FOUND 1)

# these are for compatibility with older cmake scripts
set(FlatBuffers_INCLUDE_DIR @FLATBUFFERS_INCLUDE_DIRS@)
set(FLATBUFFERS_INCLUDE_DIRS @FLATBUFFERS_INCLUDE_DIRS@)
set(FLATBUFFERS_INCLUDE_DIR @FLATBUFFERS_INCLUDE_DIRS@)
set(FLATBUFFERS_FLATC_EXECUTABLE flatc)

#-----------------------------------------------------------------------------
# function needed by dependent projects
#-----------------------------------------------------------------------------
function(flatbuffers_generate_c_headers Name)
set(FLATC_OUTPUTS)
foreach(FILE ${ARGN})
get_filename_component(FLATC_OUTPUT ${FILE} NAME_WE)
set(FLATC_OUTPUT
"${CMAKE_CURRENT_BINARY_DIR}/${FLATC_OUTPUT}_generated.h")
list(APPEND FLATC_OUTPUTS ${FLATC_OUTPUT})

add_custom_command(OUTPUT ${FLATC_OUTPUT}
COMMAND ${FLATBUFFERS_FLATC_EXECUTABLE}
ARGS -c -o "${CMAKE_CURRENT_BINARY_DIR}/" ${FILE}
COMMENT "Building C++ header for ${FILE}"
DEPENDS ${FILE} ${FLATBUFFERS_FLATC_EXECUTABLE}
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
endforeach()
set(${Name}_OUTPUTS ${FLATC_OUTPUTS} PARENT_SCOPE)
endfunction()
74 changes: 66 additions & 8 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
cmake_minimum_required(VERSION 2.8)

project(FlatBuffers)
set(FlatBuffers_VERSION 1.0.0)

# NOTE: Code coverage only works on Linux & OSX.
option(FLATBUFFERS_CODE_COVERAGE "Enable the code coverage build option." OFF)
Expand Down Expand Up @@ -75,7 +76,7 @@ elseif(CMAKE_COMPILER_IS_GNUCXX OR
CMAKE_CXX_COMPILER_ID STREQUAL "Clang" OR
CMAKE_CXX_COMPILER_ID STREQUAL "Intel")
set(CMAKE_CXX_FLAGS
"${CMAKE_CXX_FLAGS} -std=c++0x -Wall -pedantic -Werror -Wextra")
"${CMAKE_CXX_FLAGS} -std=c++0x -Wall -pedantic -Werror -Wextra -fno-strict-aliasing")
endif()
if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Qunused-arguments")
Expand All @@ -89,8 +90,6 @@ endif()

include_directories(include)

add_executable(flatc ${FlatBuffers_Compiler_SRCS})

function(compile_flatbuffers_schema_to_cpp SRC_FBS)
get_filename_component(SRC_FBS_DIR ${SRC_FBS} PATH)
string(REGEX REPLACE "\\.fbs$" "_generated.h" GEN_HEADER ${SRC_FBS})
Expand All @@ -100,6 +99,8 @@ function(compile_flatbuffers_schema_to_cpp SRC_FBS)
DEPENDS flatc)
endfunction()

add_executable(flatc ${FlatBuffers_Compiler_SRCS})

if(FLATBUFFERS_BUILD_TESTS)
compile_flatbuffers_schema_to_cpp(tests/monster_test.fbs)
include_directories(${CMAKE_CURRENT_BINARY_DIR}/tests)
Expand All @@ -116,9 +117,66 @@ if(FLATBUFFERS_BUILD_TESTS)
add_test(NAME flattests COMMAND flattests)
endif()

if(FLATBUFFERS_INSTALL)
install(DIRECTORY include/flatbuffers DESTINATION include)
install(FILES "${PROJECT_BINARY_DIR}/include/flatbuffers/options.h"
DESTINATION include/flatbuffers)
install(TARGETS flatc DESTINATION bin)

if(NOT FLATBUFFERS_INSTALL)
return()
endif()

#--------------------------------------------------
# INSTALL : setup files for projects that find_package(FlatBuffers)
# FlatBuffersTargets.cmake (any targets we export that another project needs)
# FlatBuffersConfigVersion.cmake (version info)
# FlatBuffersConfig.cmake (all the other variables another project needs)
#
# Supports three methods of using FlatBuffers
# find_package(FlatBuffers) - pointing to the INSTALL location
# find_package(FlatBuffers) - pointing to the BUILD directory
# add_subdirectory(FlatBuffers) - where the project using
# FlatBuffers can simply set FlatBuffers_DIR to the build subdirectoy
# The main difference is that the build dir versions need the source tree
# include locations instead of the install tree.
#--------------------------------------------------

set(ConfigPackageLocation share/cmake/FlatBuffers)

install(DIRECTORY include/flatbuffers DESTINATION include)
install(FILES "${PROJECT_BINARY_DIR}/include/flatbuffers/options.h"
DESTINATION include/flatbuffers)

install(TARGETS flatc
EXPORT FlatBuffersTargets
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib
RUNTIME DESTINATION bin
PUBLIC_HEADER DESTINATION include)

install(EXPORT FlatBuffersTargets
FILE FlatBuffersTargets.cmake DESTINATION .)

install(EXPORT FlatBuffersTargets
FILE FlatBuffersTargets.cmake DESTINATION ${ConfigPackageLocation})

include(CMakePackageConfigHelpers)
write_basic_package_version_file(
"${CMAKE_CURRENT_BINARY_DIR}/FlatBuffersConfigVersion.cmake"
VERSION ${FlatBuffers_VERSION} COMPATIBILITY AnyNewerVersion)

install(FILES "${CMAKE_CURRENT_BINARY_DIR}/FlatBuffersConfigVersion.cmake"
DESTINATION ${ConfigPackageLocation} COMPONENT dev)

# Setup include files for the BUILD dir and source location
set(FLATBUFFERS_INCLUDE_DIRS
"${PROJECT_BINARY_DIR}/include"
"${CMAKE_CURRENT_SOURCE_DIR}/include")

configure_file(${CMAKE_CURRENT_SOURCE_DIR}/CMake/FlatBuffersConfig.cmake.in
"${CMAKE_CURRENT_BINARY_DIR}/FlatBuffersConfig.cmake" @ONLY)

# Setup include files for the INSTALL dir
set(FLATBUFFERS_INCLUDE_DIRS "${CMAKE_INSTALL_PREFIX}/include")

configure_file(${CMAKE_CURRENT_SOURCE_DIR}/CMake/FlatBuffersConfig.cmake.in
"${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/FlatBuffersConfig.cmake" @ONLY)

install(FILES "${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/FlatBuffersConfig.cmake"
DESTINATION ${ConfigPackageLocation} COMPONENT dev)

0 comments on commit 194c1c1

Please sign in to comment.