diff --git a/example/cpp-api/CMakeLists.txt b/example/cpp-api/CMakeLists.txt index 4f914ab..4ed45e0 100644 --- a/example/cpp-api/CMakeLists.txt +++ b/example/cpp-api/CMakeLists.txt @@ -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}") @@ -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) diff --git a/example/cpp-api/cmake/FindConda.cmake b/example/cpp-api/cmake/FindConda.cmake new file mode 100644 index 0000000..c36b449 --- /dev/null +++ b/example/cpp-api/cmake/FindConda.cmake @@ -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 + ) diff --git a/example/cpp-api/cmake/findFMM.cmake b/example/cpp-api/cmake/FindFMM.cmake similarity index 85% rename from example/cpp-api/cmake/findFMM.cmake rename to example/cpp-api/cmake/FindFMM.cmake index bfba622..7d157b9 100644 --- a/example/cpp-api/cmake/findFMM.cmake +++ b/example/cpp-api/cmake/FindFMM.cmake @@ -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 ()