rvaser / spoa

SIMD partial order alignment tool/library
MIT License
158 stars 32 forks source link

4.0.5 build -DBUILD_SHARED_LIBS=ON : CMakeFiles/spoa.dir/build.make:144: *** missing separator. Stop. #56

Closed mr-c closed 3 years ago

mr-c commented 3 years ago

Excerpt from the cmake generated CMakeFiles/spoa.dir/build.make at line 144

lib/libspoa.so.$(EQUALS);7.0.0: CMakeFiles/spoa.dir/src/alignment_engine.cpp.o
lib/libspoa.so.$(EQUALS);7.0.0: CMakeFiles/spoa.dir/src/graph.cpp.o
lib/libspoa.so.$(EQUALS);7.0.0: CMakeFiles/spoa.dir/src/sisd_alignment_engine.cpp.o
lib/libspoa.so.$(EQUALS);7.0.0: CMakeFiles/spoa.dir/src/dispatcher.cpp.o
lib/libspoa.so.$(EQUALS);7.0.0: CMakeFiles/spoa.dir/build.make
lib/libspoa.so.$(EQUALS);7.0.0: CMakeFiles/spoa.dir/link.txt
        @$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --green --bold --progress-dir=/home/michael/src/spoa/spoa/build/CMakeFiles --progress-num=$(CMAKE_PROGRESS_5) "Linking CXX shared library lib/libspoa.so"
        $(CMAKE_COMMAND) -E cmake_link_script CMakeFiles/spoa.dir/link.txt --verbose=$(VERBOSE)
        $(CMAKE_COMMAND) -E cmake_symlink_library "lib/libspoa.so.=;7.0.0" "lib/libspoa.so.=;7.0.0" lib/libspoa.so

Without -DBUILD_SHARED_LIBS=ON the build suceeds

Full build log:

$ cmake -Dspoa_build_executable=ON -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=ON .. && make
-- The CXX compiler identification is GNU 10.2.1
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /usr/lib/ccache/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
CMake Warning (dev) at vendor/cereal/CMakeLists.txt:2 (project):
  Policy CMP0048 is not set: project() command manages VERSION variables.
  Run "cmake --help-policy CMP0048" for policy details.  Use the cmake_policy
  command to set the policy and suppress this warning.

  The following variable(s) would be set to empty:

    PROJECT_VERSION
    PROJECT_VERSION_MAJOR
    PROJECT_VERSION_MINOR
    PROJECT_VERSION_PATCH
This warning is for project developers.  Use -Wno-dev to suppress it.

-- The C compiler identification is GNU 10.2.1
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /usr/lib/ccache/cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Found Boost: /usr/lib/x86_64-linux-gnu/cmake/Boost-1.74.0/BoostConfig.cmake (found version "1.74.0") found components: serialization 
-- boost_variant.cpp
-- Found Doxygen: /usr/bin/doxygen (found version "1.8.20") found components: doxygen dot 
-- Found ZLIB: /usr/lib/x86_64-linux-gnu/libz.so (found version "1.2.11") 
-- Configuring done
-- Generating done
-- Build files have been written to: /home/michael/src/spoa/spoa/build
CMakeFiles/spoa.dir/build.make:141: *** missing separator.  Stop.
make[1]: *** [CMakeFiles/Makefile2:481: CMakeFiles/spoa.dir/all] Error 2
make: *** [Makefile:149: all] Error 2

Debian was depending on this to make a shared library, so this is preventing us from release an updated Debian package of spoa 4.0.5

rvaser commented 3 years ago

Can you please try the latest commit (6f421bf) if it compiles now? I will publish a release afterwards.

rvaser commented 3 years ago

I have release v4.0.6 with the fix (I hope).

mr-c commented 3 years ago

@rvaser That made it better, thanks!

Did the way cpu_features get compiled change? We are now getting a separate '.so' for that, instead of it being compiled in statically, and this is causing an issue.

rvaser commented 3 years ago

I have not updated cpu_features, only spoa CMakeLists a bit. Let me check.

rvaser commented 3 years ago

Version 3.4.0 also generates the .so file for cpu_features. what is the latest version you have in Debian?

mr-c commented 3 years ago

@rvaser We had 3.4.0. Looks like the patch we used to generate a separate shared object in 3.4.0 avoided a separate shared object for cpu_features.

https://packages.debian.org/sid/amd64/spoa/filelist https://packages.debian.org/sid/amd64/libspoa4.0.0/filelist

Seems my attempted updating of that patch for 4.0.5/4.0.6 missed something: https://salsa.debian.org/med-team/spoa/-/blob/master/debian/patches/shared_and_static.patch

rvaser commented 3 years ago

Are you building both static and shared on purpose? If so, the patch does not enable dispatching in static library.

I applied your patch locally, plus target_link_libraries(${PROJECT_NAME}_static cereal), and it works fine, i.e. cpu_features is not a .so but an .a.

[Edit] Also, the patch does not add SOVERSION to libspoa.so. [Edit2] Here is a part of modified CMakeLists which should do the trick I think:

...

set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/lib)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/lib)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/bin)
# set(BUILD_SHARED_LIBS OFF CACHE BOOL "Build all libraries as shared")

option(spoa_optimize_for_native "Build spoa with -march=native" ON)
option(spoa_optimize_for_portability "Build spoa with -msse4.1" OFF)
option(spoa_use_simde "Use SIMDe library for porting vectorized code" OFF)
option(spoa_use_simde_nonvec "Use SIMDe library for nonvectorized code" OFF)
option(spoa_use_simde_openmp "Use SIMDe support for OpenMP SIMD" OFF)
option(spoa_generate_dispatch "Use SIMDe to generate x86 dispatch" OFF)
if (NOT spoa_generate_dispatch)
  if (spoa_optimize_for_portability)
    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -msse4.1")
  elseif (spoa_optimize_for_native)
    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -march=native")
  endif ()
endif ()
if (spoa_use_simde OR
    spoa_use_simde_nonvec OR
    spoa_use_simde_openmp OR
    spoa_generate_dispatch)
  add_definitions(-DUSE_SIMDE -DSIMDE_ENABLE_NATIVE_ALIASES)
  if (spoa_use_simde_nonvec)
    add_definitions(-DSIMDE_NO_NATIVE)
  endif ()
  if (spoa_use_simde_openmp)
    add_definitions(-DSIMDE_ENABLE_OPENMP)
    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fopenmp-simd")
  endif ()
  if (spoa_generate_dispatch)
    add_definitions(-DGENERATE_DISPATCH)
  endif ()
endif ()

if (NOT TARGET cereal)
  add_subdirectory(vendor/cereal EXCLUDE_FROM_ALL)
endif ()

add_library(${PROJECT_NAME} SHARED
  src/alignment_engine.cpp
  src/graph.cpp
  src/sisd_alignment_engine.cpp
  src/dispatcher.cpp)
target_include_directories(${PROJECT_NAME} PUBLIC
  $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
  $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/vendor/simde>
  $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/vendor/cpu_features/include>
  $<INSTALL_INTERFACE:include>)
target_link_libraries(${PROJECT_NAME}
  cereal)
# if (BUILD_SHARED_LIBS)
  set_property(TARGET ${PROJECT_NAME} PROPERTY SOVERSION "7.0.0")
# endif ()

add_library(${PROJECT_NAME}_static STATIC
  src/alignment_engine.cpp
  src/graph.cpp
  src/sisd_alignment_engine.cpp
  src/dispatcher.cpp)
target_include_directories(${PROJECT_NAME}_static PUBLIC
  $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
  $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/vendor/simde>
  $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/vendor/cpu_features/include>
  $<INSTALL_INTERFACE:include>)
target_link_libraries(${PROJECT_NAME}_static
  cereal)

if (spoa_generate_dispatch)
  if (NOT TARGET cpu_features)
    add_subdirectory(vendor/cpu_features EXCLUDE_FROM_ALL)
  endif ()

  list(APPEND ARCHITECTURES avx2 sse4.1 sse2)
  foreach(arch IN LISTS ARCHITECTURES)
    add_library(${PROJECT_NAME}_${arch} OBJECT
      src/simd_alignment_engine_dispatch.cpp)
    target_include_directories(${PROJECT_NAME}_${arch} PUBLIC
      $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
      $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/vendor/simde>
      $<INSTALL_INTERFACE:include>)
    target_link_libraries(${PROJECT_NAME}_${arch}
      cereal)
    set_target_properties(${PROJECT_NAME}_${arch} PROPERTIES
      COMPILE_FLAGS "-m${arch}")
    if (BUILD_SHARED_LIBS)
      set_property(TARGET ${PROJECT_NAME}_${arch}
        PROPERTY POSITION_INDEPENDENT_CODE ON)
    endif ()
  endforeach ()

  add_dependencies(${PROJECT_NAME}
    ${PROJECT_NAME}_avx2
    ${PROJECT_NAME}_sse4.1
    ${PROJECT_NAME}_sse2)
  add_dependencies(${PROJECT_NAME}_static
    ${PROJECT_NAME}_avx2
    ${PROJECT_NAME}_sse4.1
    ${PROJECT_NAME}_sse2)

  target_link_libraries(${PROJECT_NAME}
    cpu_features)
  target_link_libraries(${PROJECT_NAME}_static
    cpu_features)
endif ()

include(GNUInstallDirs)
install(TARGETS ${PROJECT_NAME}
  DESTINATION ${CMAKE_INSTALL_LIBDIR})
install(TARGETS ${PROJECT_NAME}_static
  DESTINATION ${CMAKE_INSTALL_LIBDIR})
install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/include/spoa
  DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})

...
mr-c commented 3 years ago

Hmm.. I'm still getting a ./lib/libcpu_features.so in the build directory

cd obj-x86_64-linux-gnu && cmake -DCMAKE_INSTALL_PREFIX=/usr -DCMAKE_BUILD_TYPE=None -DCMAKE_INSTALL_SYSCONFDIR=/etc -DCMAKE_INSTALL_LOCALSTATEDIR=/var -DCMAKE_EXPORT_NO_PACKAGE_REGISTRY=ON -DCMAKE_FIND_PACKAGE_NO_PACKAGE_REGISTRY=ON -DCMAKE_INSTALL_RUNSTATEDIR=/run -DCMAKE_SKIP_INSTALL_ALL_DEPENDENCY=ON "-GUnix Makefiles" -DCMAKE_VERBOSE_MAKEFILE=ON -DCMAKE_INSTALL_LIBDIR=lib/x86_64-linux-gnu -DCMAKE_BUILD_TYPE=Release -Dspoa_build_executable=ON -Dspoa_build_tests=ON -Dspoa_use_simde_nonvec=ON -Dspoa_use_simde_openmp=ON -Dspoa_optimize_for_native=OFF -DBUILD_SHARED_LIBS=ON -Dspoa_generate_dispatch=ON ..

Here's the full log https://gist.github.com/mr-c/4561cebbad557fe97fc70ba34ad5bfff

mr-c commented 3 years ago

@rvaser Ah, if I take the -DBUILD_SHARED_LIBS=ON off the cmake invocation and use your patch it works. Thanks!