fix the problem that there is no libxgboost.dll (#1674)

fix the problem that there is no libxgboost.dll built with Visual Studio.
This commit is contained in:
EQGM 2016-10-19 00:56:48 +08:00 committed by Tianqi Chen
parent 4b9d488387
commit d3fc815b45

View File

@ -1,82 +1,90 @@
cmake_minimum_required (VERSION 2.6) cmake_minimum_required (VERSION 2.6)
project (xgboost) project (xgboost)
find_package(OpenMP) find_package(OpenMP)
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS} -fPIC") set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS} -fPIC")
# Make sure we are using C++11 # Make sure we are using C++11
# Visual Studio 12.0 and newer supports enough c++11 to make this work # Visual Studio 12.0 and newer supports enough c++11 to make this work
if(MSVC) if(MSVC)
if(MSVC_VERSION LESS 1800) if(MSVC_VERSION LESS 1800)
message(STATUS "The compiler ${CMAKE_CXX_COMPILER} has no C++11 support. Please use a different C++ compiler.") message(STATUS "The compiler ${CMAKE_CXX_COMPILER} has no C++11 support. Please use a different C++ compiler.")
endif() endif()
else() else()
# GCC 4.6 with c++0x supports enough to make this work # GCC 4.6 with c++0x supports enough to make this work
include(CheckCXXCompilerFlag) include(CheckCXXCompilerFlag)
CHECK_CXX_COMPILER_FLAG("-std=c++11" COMPILER_SUPPORTS_CXX11) CHECK_CXX_COMPILER_FLAG("-std=c++11" COMPILER_SUPPORTS_CXX11)
CHECK_CXX_COMPILER_FLAG("-std=c++0x" COMPILER_SUPPORTS_CXX0X) CHECK_CXX_COMPILER_FLAG("-std=c++0x" COMPILER_SUPPORTS_CXX0X)
if(COMPILER_SUPPORTS_CXX11) if(COMPILER_SUPPORTS_CXX11)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
elseif(COMPILER_SUPPORTS_CXX0X) elseif(COMPILER_SUPPORTS_CXX0X)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x")
else() else()
message(STATUS "The compiler ${CMAKE_CXX_COMPILER} has no C++11 support. Please use a different C++ compiler.") message(STATUS "The compiler ${CMAKE_CXX_COMPILER} has no C++11 support. Please use a different C++ compiler.")
endif() endif()
endif() endif()
#Make sure we are using the static runtime #Make sure we are using the static runtime
if(MSVC) if(MSVC)
set(variables set(variables
CMAKE_C_FLAGS_DEBUG CMAKE_C_FLAGS_DEBUG
CMAKE_C_FLAGS_MINSIZEREL CMAKE_C_FLAGS_MINSIZEREL
CMAKE_C_FLAGS_RELEASE CMAKE_C_FLAGS_RELEASE
CMAKE_C_FLAGS_RELWITHDEBINFO CMAKE_C_FLAGS_RELWITHDEBINFO
CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_DEBUG
CMAKE_CXX_FLAGS_MINSIZEREL CMAKE_CXX_FLAGS_MINSIZEREL
CMAKE_CXX_FLAGS_RELEASE CMAKE_CXX_FLAGS_RELEASE
CMAKE_CXX_FLAGS_RELWITHDEBINFO CMAKE_CXX_FLAGS_RELWITHDEBINFO
) )
foreach(variable ${variables}) foreach(variable ${variables})
if(${variable} MATCHES "/MD") if(${variable} MATCHES "/MD")
string(REGEX REPLACE "/MD" "/MT" ${variable} "${${variable}}") string(REGEX REPLACE "/MD" "/MT" ${variable} "${${variable}}")
endif() endif()
endforeach() endforeach()
endif() endif()
include_directories ( include_directories (
${PROJECT_SOURCE_DIR}/include ${PROJECT_SOURCE_DIR}/include
${PROJECT_SOURCE_DIR}/dmlc-core/include ${PROJECT_SOURCE_DIR}/dmlc-core/include
${PROJECT_SOURCE_DIR}/rabit/include ${PROJECT_SOURCE_DIR}/rabit/include
) )
file(GLOB SOURCES file(GLOB SOURCES
src/c_api/*.cc src/c_api/*.cc
src/common/*.cc src/common/*.cc
src/data/*.cc src/data/*.cc
src/gbm/*.cc src/gbm/*.cc
src/metric/*.cc src/metric/*.cc
src/objective/*.cc src/objective/*.cc
src/tree/*.cc src/tree/*.cc
src/*.cc src/*.cc
) )
set(RABIT_SOURCES set(RABIT_SOURCES
rabit/src/allreduce_base.cc rabit/src/allreduce_base.cc
rabit/src/allreduce_robust.cc rabit/src/allreduce_robust.cc
rabit/src/engine.cc rabit/src/engine.cc
rabit/src/c_api.cc rabit/src/c_api.cc
) )
add_subdirectory(dmlc-core) add_subdirectory(dmlc-core)
add_library(rabit STATIC ${RABIT_SOURCES}) add_library(rabit STATIC ${RABIT_SOURCES})
add_executable(xgboost-bin ${SOURCES}) if(MSVC)
SET_TARGET_PROPERTIES(xgboost-bin PROPERTIES OUTPUT_NAME xgboost) add_executable(xgboost ${SOURCES})
add_library(xgboost SHARED ${SOURCES}) add_library(libxgboost SHARED ${SOURCES})
target_link_libraries(xgboost-bin dmlccore rabit) target_link_libraries(xgboost dmlccore rabit)
target_link_libraries(xgboost dmlccore rabit) target_link_libraries(libxgboost dmlccore rabit)
else()
add_executable(xgboost-bin ${SOURCES})
SET_TARGET_PROPERTIES(xgboost-bin PROPERTIES OUTPUT_NAME xgboost)
add_library(xgboost SHARED ${SOURCES})
target_link_libraries(xgboost-bin dmlccore rabit)
target_link_libraries(xgboost dmlccore rabit)
endif()