From b41ec5b91f2f877d8a96f067b667aa0db65d236a Mon Sep 17 00:00:00 2001 From: Martin Beseda <martin.beseda@vsb.cz> Date: Tue, 19 Feb 2019 02:21:47 +0100 Subject: [PATCH] FIX: Trying to fix Armadillo Find module --- CMakeLists.txt | 14 ++++++++++ DownloadArmadillo.cmake | 6 ++--- FindArmadillo.cmake | 42 ++++++++++++++++++++++-------- FindBoost.cmake | 11 -------- src/ErrorFunction/ErrorFunctions.h | 2 +- 5 files changed, 49 insertions(+), 26 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index e1a07f01..c8df4000 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -86,6 +86,20 @@ if(N_CORES GREATER 1) endif() message("Build will be performed on ${N_CORES} cores.") +#----------------------------------------# +# Set prefixes and suffixes of libraries # +#----------------------------------------# +set(LIB_PREFIX "lib") +set(LIB_SUFFIX "a") # suffix for Linux static libraries +if("${DEPENDENCIES_LINK_TYPE}" STREQUAL "shared" AND WIN32) + set(LIB_PREFIX "") + set(LIB_SUFFIX "dll") +elseif("${DEPENDENCIES_LINK_TYPE}" STREQUAL "static" AND WIN32) + set(LIB_SUFFIX "lib") +elseif("${DEPENDENCIES_LINK_TYPE}" STREQUAL "shared") + set(LIB_SUFFIX "so") +endif() + #-------------------------# # Find external libraries # #-------------------------# diff --git a/DownloadArmadillo.cmake b/DownloadArmadillo.cmake index f03b9843..89e94435 100644 --- a/DownloadArmadillo.cmake +++ b/DownloadArmadillo.cmake @@ -2,9 +2,9 @@ set(ARMADILLO_LOCAL_PATH ${CMAKE_CURRENT_LIST_DIR}/external_dependencies/armadil include(FetchContent) -################### -# Download exprtk # -################### +###################### +# Download Armadillo # +###################### FetchContent_Declare( armadillo SOURCE_DIR ${ARMADILLO_LOCAL_PATH} diff --git a/FindArmadillo.cmake b/FindArmadillo.cmake index 37c55872..ff8c0dc9 100644 --- a/FindArmadillo.cmake +++ b/FindArmadillo.cmake @@ -1,6 +1,6 @@ message("FindArmadillo starting...") -# Find headers and libraries +# Find headers FIND_PATH( ARMADILLO_INCLUDE_DIR @@ -23,29 +23,49 @@ FIND_PATH( armadillo include/armadillo ) -# Set TURTLE_FOUND honoring the QUIET and REQUIRED arguments + +# Find library +set(LIBNAME ${LIB_PREFIX}armadillo.so) +message(${LIBNAME}) +FIND_LIBRARY( + ARMADILLO_LIBRARY_DIR + + NAMES + ${LIBNAME} + + HINTS + external_dependencies/armadillo + + PATHS + /usr/lib + /usr/local/lib +) + +# Set ARMADILLO_FOUND honoring the QUIET and REQUIRED arguments INCLUDE(FindPackageHandleStandardArgs) FIND_PACKAGE_HANDLE_STANDARD_ARGS( armadillo "Armadillo was NOT found!" - ARMADILLO_INCLUDE_DIR) + ARMADILLO_INCLUDE_DIR + ARMADILLO_LIBRARY_DIR) # Output variables IF(ARMADILLO_FOUND) # Include dirs SET(ARMADILLO_INCLUDE_DIRS ${ARMADILLO_INCLUDE_DIR}) - set(TMP "") - string(REGEX REPLACE "/include" "" TMP ${ARMADILLO_INCLUDE_DIR}) - add_subdirectory(${TMP} ${TMP}) + # If Armadillo is downloaded as a source code, add it to the project, so the library will be compiled + # automatically + IF(${ARMADILLO_INCLUDE_DIR} MATCHES "^.*external_dependencies.*$") + set(TMP "") + string(REGEX REPLACE "/include" "" TMP ${ARMADILLO_INCLUDE_DIR}) + add_subdirectory(${TMP} ${TMP}) + ENDIF() message("Armadillo was successfully found.") ENDIF() -# Add path only to the 'include' folder -#set(TMP "") -#string(REGEX REPLACE "/turtle$" "" TMP ${TURTLE_INCLUDE_DIR}) -#list(APPEND TURTLE_INCLUDE_DIR ${TMP}) - # Advanced options for not cluttering the cmake UIs: MARK_AS_ADVANCED(ARMADILLO_INCLUDE_DIR) +MARK_AS_ADVANCED(ARMADILLO_LIBRARY_DIR) + diff --git a/FindBoost.cmake b/FindBoost.cmake index 31093241..e23824b3 100644 --- a/FindBoost.cmake +++ b/FindBoost.cmake @@ -74,17 +74,6 @@ if(NOT DEPENDENCIES_LINK_TYPE) message(FATAL_ERROR "Variable DEPENDENCIES_LINK_TYPE is not set! Set it to 'static' or 'shared'.") endif() -set(LIB_PREFIX "lib") -set(LIB_SUFFIX "a") # suffix for Linux static libraries -if("${DEPENDENCIES_LINK_TYPE}" STREQUAL "shared" AND WIN32) - set(LIB_PREFIX "") - set(LIB_SUFFIX "dll") -elseif("${DEPENDENCIES_LINK_TYPE}" STREQUAL "static" AND WIN32) - set(LIB_SUFFIX "lib") -elseif("${DEPENDENCIES_LINK_TYPE}" STREQUAL "shared") - set(LIB_SUFFIX "so") -endif() - set(REQUESTED_BOOST_LIBS "") foreach(COMPONENT ${Boost_FIND_COMPONENTS}) list(APPEND REQUESTED_BOOST_LIBS "${LIB_PREFIX}boost_${COMPONENT}.${LIB_SUFFIX}") diff --git a/src/ErrorFunction/ErrorFunctions.h b/src/ErrorFunction/ErrorFunctions.h index a8de7298..2a5d556c 100644 --- a/src/ErrorFunction/ErrorFunctions.h +++ b/src/ErrorFunction/ErrorFunctions.h @@ -171,7 +171,7 @@ namespace lib4neuro { */ DataSet* ds_test = nullptr; }; - + class MSE : public ErrorFunction{ public: -- GitLab