diff --git a/BaseLib/CMakeLists.txt b/BaseLib/CMakeLists.txt index 43321431243769b9b4c0a06352b5b5b5fdc8a0a8..59de34e653b48e93e7c86ad14f7b3ae6dafc39c4 100644 --- a/BaseLib/CMakeLists.txt +++ b/BaseLib/CMakeLists.txt @@ -9,4 +9,6 @@ SET_TARGET_PROPERTIES(BaseLib PROPERTIES LINKER_LANGUAGE CXX) INCLUDE_DIRECTORIES( . -) \ No newline at end of file +) + +TARGET_LINK_LIBRARIES( BaseLib ${Boost_LIBRARIES} ) diff --git a/BaseLib/FileTools.cpp b/BaseLib/FileTools.cpp index f5cf869322293755ce5116b13c790cc706c7ae67..5ed8ee7458928156326618b935811972f39e546a 100644 --- a/BaseLib/FileTools.cpp +++ b/BaseLib/FileTools.cpp @@ -16,6 +16,7 @@ #include "StringTools.h" #include <sys/stat.h> +#include <boost/filesystem.hpp> namespace BaseLib { @@ -24,27 +25,10 @@ namespace BaseLib */ bool IsFileExisting(const std::string &strFilename) { - struct stat stFileInfo; - bool blnReturn; - int intStat; - - // Attempt to get the file attributes - intStat = stat(strFilename.c_str(),&stFileInfo); - - if(intStat == 0) - // We were able to get the file attributes - // so the file obviously exists. - blnReturn = true; + if(boost::filesystem::exists(strFilename)) + return true; else - // We were not able to get the file attributes. - // This may mean that we don't have permission to - // access the folder which contains this file. If you - // need to do that level of checking, lookup the - // return values of stat which will give you - // more details on why stat failed. - blnReturn = false; - - return blnReturn; + return false; } /** diff --git a/CMakeLists.txt b/CMakeLists.txt index e706b3a45b5ea9c832ef246941816bd0c9d11c90..384eb58798739aa1409a429cf7fd2b6f9c3b4f15 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,7 +3,7 @@ ##################### # Specify minimum CMake version -CMAKE_MINIMUM_REQUIRED(VERSION 2.8.3) +CMAKE_MINIMUM_REQUIRED(VERSION 2.8.7) # Project name PROJECT( OGS-6 ) @@ -25,10 +25,10 @@ INCLUDE(scripts/cmake/FindIncludeHeader.cmake) INCLUDE(scripts/cmake/Functions.cmake) INCLUDE(scripts/cmake/CMakeSetup.cmake) INCLUDE(scripts/cmake/CompilerSetup.cmake) -INCLUDE(scripts/cmake/SubmoduleSetup.cmake) IF(NOT OGS_NO_EXTERNAL_LIBS) INCLUDE(scripts/cmake/Find.cmake) ENDIF() # NOT OGS_NO_EXTERNAL_LIBS +INCLUDE(scripts/cmake/SubmoduleSetup.cmake) INCLUDE(scripts/cmake/ProjectSetup.cmake) INCLUDE(scripts/cmake/DocumentationSetup.cmake) INCLUDE(scripts/cmake/Test.cmake) @@ -58,6 +58,9 @@ OPTION(OGS_NO_EXTERNAL_LIBS "Builds OGS without any external dependencies." OFF) # Logging OPTION(OGS_DISABLE_LOGGING "Disables all logog messages." OFF) +# Compiler flags +SET(OGS_CXX_FLAGS "" CACHE STRING "Additional C++ compiler flags.") + # Search paths SET(OGS_LIBS_DIR "" CACHE PATH "The path to the compiled third party libs (mainly used for Windows).") @@ -86,6 +89,9 @@ ENDIF() #OGS_PACKAGING ### Subdirectories ### ###################### +# External projects +INCLUDE(scripts/cmake/ExternalProjectBoost.cmake) + # Add subdirectories with the projects ADD_SUBDIRECTORY( ThirdParty ) INCLUDE_DIRECTORIES( ${CMAKE_SOURCE_DIR}/ThirdParty ) @@ -93,6 +99,8 @@ INCLUDE_DIRECTORIES( ${CMAKE_SOURCE_DIR}/ThirdParty/quickcheck ) INCLUDE_DIRECTORIES( ${CMAKE_BINARY_DIR}/ThirdParty/zlib ) ADD_SUBDIRECTORY( BaseLib ) +# TODO This is a hack but we have to make sure that Boost is built first +ADD_DEPENDENCIES(BaseLib Boost) ADD_SUBDIRECTORY( FemLib ) ADD_SUBDIRECTORY( FileIO ) ADD_SUBDIRECTORY( GeoLib ) diff --git a/Gui/DataExplorer.cmake b/Gui/DataExplorer.cmake index 7bcbdc35aff973504887787961e52bb9d19474ea..55e94dca979fe88a8be87be05be09a1df4254695 100644 --- a/Gui/DataExplorer.cmake +++ b/Gui/DataExplorer.cmake @@ -92,6 +92,7 @@ TARGET_LINK_LIBRARIES( ogs-gui vtkRendering vtkWidgets QVTK + ${Boost_LIBRARIES} ) IF(VTK_NETCDF_FOUND) diff --git a/SimpleTests/MeshTests/CMakeLists.txt b/SimpleTests/MeshTests/CMakeLists.txt index 8202a95cec6ca585265118b42f65044e72319204..c52e4972ecd766a8e4305587dd77c20316eb1d63 100644 --- a/SimpleTests/MeshTests/CMakeLists.txt +++ b/SimpleTests/MeshTests/CMakeLists.txt @@ -13,9 +13,9 @@ INCLUDE_DIRECTORIES( # Create the executable ADD_EXECUTABLE( MeshRead - MeshRead.cpp - ${SOURCES} - ${HEADERS} + MeshRead.cpp + ${SOURCES} + ${HEADERS} ) TARGET_LINK_LIBRARIES ( MeshRead @@ -26,13 +26,14 @@ TARGET_LINK_LIBRARIES ( MeshRead GeoLib logog ${ADDITIONAL_LIBS} + ${Boost_LIBRARIES} ) # Create CollapseMeshNodes executable ADD_EXECUTABLE( CollapseMeshNodes - CollapseMeshNodes.cpp - ${SOURCES} - ${HEADERS} + CollapseMeshNodes.cpp + ${SOURCES} + ${HEADERS} ) TARGET_LINK_LIBRARIES ( CollapseMeshNodes @@ -42,13 +43,14 @@ TARGET_LINK_LIBRARIES ( CollapseMeshNodes BaseLib GeoLib logog + ${Boost_LIBRARIES} ) # Create MeshSearchTest executable ADD_EXECUTABLE( MeshSearchTest - MeshSearchTest.cpp - ${SOURCES} - ${HEADERS} + MeshSearchTest.cpp + ${SOURCES} + ${HEADERS} ) TARGET_LINK_LIBRARIES ( MeshSearchTest @@ -59,5 +61,5 @@ TARGET_LINK_LIBRARIES ( MeshSearchTest GeoLib logog ${ADDITIONAL_LIBS} + ${Boost_LIBRARIES} ) - diff --git a/Tests/CMakeLists.txt b/Tests/CMakeLists.txt index 69f73c75decf7cc4fc2b9fb63c03d77db50fdf67..be2627dea1dfa4bc84baf0cd6f7b19a23cbff050 100644 --- a/Tests/CMakeLists.txt +++ b/Tests/CMakeLists.txt @@ -21,6 +21,8 @@ TARGET_LINK_LIBRARIES(testrunner GTest BaseLib GeoLib + ${Boost_LIBRARIES} + ${CMAKE_THREAD_LIBS_INIT} ) # Add make-target test which runs the testrunner diff --git a/scripts/cmake/CMakeSetup.cmake b/scripts/cmake/CMakeSetup.cmake index 99f059df0f98c9a3d75e4f53e920f6196d6994e6..ab831761d831201e9d43b85a7546fd5a1de02d28 100644 --- a/scripts/cmake/CMakeSetup.cmake +++ b/scripts/cmake/CMakeSetup.cmake @@ -8,6 +8,9 @@ INCLUDE(UseBackportedModules) INCLUDE(OptionRequires) INCLUDE(CppcheckTargets) INCLUDE(GetCompilerInfoString) +INCLUDE(ProcessorCount) +ProcessorCount(NUM_PROCESSORS) +SET(NUM_PROCESSORS ${NUM_PROCESSORS} CACHE STRING "Processor count") # Suppress warning on setting policies CMAKE_POLICY(SET CMP0011 OLD) diff --git a/scripts/cmake/CompilerSetup.cmake b/scripts/cmake/CompilerSetup.cmake index bb341268d1a5b36b38d5324a59da719cc74f1fa7..34af36a230b72722891aff9bcc93d32026726e26 100644 --- a/scripts/cmake/CompilerSetup.cmake +++ b/scripts/cmake/CompilerSetup.cmake @@ -6,14 +6,17 @@ INCLUDE(MSVCMultipleProcessCompile) # /MP switch (multi processor) for VS # Set compiler helper variables IF ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") - SET(COMPILER_IS_CLANG 1) -ENDIF () -IF(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_COMPILER_IS_GNUCC) - SET(COMPILER_IS_GCC 1) -ENDIF () -IF (${CMAKE_C_COMPILER} MATCHES "icc.*$" OR ${CMAKE_CXX_COMPILER} MATCHES "icpc.*$") - SET(COMPILER_IS_INTEL) -ENDIF () + SET(COMPILER_IS_CLANG TRUE) +ELSEIF ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") + SET(COMPILER_IS_GCC TRUE) +ELSEIF ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Intel") + SET(COMPILER_IS_INTEL TRUE) +ELSEIF ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC") + SET(COMPILER_IS_MSVC TRUE) +ENDIF () # CMAKE_CXX_COMPILER_ID + +# Set additional user-given compiler flags +SET(CMAKE_CXX_FLAGS ${OGS_CXX_FLAGS}) ### GNU C/CXX compiler IF(COMPILER_IS_GCC) @@ -50,7 +53,7 @@ IF (COMPILER_IS_INTEL) MESSAGE(STATUS "Set Intel release flags") SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3 -DNDEBUG") ENDIF() - SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -xHOST -O3 -no-prec-div -static -DNDEBUG") + SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -xHOST -O3 -no-prec-div -DNDEBUG") ENDIF() # COMPILER_IS_INTEL # Profiling diff --git a/scripts/cmake/ExternalProjectBoost.cmake b/scripts/cmake/ExternalProjectBoost.cmake new file mode 100644 index 0000000000000000000000000000000000000000..df70f9d1e473ffb9f308014090e6ba338c44d6e6 --- /dev/null +++ b/scripts/cmake/ExternalProjectBoost.cmake @@ -0,0 +1,121 @@ +INCLUDE(ExternalProject) +# Set Boost version and which libraries to compile +SET(Boost_Version 1.52.0) +SET(BOOST_LIBS_TO_BUILD + # chrono + # context + date_time + # exception + filesystem + # graph + # graph_parallel + # iostreams + # locale + # math + # mpi + program_options + # python + # random + # regex + # serialization + # signals + system + # test + # thread + # timer + # wave +) + +# First check for system boost +IF(NOT Boost_INCLUDE_DIRS) + SET(Boost_USE_STATIC_LIBS ON) + SET(Boost_USE_STATIC_RUNTIME OFF) + FIND_PACKAGE(Boost 1.48.0 COMPONENTS ${BOOST_LIBS_TO_BUILD}) + IF(Boost_FOUND) + INCLUDE_DIRECTORIES(${Boost_INCLUDE_DIRS}) + RETURN() + ELSE() + SET(Boost_INCLUDE_DIRS "") + ENDIF() +ENDIF() + +# Check required gcc +IF(COMPILER_IS_GCC AND GCC_VERSION VERSION_LESS "4.4") + MESSAGE(FATAL_ERROR "GCC version >= 4.4 is required for building Boost ${Boost_Version}!") +ENDIF() + +# Prefix with --with- for bjam (b2) build command +FOREACH(LIB_TO_BUILD ${BOOST_LIBS_TO_BUILD}) + SET(BOOST_LIBS_TO_BUILD_CMD ${BOOST_LIBS_TO_BUILD_CMD} --with-${LIB_TO_BUILD}) +ENDFOREACH() + +# Prefix with boost_ for library names +FOREACH(LIB_TO_BUILD ${BOOST_LIBS_TO_BUILD}) + SET(BOOST_LIBS_TO_BUILD_NAMES ${BOOST_LIBS_TO_BUILD_NAMES} boost_${LIB_TO_BUILD}) +ENDFOREACH() + +STRING(REPLACE "." "_" Boost_Version_Underscore ${Boost_Version}) + +# Set boost toolset +IF(MSVC10) + SET(BOOST_TOOLSET msvc-10.0) +ELSEIF(MSVC11) + SET(BOOST_TOOLSET msvc-11.0) +ELSEIF(APPLE) + SET(BOOST_TOOLSET darwin) +ELSEIF(COMPILER_IS_CLANG) + SET(BOOST_TOOLSET clang) +ELSEIF(COMPILER_IS_INTEL) + # Extracts first two version numbers, e.g. 13.0 from 13.0.0.20121010 + STRING(REGEX MATCH ^[0-9]*.[0-9] INTEL_COMPILER_VERSION ${CMAKE_CXX_COMPILER_VERSION}) + SET(BOOST_TOOLSET intel-${INTEL_COMPILER_VERSION}) +ELSEIF(COMPILER_IS_GCC) + SET(BOOST_TOOLSET gcc) +ENDIF() + +# Set update command +IF(WIN32) + SET(BOOST_UPDATE_COMMAND bootstrap.bat) +ELSE() + SET(BOOST_UPDATE_COMMAND ./bootstrap.sh) +ENDIF() + +# Set additional config options +SET(BOOST_CONFIG_OPTIONS "") +IF(WIN32) + IF(HAVE_64_BIT) + SET(BOOST_CONFIG_OPTIONS "architecture=x86;address-model=64") + ENDIF() +ENDIF() + +# Set archive sources +SET(BOOST_ARCHIVE_EXT "tar.bz2") +SET(BOOST_ARCHIVE_MD5 3a855e0f919107e0ca4de4d84ad3f750) + +SET(BOOST_URL "http://switch.dl.sourceforge.net/project/boost/boost/${Boost_Version}/boost_${Boost_Version_Underscore}.${BOOST_ARCHIVE_EXT}") + +ExternalProject_Add(Boost + PREFIX ${CMAKE_BINARY_DIR}/External/boost + URL ${BOOST_URL} + URL_MD5 ${BOOST_ARCHIVE_MD5} + UPDATE_COMMAND "${BOOST_UPDATE_COMMAND}" + CONFIGURE_COMMAND "" + BUILD_COMMAND ./b2 ${BOOST_LIBS_TO_BUILD_CMD} -j ${NUM_PROCESSORS} toolset=${BOOST_TOOLSET} link=static stage ${BOOST_CONFIG_OPTIONS} + BUILD_IN_SOURCE 1 + INSTALL_COMMAND "" +) +ExternalProject_Get_Property( Boost source_dir ) + +IF(NOT Boost_INCLUDE_DIRS) + SET( Boost_INCLUDE_DIRS ${source_dir} CACHE INTERNAL "Boost include directories") + # On Visual Studio Boost libs get automatically linked + IF(MSVC) + SET( Boost_LIBRARIES "" CACHE INTERNAL "Boost libraries") + ELSE() + SET( Boost_LIBRARIES ${BOOST_LIBS_TO_BUILD_NAMES} CACHE INTERNAL "Boost libraries") + ENDIF() + MESSAGE(STATUS "Building Boost automatically.") +ENDIF() + +INCLUDE_DIRECTORIES( ${Boost_INCLUDE_DIRS} ) +LINK_DIRECTORIES( ${source_dir}/stage/lib/ ) diff --git a/scripts/cmake/Find.cmake b/scripts/cmake/Find.cmake index 3e06d36ee4e5ed12518594a30d22d5a267bab6e4..4feea6704f4d5ca2c681a5bf9a4e3b3ca65ec3a5 100644 --- a/scripts/cmake/Find.cmake +++ b/scripts/cmake/Find.cmake @@ -29,6 +29,8 @@ FIND_PACKAGE(PythonInterp QUIET) FIND_PACKAGE(GitHub) +FIND_PROGRAM(GIT_TOOL_PATH git HINTS ${GITHUB_BIN_DIR} DOC "The git command line interface") + # Find bash itself ... FIND_PROGRAM(BASH_TOOL_PATH bash HINTS ${GITHUB_BIN_DIR} DOC "The bash executable") diff --git a/scripts/cmake/SubmoduleSetup.cmake b/scripts/cmake/SubmoduleSetup.cmake index b39652a139d4029bd64c270894843e4cead809b1..6acc2a96da39e81dc9c07be6baa0ebcd03e3498d 100644 --- a/scripts/cmake/SubmoduleSetup.cmake +++ b/scripts/cmake/SubmoduleSetup.cmake @@ -16,7 +16,7 @@ FOREACH(SUBMODULE ${REQUIRED_SUBMODULES}) IF(SUBMODULE_STATE EQUAL 1) MESSAGE(STATUS "Initializing submodule ${SUBMODULE}") EXECUTE_PROCESS( - COMMAND git submodule update --init ${SUBMODULE} + COMMAND ${GIT_TOOL_PATH} submodule update --init ${SUBMODULE} WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} ) ELSEIF(SUBMODULE_STATE EQUAL 2)