diff --git a/CMakeLists.txt b/CMakeLists.txt index 4563c8d78a25ee5fa64e4f3edfb56a5fbd9f9787..5df0882825ba2aa83714918bf9c25dc6fdcafa23 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -100,18 +100,11 @@ set(SRC_DIR ${CMAKE_CURRENT_LIST_DIR}/src) set(PROJECT_BINARY_DIR ${CMAKE_CURRENT_LIST_DIR}/build) set(CMAKE_LIBRARY_OUTPUT_DIRECTORY lib) set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY lib) -set(CMAKE_RUNTIME_OUTPUT_DIRECTORY bin) +set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/bin) #----------------------------------------# # Dependencies for the lib4neuro library # #----------------------------------------# -#if(WIN32) -# set(LINK_DEP_LIB4NEURO libboost_serialization libboost_system libboost_random libboost_unit_test libexprtk) -#else() -# set(LINK_DEP_LIB4NEURO boost_serialization boost_system boost_random boost_unit_test exprtk) -#endif() - - message("Running CMake in: ${SRC_DIR} ${PROJECT_BINARY_DIR}") add_subdirectory(${SRC_DIR} ${PROJECT_BINARY_DIR}) diff --git a/FindBoost.cmake b/FindBoost.cmake index a107e68c993745173cba9d7b733fdd2b27e7f6b1..61fc0d8b7589ad483e531296107cf011591b878d 100644 --- a/FindBoost.cmake +++ b/FindBoost.cmake @@ -9,6 +9,10 @@ # * BOOST_LIBRARYDIR - The path to the folder containing Boost libraries # * BOOST_INCLUDEDIR - The path to the folder containing Boost header files +# "External" used variables +# +# * DEPENDENCIES_LINK_TYPE - TODO + # "Output" variables set after running this script # * Boost_FOUND - TODO # * Boost_INCLUDE_DIRS - TODO @@ -53,9 +57,20 @@ if(NOT Boost_INCLUDE_DIRS) endif() # Create a list of requested Boost libraries with "system" names +if(NOT DEPENDENCIES_LINK_TYPE) + message(FATAL_ERROR "Variable DEPENDENCIES_LINK_TYPE is not set! Set it to 'static' or 'shared'.") +endif() + +set(LIB_SUFFIX "a") +if("${DEPENDENCIES_LINK_TYPE}" STREQUAL "shared" AND WIN32) + set(LIB_SUFFIX "dll") +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 "libboost_${COMPONENT}.a") + list(APPEND REQUESTED_BOOST_LIBS "libboost_${COMPONENT}.${LIB_SUFFIX}") endforeach() # Look for libraries specified by COMPONENTS flag diff --git a/build.sh b/build.sh index e706a3256a2cb35dd7f2801b290a7e056ddb610c..414ccae2779715ac69c0761edc2e9b821679e420 100755 --- a/build.sh +++ b/build.sh @@ -10,6 +10,7 @@ BUILD_TESTS=yes BUILD_EXAMPLES=yes BUILD_LIB=yes +DEPENDENCIES_LINK_TYPE=shared # shared/static # Build type (Release/Debug) BUILD_TYPE=Debug @@ -31,5 +32,5 @@ $(pwd)/clean.sh git submodule init git submodule update --remote -cmake -DCMAKE_VERBOSE_MAKEFILE:BOOL=ON -DCMAKE_BUILD_TYPE=${BUILD_TYPE} -DCMAKE_CXX_COMPILER=${CXX_COMPILER} -DCMAKE_C_COMPILER=${C_COMPILER} -DBUILD_TESTS=${BUILD_TESTS} -DBUILD_EXAMPLES=${BUILD_EXAMPLES} -DBUILD_LIB=${BUILD_LIB} -DLIB4NEURO_DIR=$(pwd)/build/lib . +cmake -DCMAKE_VERBOSE_MAKEFILE:BOOL=ON -DCMAKE_BUILD_TYPE=${BUILD_TYPE} -DCMAKE_CXX_COMPILER=${CXX_COMPILER} -DCMAKE_C_COMPILER=${C_COMPILER} -DBUILD_TESTS=${BUILD_TESTS} -DBUILD_EXAMPLES=${BUILD_EXAMPLES} -DBUILD_LIB=${BUILD_LIB} -DLIB4NEURO_DIR=$(pwd)/build/lib -DDEPENDENCIES_LINK_TYPE=${DEPENDENCIES_LINK_TYPE} . cmake --build . --config ${BUILD_TYPE} -- -j${N_CORES} && (tput setaf 2; echo "Build complete."; echo "For examples have a look at the folder build/bin/examples."; tput sgr 0; ) || (tput setaf 1; echo "Build finished with errors!"; tput sgr 0; exit 1;) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index fa0f5d24355cd487a354fda3a8657d880b3ec94c..7673af5eea326613593e270c3e3d52e7a438e1cd 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -29,16 +29,22 @@ if ("${BUILD_LIB}" STREQUAL "yes") PROPERTIES INCLUDE_DIRECTORIES "${ROOT_DIR}/include;${SRC_DIR};${Boost_INCLUDE_DIRS}" LINK_LIBRARIES "${BOOST_LIBRARIES}" + ARCHIVE_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/lib" + LIBRARY_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/lib" + RUNTIME_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/bin" ) - if(WIN32) + if(WIN32 AND "${DEPENDENCIES_LINK_TYPE}" STREQUAL "static") add_library(libboost_unit_test STATIC boost_test_lib_dummy.cpp) add_library(libexprtk STATIC exprtk.cpp) - #target_link_libraries(lib4neuro ${LINK_DEP_LIB4NEURO}) - else() + elseif(WIN32 AND "${DEPENDENCIES_LINK_TYPE}" STREQUAL "static") + message(FATAL_ERROR "Only static linking of external dependencies is supported for Windows systems now!") + elseif("${DEPENDENCIES_LINK_TYPE}" STREQUAL "static") add_library(boost_unit_test STATIC boost_test_lib_dummy.cpp) add_library(exprtk STATIC exprtk.cpp) - #target_link_libraries(lib4neuro ${LINK_DEP_LIB4NEURO}) + elseif("${DEPENDENCIES_LINK_TYPE}" STREQUAL "shared") + add_library(boost_unit_test SHARED boost_test_lib_dummy.cpp) + add_library(exprtk SHARED exprtk.cpp) endif() endif () diff --git a/src/examples/CMakeLists.txt b/src/examples/CMakeLists.txt index c53079c7f76ee25e298598d93f3a07d918d1ce8a..3ce77689f4652beec75efe93e0d6ef5ba239abf9 100644 --- a/src/examples/CMakeLists.txt +++ b/src/examples/CMakeLists.txt @@ -22,4 +22,7 @@ set_target_properties( PROPERTIES INCLUDE_DIRECTORIES "${ROOT_DIR}/include" LINK_LIBRARIES "lib4neuro" + ARCHIVE_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/lib/" + LIBRARY_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/lib" + RUNTIME_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/bin/examples" ) diff --git a/src/tests/CMakeLists.txt b/src/tests/CMakeLists.txt index 61b57ad30a10c2d7e47579d5c77e4f53f7a34b5e..0942bfedb6442b9aafa77d4e3418e25384d8d36e 100644 --- a/src/tests/CMakeLists.txt +++ b/src/tests/CMakeLists.txt @@ -34,5 +34,8 @@ set_target_properties( PROPERTIES INCLUDE_DIRECTORIES "${ROOT_DIR}/include;${SRC_DIR};${Boost_INCLUDE_DIRS}" LINK_LIBRARIES "lib4neuro;boost_unit_test;${BOOST_LIBRARIES}" + ARCHIVE_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/lib" + LIBRARY_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/lib" + RUNTIME_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/bin/tests" )