зеркало из https://github.com/microsoft/LightGBM.git
simplify cmake
This commit is contained in:
Родитель
2cd024e9c6
Коммит
70c31c075d
|
@ -5,23 +5,90 @@ PROJECT(lightgbm)
|
|||
OPTION(USE_MPI "MPI based parallel learning" OFF)
|
||||
|
||||
if(USE_MPI)
|
||||
find_package(MPI REQUIRED)
|
||||
ADD_DEFINITIONS(-DUSE_MPI)
|
||||
MESSAGE(${MPI_LIBRARIES})
|
||||
MESSAGE(${MPI_CXX_LIBRARIES})
|
||||
find_package(MPI REQUIRED)
|
||||
ADD_DEFINITIONS(-DUSE_MPI)
|
||||
MESSAGE(${MPI_LIBRARIES})
|
||||
MESSAGE(${MPI_CXX_LIBRARIES})
|
||||
else()
|
||||
ADD_DEFINITIONS(-DUSE_SOCKET)
|
||||
ADD_DEFINITIONS(-DUSE_SOCKET)
|
||||
endif()
|
||||
|
||||
find_package(OpenMP)
|
||||
|
||||
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
|
||||
|
||||
if(UNIX)
|
||||
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -fopenmp -pthread -O2 -std=c++11")
|
||||
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread -O3 -Wall -std=c++11")
|
||||
endif()
|
||||
|
||||
if(MSVC)
|
||||
if(MSVC_VERSION LESS 1800)
|
||||
message(STATUS "The compiler ${CMAKE_CXX_COMPILER} has no C++11 support. Please use a newer msvc.")
|
||||
endif()
|
||||
|
||||
SET(variables
|
||||
CMAKE_C_FLAGS_DEBUG
|
||||
CMAKE_C_FLAGS_MINSIZEREL
|
||||
CMAKE_C_FLAGS_RELEASE
|
||||
CMAKE_C_FLAGS_RELWITHDEBINFO
|
||||
CMAKE_CXX_FLAGS_DEBUG
|
||||
CMAKE_CXX_FLAGS_MINSIZEREL
|
||||
CMAKE_CXX_FLAGS_RELEASE
|
||||
CMAKE_CXX_FLAGS_RELWITHDEBINFO
|
||||
)
|
||||
foreach(variable ${variables})
|
||||
if(${variable} MATCHES "/MD")
|
||||
string(REGEX REPLACE "/MD" "/MT" ${variable} "${${variable}}")
|
||||
endif()
|
||||
endforeach()
|
||||
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W4 /O2 /Ob2 /Oi /Ot /Oy /GL")
|
||||
else()
|
||||
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC")
|
||||
endif()
|
||||
|
||||
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -fopenmp -O2 -std=c++11")
|
||||
|
||||
SET(LightGBM_HEADER_DIR ${PROJECT_SOURCE_DIR}/include)
|
||||
|
||||
SET(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR})
|
||||
SET(LIBRARY_OUTPUT_PATH ${PROJECT_SOURCE_DIR})
|
||||
|
||||
ADD_SUBDIRECTORY(src)
|
||||
include_directories (${LightGBM_HEADER_DIR})
|
||||
|
||||
if(APPLE)
|
||||
SET(CMAKE_SHARED_LIBRARY_SUFFIX ".so")
|
||||
endif(APPLE)
|
||||
|
||||
if(USE_MPI)
|
||||
include_directories(${MPI_CXX_INCLUDE_PATH})
|
||||
endif()
|
||||
|
||||
file(GLOB SOURCES
|
||||
src/application/*.cpp
|
||||
src/boosting/*.cpp
|
||||
src/io/*.cpp
|
||||
src/metric/*.cpp
|
||||
src/objective/*.cpp
|
||||
src/network/*.cpp
|
||||
src/treelearner/*.cpp
|
||||
)
|
||||
|
||||
add_executable(lightgbm src/main.cpp ${SOURCES})
|
||||
|
||||
add_library(_lightgbm SHARED src/c_api.cpp ${SOURCES})
|
||||
|
||||
if(USE_MPI)
|
||||
TARGET_LINK_LIBRARIES(lightgbm ${MPI_CXX_LIBRARIES})
|
||||
TARGET_LINK_LIBRARIES(_lightgbm ${MPI_CXX_LIBRARIES})
|
||||
endif(USE_MPI)
|
||||
|
||||
if(WIN32)
|
||||
TARGET_LINK_LIBRARIES(lightgbm Ws2_32)
|
||||
TARGET_LINK_LIBRARIES(_lightgbm Ws2_32)
|
||||
TARGET_LINK_LIBRARIES(lightgbm IPHLPAPI)
|
||||
TARGET_LINK_LIBRARIES(_lightgbm IPHLPAPI)
|
||||
endif(WIN32)
|
||||
|
||||
install(TARGETS lightgbm _lightgbm
|
||||
RUNTIME DESTINATION ${CMAKE_INSTALL_PREFIX}/bin
|
||||
LIBRARY DESTINATION ${CMAKE_INSTALL_PREFIX}/lib)
|
||||
install(DIRECTORY ${LightGBM_HEADER_DIR}/LightGBM DESTINATION ${CMAKE_INSTALL_PREFIX}/include)
|
|
@ -158,7 +158,7 @@ public:
|
|||
++cur_sample_cnt;
|
||||
}
|
||||
else {
|
||||
const size_t idx = random.NextInt(0, line_idx + 1);
|
||||
const size_t idx = static_cast<size_t>(random.NextInt(0, line_idx + 1));
|
||||
if (idx < static_cast<size_t>(sample_cnt)) {
|
||||
out_sampled_data->operator[](idx) = std::string(buffer, size);
|
||||
}
|
||||
|
@ -198,7 +198,7 @@ public:
|
|||
++cur_sample_cnt;
|
||||
}
|
||||
else {
|
||||
const size_t idx = random.NextInt(0, out_used_data_indices->size());
|
||||
const size_t idx = static_cast<size_t>(random.NextInt(0, out_used_data_indices->size()));
|
||||
if (idx < static_cast<size_t>(sample_cnt) ) {
|
||||
out_sampled_data->operator[](idx) = std::string(buffer, size);
|
||||
}
|
||||
|
|
|
@ -1,39 +0,0 @@
|
|||
include_directories(${LightGBM_HEADER_DIR})
|
||||
|
||||
if(APPLE)
|
||||
set(CMAKE_SHARED_LIBRARY_SUFFIX ".so")
|
||||
endif(APPLE)
|
||||
|
||||
if(USE_MPI)
|
||||
include_directories(${MPI_CXX_INCLUDE_PATH})
|
||||
endif()
|
||||
|
||||
AUX_SOURCE_DIRECTORY(./application/ APPLICATION_SRC)
|
||||
AUX_SOURCE_DIRECTORY(./boosting/ BOOSTING_SRC)
|
||||
AUX_SOURCE_DIRECTORY(./io/ IO_SRC)
|
||||
AUX_SOURCE_DIRECTORY(./metric/ METRIC_SRC)
|
||||
AUX_SOURCE_DIRECTORY(./objective/ OBJECTIVE_SRC)
|
||||
AUX_SOURCE_DIRECTORY(./network/ NETWORK_SRC)
|
||||
AUX_SOURCE_DIRECTORY(./treelearner/ TREELEARNER_SRC)
|
||||
|
||||
add_executable(lightgbm main.cpp ${APPLICATION_SRC} ${BOOSTING_SRC} ${IO_SRC} ${METRIC_SRC} ${OBJECTIVE_SRC} ${NETWORK_SRC} ${TREELEARNER_SRC})
|
||||
|
||||
add_library(_lightgbm SHARED c_api.cpp ${APPLICATION_SRC} ${BOOSTING_SRC} ${IO_SRC} ${METRIC_SRC} ${OBJECTIVE_SRC} ${NETWORK_SRC} ${TREELEARNER_SRC})
|
||||
|
||||
if(USE_MPI)
|
||||
TARGET_LINK_LIBRARIES(lightgbm ${MPI_CXX_LIBRARIES})
|
||||
TARGET_LINK_LIBRARIES(_lightgbm ${MPI_CXX_LIBRARIES})
|
||||
endif(USE_MPI)
|
||||
|
||||
if(WIN32)
|
||||
TARGET_LINK_LIBRARIES(lightgbm Ws2_32)
|
||||
TARGET_LINK_LIBRARIES(_lightgbm Ws2_32)
|
||||
TARGET_LINK_LIBRARIES(lightgbm IPHLPAPI)
|
||||
TARGET_LINK_LIBRARIES(_lightgbm IPHLPAPI)
|
||||
endif(WIN32)
|
||||
|
||||
install(TARGETS lightgbm _lightgbm
|
||||
RUNTIME DESTINATION ${CMAKE_INSTALL_PREFIX}/bin
|
||||
LIBRARY DESTINATION ${CMAKE_INSTALL_PREFIX}/lib)
|
||||
install(DIRECTORY ${LightGBM_HEADER_DIR}/LightGBM DESTINATION ${CMAKE_INSTALL_PREFIX}/include)
|
||||
|
|
@ -94,6 +94,7 @@
|
|||
<EnableFiberSafeOptimizations>false</EnableFiberSafeOptimizations>
|
||||
<WholeProgramOptimization>false</WholeProgramOptimization>
|
||||
<Optimization>Disabled</Optimization>
|
||||
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<AdditionalLibraryDirectories>
|
||||
|
@ -114,6 +115,7 @@
|
|||
<EnableFiberSafeOptimizations>false</EnableFiberSafeOptimizations>
|
||||
<WholeProgramOptimization>false</WholeProgramOptimization>
|
||||
<Optimization>Disabled</Optimization>
|
||||
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<AdditionalDependencies>
|
||||
|
@ -134,7 +136,7 @@
|
|||
<EnableFiberSafeOptimizations>false</EnableFiberSafeOptimizations>
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
<OmitFramePointers>true</OmitFramePointers>
|
||||
<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
|
||||
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<AdditionalLibraryDirectories>
|
||||
|
@ -157,7 +159,7 @@
|
|||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
<EnableFiberSafeOptimizations>false</EnableFiberSafeOptimizations>
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
|
||||
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
|
||||
<OmitFramePointers>true</OmitFramePointers>
|
||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||
</ClCompile>
|
||||
|
@ -176,7 +178,7 @@
|
|||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
<EnableFiberSafeOptimizations>false</EnableFiberSafeOptimizations>
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
|
||||
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
|
||||
<OmitFramePointers>true</OmitFramePointers>
|
||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||
</ClCompile>
|
||||
|
|
Загрузка…
Ссылка в новой задаче