-
Notifications
You must be signed in to change notification settings - Fork 542
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #19 from yajiedesign/addcmake
add cmake
- Loading branch information
Showing
12 changed files
with
1,497 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
cmake_minimum_required(VERSION 2.8.7) | ||
|
||
project(pslite C CXX) | ||
|
||
list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake/Modules) | ||
|
||
include(ExternalProject) | ||
set(pslite_LINKER_LIBS "") | ||
|
||
# ---[ Google-gflags | ||
include("cmake/External/gflags.cmake") | ||
include_directories(pslite ${GFLAGS_INCLUDE_DIRS}) | ||
list(APPEND pslite_LINKER_LIBS ${GFLAGS_LIBRARIES}) | ||
|
||
# ---[ Google-glog | ||
include("cmake/External/glog.cmake") | ||
include_directories(pslite ${GLOG_INCLUDE_DIRS}) | ||
list(APPEND pslite_LINKER_LIBS ${GLOG_LIBRARIES}) | ||
|
||
# ---[ Google-protobuf | ||
include(cmake/ProtoBuf.cmake) | ||
|
||
# generate protobuf sources | ||
set(proto_gen_folder "${PROJECT_BINARY_DIR}/include") | ||
file(GLOB proto_files "src/proto/*.proto") | ||
pslite_protobuf_generate_cpp_py(${proto_gen_folder} proto_srcs proto_hdrs proto_python "${PROJECT_SOURCE_DIR}" "src" ${proto_files}) | ||
include_directories(pslite "${PROJECT_BINARY_DIR}/include/") | ||
|
||
FILE(GLOB SOURCE "src/*.cc") | ||
|
||
if(MSVC) | ||
FILE(GLOB getopt_SOURCE "src/windows/getopt.c") | ||
list(APPEND SOURCE ${getopt_SOURCE}) | ||
add_definitions(-DSTATIC_GETOPT) | ||
endif() | ||
|
||
list(APPEND SOURCE ${proto_srcs}) | ||
add_library(pslite ${SOURCE}) | ||
|
||
target_link_libraries(pslite ${pslite_LINKER_LIBS}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
if (NOT __GETOPT_INCLUDED) # guard against multiple includes | ||
set(__GETOPT_INCLUDED TRUE) | ||
include(CheckIncludeFile) | ||
check_include_file("getopt.h" HAVE_GETOPT_H) | ||
if(NOT HAVE_GETOPT_H) | ||
find_path(GETOPT_INCLUDE_DIRS "getopt.h") | ||
find_library(GETOPT_LIBRARIES "getopt") | ||
endif() | ||
|
||
endif() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
if (NOT __GFLAGS_INCLUDED) # guard against multiple includes | ||
set(__GFLAGS_INCLUDED TRUE) | ||
|
||
# use the system-wide gflags if present | ||
find_package(GFlags) | ||
if (GFLAGS_FOUND) | ||
set(GFLAGS_EXTERNAL FALSE) | ||
else() | ||
# gflags will use pthreads if it's available in the system, so we must link with it | ||
find_package(Threads) | ||
|
||
# build directory | ||
set(gflags_PREFIX ${CMAKE_BINARY_DIR}/external/gflags-prefix) | ||
# install directory | ||
set(gflags_INSTALL ${CMAKE_BINARY_DIR}/external/gflags-install) | ||
|
||
# we build gflags statically, but want to link it into the caffe shared library | ||
# this requires position-independent code | ||
if (UNIX) | ||
set(GFLAGS_EXTRA_COMPILER_FLAGS "-fPIC") | ||
endif() | ||
|
||
set(GFLAGS_CXX_FLAGS ${CMAKE_CXX_FLAGS} ${GFLAGS_EXTRA_COMPILER_FLAGS}) | ||
set(GFLAGS_C_FLAGS ${CMAKE_C_FLAGS} ${GFLAGS_EXTRA_COMPILER_FLAGS}) | ||
|
||
ExternalProject_Add(gflags | ||
PREFIX ${gflags_PREFIX} | ||
GIT_REPOSITORY "https://github.com/gflags/gflags.git" | ||
GIT_TAG "v2.1.2" | ||
UPDATE_COMMAND "" | ||
INSTALL_DIR ${gflags_INSTALL} | ||
CMAKE_ARGS -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} | ||
-DCMAKE_INSTALL_PREFIX=${gflags_INSTALL} | ||
-DBUILD_SHARED_LIBS=OFF | ||
-DBUILD_STATIC_LIBS=ON | ||
-DBUILD_PACKAGING=OFF | ||
-DBUILD_TESTING=OFF | ||
-DBUILD_NC_TESTS=OFF | ||
-BUILD_CONFIG_TESTS=OFF | ||
-DINSTALL_HEADERS=ON | ||
-DCMAKE_C_FLAGS=${GFLAGS_C_FLAGS} | ||
-DCMAKE_CXX_FLAGS=${GFLAGS_CXX_FLAGS} | ||
LOG_DOWNLOAD 1 | ||
LOG_INSTALL 1 | ||
) | ||
|
||
set(GFLAGS_FOUND TRUE) | ||
set(GFLAGS_INCLUDE_DIRS ${gflags_INSTALL}/include) | ||
if(MSVC) | ||
set(GFLAGS_LIBRARIES ${gflags_INSTALL}/lib/gflags.lib ${CMAKE_THREAD_LIBS_INIT}) | ||
else() | ||
set(GFLAGS_LIBRARIES ${gflags_INSTALL}/lib/libgflags.a ${CMAKE_THREAD_LIBS_INIT}) | ||
endif() | ||
set(GFLAGS_LIBRARY_DIRS ${gflags_INSTALL}/lib) | ||
set(GFLAGS_EXTERNAL TRUE) | ||
|
||
list(APPEND external_project_dependencies gflags) | ||
endif() | ||
|
||
endif() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
# glog depends on gflags | ||
include("cmake/External/gflags.cmake") | ||
|
||
set(GFLAGS_ROOT_DIR ${gflags_INSTALL}) | ||
|
||
if (NOT __GLOG_INCLUDED) | ||
set(__GLOG_INCLUDED TRUE) | ||
|
||
# try the system-wide glog first | ||
find_package(Glog) | ||
if (GLOG_FOUND) | ||
set(GLOG_EXTERNAL FALSE) | ||
else() | ||
# fetch and build glog from github | ||
|
||
# build directory | ||
set(glog_PREFIX ${CMAKE_BINARY_DIR}/external/glog-prefix) | ||
# install directory | ||
set(glog_INSTALL ${CMAKE_BINARY_DIR}/external/glog-install) | ||
|
||
# we build glog statically, but want to link it into the caffe shared library | ||
# this requires position-independent code | ||
if (UNIX) | ||
set(GLOG_EXTRA_COMPILER_FLAGS "-fPIC") | ||
endif() | ||
|
||
set(GLOG_CXX_FLAGS ${CMAKE_CXX_FLAGS} ${GLOG_EXTRA_COMPILER_FLAGS}) | ||
set(GLOG_C_FLAGS ${CMAKE_C_FLAGS} ${GLOG_EXTRA_COMPILER_FLAGS}) | ||
|
||
# depend on gflags if we're also building it | ||
if (GFLAGS_EXTERNAL) | ||
set(GLOG_DEPENDS gflags) | ||
endif() | ||
|
||
|
||
ExternalProject_Add(glog | ||
DEPENDS ${GLOG_DEPENDS} | ||
PREFIX ${glog_PREFIX} | ||
GIT_REPOSITORY "https://github.com/google/glog" | ||
UPDATE_COMMAND "" | ||
INSTALL_DIR ${glog_INSTALL} | ||
CMAKE_ARGS -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} | ||
-DCMAKE_INSTALL_PREFIX=${glog_INSTALL} | ||
-DCMAKE_PREFIX_PATH=${gflags_INSTALL} | ||
-Dgflags_FOUND=ON | ||
-Dgflags_INCLUDE_DIR=${gflags_INSTALL}/Include | ||
-Dgflags_INCLUDE_DIR=${gflags_INSTALL}/Lib/gflags | ||
-DBUILD_SHARED_LIBS=OFF | ||
-DINSTALL_HEADERS=ON | ||
-DCMAKE_C_FLAGS=${GLOG_C_FLAGS} | ||
-DCMAKE_CXX_FLAGS=${GLOG_CXX_FLAGS} | ||
LOG_DOWNLOAD 1 | ||
LOG_CONFIGURE 1 | ||
LOG_INSTALL 1 | ||
) | ||
|
||
set(GLOG_FOUND TRUE) | ||
set(GLOG_INCLUDE_DIRS ${glog_INSTALL}/include) | ||
if(MSVC) | ||
set(GLOG_LIBRARIES ${GFLAGS_LIBRARIES} ${glog_INSTALL}/lib/glog.lib) | ||
else() | ||
set(GLOG_LIBRARIES ${GFLAGS_LIBRARIES} ${glog_INSTALL}/lib/libglog.a) | ||
endif() | ||
set(GLOG_LIBRARY_DIRS ${glog_INSTALL}/lib) | ||
set(GLOG_EXTERNAL TRUE) | ||
|
||
list(APPEND external_project_dependencies glog) | ||
endif() | ||
|
||
endif() | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
# - Try to find Glog | ||
# | ||
# The following variables are optionally searched for defaults | ||
# GLOG_ROOT_DIR: Base directory where all GLOG components are found | ||
# | ||
# The following are set after configuration is done: | ||
# GLOG_FOUND | ||
# GLOG_INCLUDE_DIRS | ||
# GLOG_LIBRARIES | ||
# GLOG_LIBRARYRARY_DIRS | ||
|
||
include(FindPackageHandleStandardArgs) | ||
|
||
set(GLOG_ROOT_DIR "" CACHE PATH "Folder contains Google glog") | ||
|
||
if(WIN32) | ||
find_path(GLOG_INCLUDE_DIR glog/logging.h | ||
PATHS ${GLOG_ROOT_DIR}/src/windows) | ||
else() | ||
find_path(GLOG_INCLUDE_DIR glog/logging.h | ||
PATHS ${GLOG_ROOT_DIR}) | ||
endif() | ||
|
||
if(MSVC) | ||
find_library(GLOG_LIBRARY_RELEASE libglog_static | ||
PATHS ${GLOG_ROOT_DIR} | ||
PATH_SUFFIXES Release) | ||
|
||
find_library(GLOG_LIBRARY_DEBUG libglog_static | ||
PATHS ${GLOG_ROOT_DIR} | ||
PATH_SUFFIXES Debug) | ||
|
||
set(GLOG_LIBRARY optimized ${GLOG_LIBRARY_RELEASE} debug ${GLOG_LIBRARY_DEBUG}) | ||
else() | ||
find_library(GLOG_LIBRARY glog | ||
PATHS ${GLOG_ROOT_DIR} | ||
PATH_SUFFIXES lib lib64) | ||
endif() | ||
|
||
find_package_handle_standard_args(Glog DEFAULT_MSG GLOG_INCLUDE_DIR GLOG_LIBRARY) | ||
|
||
if(GLOG_FOUND) | ||
set(GLOG_INCLUDE_DIRS ${GLOG_INCLUDE_DIR}) | ||
set(GLOG_LIBRARIES ${GLOG_LIBRARY}) | ||
message(STATUS "Found glog (include: ${GLOG_INCLUDE_DIR}, library: ${GLOG_LIBRARY})") | ||
mark_as_advanced(GLOG_ROOT_DIR GLOG_LIBRARY_RELEASE GLOG_LIBRARY_DEBUG | ||
GLOG_LIBRARY GLOG_INCLUDE_DIR) | ||
endif() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
# Finds Google Protocol Buffers library and compilers and extends | ||
# the standard cmake script with version and python generation support | ||
|
||
find_package( Protobuf REQUIRED ) | ||
include_directories(SYSTEM ${PROTOBUF_INCLUDE_DIR}) | ||
list(APPEND pslite_LINKER_LIBS ${PROTOBUF_LIBRARIES}) | ||
|
||
# As of Ubuntu 14.04 protoc is no longer a part of libprotobuf-dev package | ||
# and should be installed separately as in: sudo apt-get install protobuf-compiler | ||
if(EXISTS ${PROTOBUF_PROTOC_EXECUTABLE}) | ||
message(STATUS "Found PROTOBUF Compiler: ${PROTOBUF_PROTOC_EXECUTABLE}") | ||
else() | ||
message(FATAL_ERROR "Could not find PROTOBUF Compiler") | ||
endif() | ||
|
||
|
||
# place where to generate protobuf sources | ||
set(proto_gen_folder "${PROJECT_BINARY_DIR}/include/pslite/proto") | ||
include_directories(SYSTEM "${PROJECT_BINARY_DIR}/include") | ||
|
||
set(PROTOBUF_GENERATE_CPP_APPEND_PATH TRUE) | ||
|
||
################################################################################################ | ||
# Modification of standard 'protobuf_generate_cpp()' with output dir parameter and python support | ||
# Usage: | ||
# pslite_protobuf_generate_cpp_py(<output_dir> <srcs_var> <hdrs_var> <python_var> <proto_files>) | ||
function(pslite_protobuf_generate_cpp_py output_dir srcs_var hdrs_var python_var work_path proto_path) | ||
if(NOT ARGN) | ||
message(SEND_ERROR "Error: pslite_protobuf_generate_cpp_py() called without any proto files") | ||
return() | ||
endif() | ||
|
||
if(PROTOBUF_GENERATE_CPP_APPEND_PATH) | ||
# Create an include path for each file specified | ||
foreach(fil ${ARGN}) | ||
get_filename_component(abs_fil ${fil} ABSOLUTE) | ||
get_filename_component(abs_path ${abs_fil} PATH) | ||
list(FIND _protoc_include ${abs_path} _contains_already) | ||
if(${_contains_already} EQUAL -1) | ||
list(APPEND _protoc_include -I ${abs_path}) | ||
endif() | ||
endforeach() | ||
else() | ||
set(_protoc_include -I ${CMAKE_CURRENT_SOURCE_DIR}) | ||
endif() | ||
|
||
if(DEFINED PROTOBUF_IMPORT_DIRS) | ||
foreach(dir ${PROTOBUF_IMPORT_DIRS}) | ||
get_filename_component(abs_path ${dir} ABSOLUTE) | ||
list(FIND _protoc_include ${abs_path} _contains_already) | ||
if(${_contains_already} EQUAL -1) | ||
list(APPEND _protoc_include -I ${abs_path}) | ||
endif() | ||
endforeach() | ||
endif() | ||
|
||
set(${srcs_var}) | ||
set(${hdrs_var}) | ||
set(${python_var}) | ||
foreach(fil ${ARGN}) | ||
get_filename_component(abs_fil ${fil} ABSOLUTE) | ||
get_filename_component(fil_we ${fil} NAME_WE) | ||
string(REPLACE ${work_path}/ "" o_fil ${abs_fil}) | ||
|
||
list(APPEND ${srcs_var} "${output_dir}/proto/${fil_we}.pb.cc") | ||
list(APPEND ${hdrs_var} "${output_dir}/proto/${fil_we}.pb.h") | ||
list(APPEND ${python_var} "${output_dir}/proto/${fil_we}_pb2.py") | ||
|
||
add_custom_command( | ||
OUTPUT "${output_dir}/proto/${fil_we}.pb.cc" | ||
"${output_dir}/proto/${fil_we}.pb.h" | ||
"${output_dir}/proto/${fil_we}_pb2.py" | ||
COMMAND ${CMAKE_COMMAND} -E make_directory "${output_dir}" | ||
COMMAND ${PROTOBUF_PROTOC_EXECUTABLE} --cpp_out ${output_dir} ${_protoc_include} ${o_fil} --proto_path src | ||
COMMAND ${PROTOBUF_PROTOC_EXECUTABLE} --python_out ${output_dir} ${_protoc_include} ${o_fil} --proto_path src | ||
DEPENDS ${abs_fil} | ||
WORKING_DIRECTORY ${work_path} | ||
COMMENT "Running C++/Python protocol buffer compiler on ${o_fil}" VERBATIM ) | ||
endforeach() | ||
|
||
set_source_files_properties(${${srcs_var}} ${${hdrs_var}} ${${python_var}} PROPERTIES GENERATED TRUE) | ||
set(${srcs_var} ${${srcs_var}} PARENT_SCOPE) | ||
set(${hdrs_var} ${${hdrs_var}} PARENT_SCOPE) | ||
set(${python_var} ${${python_var}} PARENT_SCOPE) | ||
endfunction() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.