Skip to content

Commit

Permalink
Update cpp-api example
Browse files Browse the repository at this point in the history
  • Loading branch information
cyang-kth committed Dec 4, 2020
1 parent cdcda9a commit 12cf08e
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 2 deletions.
55 changes: 54 additions & 1 deletion example/cpp-api/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,47 @@ set(CMAKE_CXX_STANDARD 11)

list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake")

set(CMAKE_BUILD_TYPE "Release")
set(CMAKE_CXX_FLAGS "-O3 -DSPDLOG_ACTIVE_LEVEL=SPDLOG_LEVEL_TRACE")
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/build")

list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")

find_package(Conda)
if(CONDA_PREFIX)
message(STATUS "Set CONDA_PREFIX ${CONDA_PREFIX}")
set(CMAKE_PREFIX_PATH ${CMAKE_PREFIX_PATH} ${CONDA_PREFIX})
else()
message(STATUS "Non conda exist, search library in default path")
endif()

find_package(GDAL 2.2 REQUIRED)
if (GDAL_FOUND)
message(STATUS "GDAL headers found at ${GDAL_INCLUDE_DIR}")
message(STATUS "GDAL library found at ${GDAL_LIBRARIES}")
include_directories(${GDAL_INCLUDE_DIR})
else()
message(FATAL_ERROR "GDAL Not Found!")
endif (GDAL_FOUND)

find_package(Boost 1.56.0 REQUIRED serialization)
if (Boost_FOUND)
message(STATUS "Boost headers found at ${Boost_INCLUDE_DIR}")
message(STATUS "Boost library found at ${Boost_LIBRARIES}")
message(STATUS "Boost library version ${Boost_LIB_VERSION}")
else()
message(FATAL_ERROR "Boost Not Found!")
endif (Boost_FOUND)

find_package(OpenMP REQUIRED)
if(OPENMP_FOUND)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
message(STATUS "OpenMP_HEADERS found at ${OpenMP_CXX_INCLUDE_DIRS}")
message(STATUS "OpenMP_CXX_LIBRARIES found at ${OpenMP_CXX_LIBRARIES}")
endif()

find_package(FMM REQUIRED)
if (FMM_FOUND)
message(STATUS "FMM headers found at ${FMM_INCLUDE_DIR}")
Expand All @@ -17,7 +58,19 @@ else()
message(FATAL_ERROR "FMM Not Found!")
endif (FMM_FOUND)

### Set RPATH properties

set(CMAKE_SKIP_BUILD_RPATH FALSE)

set(CMAKE_BUILD_WITH_INSTALL_RPATH FALSE)

set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib")

set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)

add_executable(fmm_print_network main.cpp)
target_link_libraries(fmm_print_network ${FMM_LIBRARY})
target_link_libraries(fmm_print_network
${FMM_LIBRARY} ${GDAL_LIBRARIES} ${Boost_LIBRARIES}
${OpenMP_CXX_LIBRARIES})

install(TARGETS fmm_print_network DESTINATION bin)
24 changes: 24 additions & 0 deletions example/cpp-api/cmake/FindConda.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
if(DEFINED ENV{CONDA_PREFIX})
set(CONDA_PREFIX $ENV{CONDA_PREFIX} CACHE PATH "")
else()
# Assuming the active conda environment is on PATH, this finds the path of bin/ in the environment
find_program(CONDA_EXECUTABLE conda
PATHS ${CONDA_PREFIX}/bin ${CONDA_PREFIX}/Scripts ENV PATH
)
if(CONDA_EXECUTABLE)
execute_process(COMMAND ${CONDA_EXECUTABLE} info --root
OUTPUT_VARIABLE out_var
OUTPUT_STRIP_TRAILING_WHITESPACE
)
execute_process(COMMAND ${CONDA_EXECUTABLE} info --envs
)
else()
message(STATUS "\nNo conda environment found in PATH!\nPATH=$ENV{PATH}\n")
endif()
set(CONDA_PREFIX ${out_var})
endif()

include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(Conda
REQUIRED_VARS CONDA_PREFIX
)
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ else ()
endif ()

if (NOT FMM_LIBRARY)
find_library(FMM_LIBRARY NAMES fmmlib NAMES_PER_DIR PATH_SUFFIXES lib)
find_library(FMM_LIBRARY NAMES FMMLIB PATH_SUFFIXES lib)
else ()
file(TO_CMAKE_PATH "${FMM_LIBRARY}" FMM_LIBRARY)
endif ()
Expand Down

0 comments on commit 12cf08e

Please sign in to comment.