diff --git a/CMakeLists.txt b/CMakeLists.txt index fe7553ced..1b4c2f909 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -20,51 +20,66 @@ endif (MSVC) include_directories(Program) -# Build Executable -add_executable(bin - Program/main.cpp - ${src_files}) +# object to be used by both static and shared (compile only once) +add_library(objlib OBJECT ${src_files}) +set_property(TARGET objlib PROPERTY POSITION_INDEPENDENT_CODE 1) -set_target_properties(bin PROPERTIES OUTPUT_NAME hgs) +# runtime library +add_library(lib SHARED $) +set_target_properties(lib PROPERTIES OUTPUT_NAME hgscvrp) -# Test Executable -include(CTest) -add_test(NAME bin_test_X-n101-k25 - COMMAND ${CMAKE_COMMAND} -DINSTANCE=X-n101-k25 - -DCOST=27591 - -DROUND=1 - -P ${CMAKE_CURRENT_SOURCE_DIR}/Test/TestExecutable.cmake) -add_test(NAME bin_test_X-n106-k14 - COMMAND ${CMAKE_COMMAND} -DINSTANCE=X-n110-k13 - -DCOST=14971 - -DROUND=1 - -P ${CMAKE_CURRENT_SOURCE_DIR}/Test/TestExecutable.cmake) +if(CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR) + # We're in the root, build everything + # static library + add_library(lib_static STATIC $) + # if static and runtime libraries use name "hgscvrp", MSVC will overwrite one + # of them, because both STATIC and SHARED builds create "hgscvrp.lib" + set_target_properties(lib_static PROPERTIES OUTPUT_NAME hgscvrp_static) -# Test Executable: Instances with Duration, without Rounding -add_test(NAME bin_test_CMT6 - COMMAND ${CMAKE_COMMAND} -DINSTANCE=CMT6 - -DCOST=555.43 - -DROUND=0 - -P ${CMAKE_CURRENT_SOURCE_DIR}/Test/TestExecutable.cmake) -add_test(NAME bin_test_CMT7 - COMMAND ${CMAKE_COMMAND} -DINSTANCE=CMT7 - -DCOST=909.675 - -DROUND=0 - -P ${CMAKE_CURRENT_SOURCE_DIR}/Test/TestExecutable.cmake) + # Build Executable -# Build Library -add_library(lib SHARED ${src_files}) -set_target_properties(lib PROPERTIES OUTPUT_NAME hgscvrp) + add_executable(bin Program/main.cpp) + target_link_libraries(bin PRIVATE lib_static) + set_target_properties(bin PROPERTIES OUTPUT_NAME hgs) + + + # Test Executable + + include(CTest) + add_test(NAME bin_test_X-n101-k25 + COMMAND ${CMAKE_COMMAND} -DINSTANCE=X-n101-k25 + -DCOST=27591 + -DROUND=1 + -P ${PROJECT_SOURCE_DIR}/Test/TestExecutable.cmake) + add_test(NAME bin_test_X-n106-k14 + COMMAND ${CMAKE_COMMAND} -DINSTANCE=X-n110-k13 + -DCOST=14971 + -DROUND=1 + -P ${PROJECT_SOURCE_DIR}/Test/TestExecutable.cmake) + + # Test Executable: Instances with Duration, without Rounding + add_test(NAME bin_test_CMT6 + COMMAND ${CMAKE_COMMAND} -DINSTANCE=CMT6 + -DCOST=555.43 + -DROUND=0 + -P ${PROJECT_SOURCE_DIR}/Test/TestExecutable.cmake) + add_test(NAME bin_test_CMT7 + COMMAND ${CMAKE_COMMAND} -DINSTANCE=CMT7 + -DCOST=909.675 + -DROUND=0 + -P ${PROJECT_SOURCE_DIR}/Test/TestExecutable.cmake) + + # Test Library + add_subdirectory(Test/Test-c/) + add_test(NAME lib_test_c + COMMAND lib_test_c) -# Test Library -add_subdirectory(Test/Test-c/) -add_test(NAME lib_test_c - COMMAND lib_test_c) + # Install + install(TARGETS lib + DESTINATION lib) + install(TARGETS bin + DESTINATION bin) + install(FILES Program/AlgorithmParameters.h Program/C_Interface.h + DESTINATION include) +endif() -# Install -install(TARGETS lib - DESTINATION lib) -install(TARGETS bin - DESTINATION bin) -install(FILES Program/AlgorithmParameters.h Program/C_Interface.h - DESTINATION include) \ No newline at end of file diff --git a/Test/Test-c/CMakeLists.txt b/Test/Test-c/CMakeLists.txt index 0a89d265e..677bd90e3 100644 --- a/Test/Test-c/CMakeLists.txt +++ b/Test/Test-c/CMakeLists.txt @@ -2,13 +2,10 @@ cmake_minimum_required(VERSION 3.15) project(HGS_Test_c) set(CMAKE_C_STANDARD 99) -include_directories(${CMAKE_SOURCE_DIR}/Program) +add_executable(lib_test_c test.c) -add_executable(lib_test_c - test.c - ${CMAKE_SOURCE_DIR}/Program/C_Interface.h - ${CMAKE_SOURCE_DIR}/Program/AlgorithmParameters.h - ) - -target_link_libraries(lib_test_c -lm lib) # need -lm to link math library +IF (NOT WIN32) + target_link_libraries(lib_test_c m) +ENDIF() +target_link_libraries(lib_test_c lib_static)