diff --git a/CMakeLists.txt b/CMakeLists.txt --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -9,6 +9,15 @@ INCLUDE(FindDoxygen) INCLUDE(FindGhostscript) +FIND_PACKAGE(GLPK 4.33) + +ADD_DEFINITIONS(-DHAVE_CONFIG_H) + +IF(GLPK_FOUND) + SET(HAVE_LP TRUE) + SET(HAVE_MIP TRUE) + SET(HAVE_GLPK TRUE) +ENDIF(GLPK_FOUND) ENABLE_TESTING() diff --git a/cmake/FindGLPK.cmake b/cmake/FindGLPK.cmake new file mode 100644 --- /dev/null +++ b/cmake/FindGLPK.cmake @@ -0,0 +1,20 @@ +SET(GLPK_REGKEY "[HKEY_LOCAL_MACHINE\\SOFTWARE\\GnuWin32\\Glpk;InstallPath]") +GET_FILENAME_COMPONENT(GLPK_ROOT_PATH ${GLPK_REGKEY} ABSOLUTE) + +FIND_PATH(GLPK_INCLUDE_DIR + glpk.h + PATHS ${GLPK_REGKEY}/include) + +FIND_LIBRARY(GLPK_LIBRARY + NAMES glpk + PATHS ${GLPK_REGKEY}/lib) + +INCLUDE(FindPackageHandleStandardArgs) +FIND_PACKAGE_HANDLE_STANDARD_ARGS(GLPK DEFAULT_MSG GLPK_LIBRARY GLPK_INCLUDE_DIR) + +IF(GLPK_FOUND) + SET(GLPK_LIBRARIES ${GLPK_LIBRARY}) + SET(GLPK_BIN_DIR ${GLPK_ROOT_PATH}/bin) +ENDIF(GLPK_FOUND) + +MARK_AS_ADVANCED(GLPK_LIBRARY GLPK_INCLUDE_DIR GLPK_BIN_DIR) diff --git a/demo/CMakeLists.txt b/demo/CMakeLists.txt --- a/demo/CMakeLists.txt +++ b/demo/CMakeLists.txt @@ -1,4 +1,8 @@ -INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}) +INCLUDE_DIRECTORIES( + ${CMAKE_SOURCE_DIR} + ${CMAKE_BINARY_DIR} + ${GLPK_INCLUDE_DIR} +) LINK_DIRECTORIES(${CMAKE_BINARY_DIR}/lemon) diff --git a/lemon/CMakeLists.txt b/lemon/CMakeLists.txt --- a/lemon/CMakeLists.txt +++ b/lemon/CMakeLists.txt @@ -1,11 +1,28 @@ -INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}) +INCLUDE_DIRECTORIES( + ${CMAKE_SOURCE_DIR} + ${CMAKE_BINARY_DIR} + ${GLPK_INCLUDE_DIR} +) -ADD_LIBRARY(lemon +CONFIGURE_FILE( + ${CMAKE_CURRENT_SOURCE_DIR}/config.h.cmake + ${CMAKE_CURRENT_BINARY_DIR}/config.h +) + +SET(LEMON_SOURCES arg_parser.cc base.cc color.cc + lp_base.cc + lp_skeleton.cc random.cc) +IF(HAVE_GLPK) + SET(LEMON_SOURCES ${LEMON_SOURCES} glpk.cc) +ENDIF(HAVE_GLPK) + +ADD_LIBRARY(lemon ${LEMON_SOURCES}) + INSTALL( TARGETS lemon ARCHIVE DESTINATION lib @@ -16,3 +33,9 @@ DESTINATION include/lemon COMPONENT headers FILES_MATCHING PATTERN "*.h") + +IF(WIN32) + INSTALL(FILES ${GLPK_BIN_DIR}/glpk.dll DESTINATION bin) + INSTALL(FILES ${GLPK_BIN_DIR}/libltdl3.dll DESTINATION bin) + INSTALL(FILES ${GLPK_BIN_DIR}/zlib1.dll DESTINATION bin) +ENDIF(WIN32) diff --git a/lemon/config.h.cmake b/lemon/config.h.cmake new file mode 100644 --- /dev/null +++ b/lemon/config.h.cmake @@ -0,0 +1,3 @@ +#cmakedefine HAVE_LP 1 +#cmakedefine HAVE_MIP 1 +#cmakedefine HAVE_GLPK 1 diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -1,4 +1,8 @@ -INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}) +INCLUDE_DIRECTORIES( + ${CMAKE_SOURCE_DIR} + ${CMAKE_BINARY_DIR} + ${GLPK_INCLUDE_DIR} +) LINK_DIRECTORIES(${CMAKE_BINARY_DIR}/lemon) @@ -11,26 +15,56 @@ digraph_test dijkstra_test dim_test + edge_set_test error_test - edge_set_test graph_copy_test graph_test graph_utils_test hao_orlin_test heap_test kruskal_test - lp_test - mip_test maps_test max_matching_test - radix_sort_test path_test preflow_test + radix_sort_test random_test suurballe_test time_measure_test unionfind_test) +IF(HAVE_LP) + ADD_EXECUTABLE(lp_test lp_test.cc) + TARGET_LINK_LIBRARIES(lp_test lemon ${GLPK_LIBRARIES}) + ADD_TEST(lp_test lp_test) + + IF(WIN32) + GET_TARGET_PROPERTY(TARGET_LOC lp_test LOCATION) + GET_FILENAME_COMPONENT(TARGET_PATH ${TARGET_LOC} PATH) + ADD_CUSTOM_COMMAND(TARGET lp_test POST_BUILD + COMMAND cmake -E copy ${GLPK_BIN_DIR}/glpk.dll ${TARGET_PATH} + COMMAND cmake -E copy ${GLPK_BIN_DIR}/libltdl3.dll ${TARGET_PATH} + COMMAND cmake -E copy ${GLPK_BIN_DIR}/zlib1.dll ${TARGET_PATH} + ) + ENDIF(WIN32) +ENDIF(HAVE_LP) + +IF(HAVE_MIP) + ADD_EXECUTABLE(mip_test mip_test.cc) + TARGET_LINK_LIBRARIES(mip_test lemon ${GLPK_LIBRARIES}) + ADD_TEST(mip_test mip_test) + + IF(WIN32) + GET_TARGET_PROPERTY(TARGET_LOC mip_test LOCATION) + GET_FILENAME_COMPONENT(TARGET_PATH ${TARGET_LOC} PATH) + ADD_CUSTOM_COMMAND(TARGET mip_test POST_BUILD + COMMAND cmake -E copy ${GLPK_BIN_DIR}/glpk.dll ${TARGET_PATH} + COMMAND cmake -E copy ${GLPK_BIN_DIR}/libltdl3.dll ${TARGET_PATH} + COMMAND cmake -E copy ${GLPK_BIN_DIR}/zlib1.dll ${TARGET_PATH} + ) + ENDIF(WIN32) +ENDIF(HAVE_MIP) + FOREACH(TEST_NAME ${TESTS}) ADD_EXECUTABLE(${TEST_NAME} ${TEST_NAME}.cc) TARGET_LINK_LIBRARIES(${TEST_NAME} lemon)