Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add cmake support #40

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

add cmake support #40

wants to merge 1 commit into from

Conversation

tienex
Copy link

@tienex tienex commented Apr 23, 2016

I needed to use this awesome library in a bigger project which requires CMake, since I don't feel to maintain it for the whole lifetime of the project, it would be nice if this could get merged as an alternative way to build liquid. I successfully compiled it on different architectures, including Windows (although some changes are required in order to run the benchmark suite) with Mingw.

@jgaeddert
Copy link
Owner

I have to admit I'm not a fan of CMake for its recursive makefile generation, but this is intriguing. At the end of the day if it's easier for people to build, then it's a win in my book. I'll take a closer look at this soon.

@tienex
Copy link
Author

tienex commented Apr 24, 2016

Thanks! If you have any question or request, feel free to ask, I'll be happy to help.

@guruofquality
Copy link
Contributor

I messed with a cmake build a while ago. Its probably not as complete, but the work is here: pothosware@5b1c843 I actually made a little python script to parse the makefile rules into cmake variables to reduce the amount of duplication. For better for for worse :-)

Here is a snippet if you want to extract the version number from liquid.h instead:

+########################################################################
+# Extract version
+########################################################################
+set(LIQUID_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/parser)
+file(READ "${CMAKE_CURRENT_SOURCE_DIR}/include/liquid.h" liquid_h)
+string(REGEX MATCH "\\#define LIQUID_VERSION          \"([0-9]+\\.[0-9]+\\.[0-9]+)\"" LIQUID_VERSION_MATCHES "${liquid_h}")
+if(NOT LIQUID_VERSION_MATCHES)
+    message(FATAL_ERROR "Failed to extract version number from liquid.h")
+endif(NOT LIQUID_VERSION_MATCHES)
+set(LIQUID_VERSION ${CMAKE_MATCH_1})
+

@tienex
Copy link
Author

tienex commented Apr 24, 2016

@guruofquality thanks! will update it as soon as i am back home!

@tienex
Copy link
Author

tienex commented Apr 24, 2016

I've updated the change, removed some redundancy in building examples and merged the bits from @guruofquality. I've also fixed a couple of other issues related to cross compiling.

@guruofquality
Copy link
Contributor

@tienex Also, I would suggest throwing in a variable for LIB_SUFFIX. This helps the multi-arch systems (like when debian uses lib/x86_64-linux-gnu or when redhat uses lib64). I'm not suggesting any kind of automatic detection, just a way to set this if need-be. Here is a snippet/example that I commonly use:

install(TARGETS SoapySDR
    LIBRARY DESTINATION lib${LIB_SUFFIX} # .so file
    ARCHIVE DESTINATION lib${LIB_SUFFIX} # .lib file
    RUNTIME DESTINATION bin              # .dll file
)

Also thanks for doing this :-)

@lleoha
Copy link

lleoha commented Apr 25, 2016

@jgaeddert What about just improving autotools building? I had to improve build system a little bit so I moved project to use libtool and automake so it is easier for me to cross compile and build dll libraries on windows (mingw). If you're interested in I could tidy up the code and create pull request.

@tienex
Copy link
Author

tienex commented Apr 25, 2016

@lleoha I want to state I didn't do this with the goal to replace the current build system nor I asked for that, I am just interested to have liquid-dsp build being integrable in larger cmake projects.

@tienex
Copy link
Author

tienex commented Apr 25, 2016

OK I cleaned it up some more, especially the mess I did for CPU features check improving the CheckCPUID when cross-compiling based on compiler features available and added the ${LIB_SUFFIX} @guruofquality asked for.

@NawfalMotii
Copy link

Hi tienex, any help on how to use the library on windows on Eclipse GCC for an STM32F7??

@brian-armstrong
Copy link
Contributor

This is great stuff. liquid is the last dependency for my project that doesn't use cmake, so with this change I can just use the same toolchain file everywhere for cross-compiling 👍

@shaggyhiggins
Copy link

Hi!

liquid-dsp has has quite a few changes since this CMake branch was created. Has anyone had success using it to build in Windows/MSYS2/MinGW on more recent versions? Out of the box, I am getting undefined references:

[ 32%] Linking C shared library msys-liquid-1.2.0.dll
CMakeFiles/liquid-shared.dir/src/fft/src/spgramcf.c.o:spgramcf.c:(.text+0x86d): undefined reference to 'hamming'
CMakeFiles/liquid-shared.dir/src/fft/src/spgramcf.c.o:spgramcf.c:(.text+0x898): undefined reference to 'hann'
CMakeFiles/liquid-shared.dir/src/fft/src/spgramcf.c.o:spgramcf.c:(.text+0x8c3): undefined reference to 'blackmanharris'
CMakeFiles/liquid-shared.dir/src/fft/src/spgramcf.c.o:spgramcf.c:(.text+0x8ee): undefined reference to 'blackmanharris7'
CMakeFiles/liquid-shared.dir/src/fft/src/spgramcf.c.o:spgramcf.c:(.text+0x926): undefined reference to 'kaiser'
CMakeFiles/liquid-shared.dir/src/fft/src/spgramcf.c.o:spgramcf.c:(.text+0x951): undefined reference to 'flattop'
CMakeFiles/liquid-shared.dir/src/fft/src/spgramcf.c.o:spgramcf.c:(.text+0x982): undefined reference to 'triangular'
CMakeFiles/liquid-shared.dir/src/fft/src/spgramcf.c.o:spgramcf.c:(.text+0x9bc): undefined reference to 'liquid_rcostaper_windowf'
CMakeFiles/liquid-shared.dir/src/fft/src/spgramcf.c.o:spgramcf.c:(.text+0x9ed): undefined reference to 'liquid_kbd'
CMakeFiles/liquid-shared.dir/src/fft/src/spgramf.c.o:spgramf.c:(.text+0x847): undefined reference to 'hamming'
CMakeFiles/liquid-shared.dir/src/fft/src/spgramf.c.o:spgramf.c:(.text+0x872): undefined reference to 'hann'
CMakeFiles/liquid-shared.dir/src/fft/src/spgramf.c.o:spgramf.c:(.text+0x89d): undefined reference to 'blackmanharris'
CMakeFiles/liquid-shared.dir/src/fft/src/spgramf.c.o:spgramf.c:(.text+0x8c8): undefined reference to 'blackmanharris7'
CMakeFiles/liquid-shared.dir/src/fft/src/spgramf.c.o:spgramf.c:(.text+0x900): undefined reference to 'kaiser'
CMakeFiles/liquid-shared.dir/src/fft/src/spgramf.c.o:spgramf.c:(.text+0x92b): undefined reference to 'flattop'
CMakeFiles/liquid-shared.dir/src/fft/src/spgramf.c.o:spgramf.c:(.text+0x95c): undefined reference to 'triangular'
CMakeFiles/liquid-shared.dir/src/fft/src/spgramf.c.o:spgramf.c:(.text+0x996): undefined reference to 'liquid_rcostaper_windowf'
CMakeFiles/liquid-shared.dir/src/fft/src/spgramf.c.o:spgramf.c:(.text+0x9c7): undefined reference to 'liquid_kbd'
CMakeFiles/liquid-shared.dir/src/filter/src/filter_rrrf.c.o:filter_rrrf.c:(.text+0x1d2d): undefined reference to 'kaiser'
CMakeFiles/liquid-shared.dir/src/filter/src/filter_rrrf.c.o:filter_rrrf.c:(.text+0x991f): undefined reference to 'kaiser'
CMakeFiles/liquid-shared.dir/src/filter/src/filter_rrrf.c.o:filter_rrrf.c:(.text+0x9b91): undefined reference to 'kaiser'
CMakeFiles/liquid-shared.dir/src/filter/src/filter_crcf.c.o:filter_crcf.c:(.text+0x1a5f): undefined reference to 'kaiser'
CMakeFiles/liquid-shared.dir/src/filter/src/filter_crcf.c.o:filter_crcf.c:(.text+0x9416): undefined reference to 'kaiser'
CMakeFiles/liquid-shared.dir/src/filter/src/filter_crcf.c.o:filter_crcf.c:(.text+0x9688): more undefined references to 'kaiser' follow
CMakeFiles/liquid-shared.dir/src/framing/src/gmskframegen.c.o:gmskframegen.c:(.text+0x89d): undefined reference to 'hamming'
CMakeFiles/liquid-shared.dir/src/framing/src/gmskframegen.c.o:gmskframegen.c:(.text+0xb42): undefined reference to 'hamming'
collect2.exe: error: ld returned 1 exit status
make[2]: *** [CMakeFiles/liquid-shared.dir/build.make:4073: msys-liquid-1.2.0.dll] Error 1
make[1]: *** [CMakeFiles/Makefile2:137: CMakeFiles/liquid-shared.dir/all] Error 2
make: *** [Makefile:128: all] Error 2

Does the CMakeLists file need any changes to reflect the current code from jgaeddert?

@shaggyhiggins
Copy link

If you're still interested in maintining this, there was a file added that isn't in the CMakeLists.txt: src/math/src/windows.c

Once I added that the static and shared lib both built. Haven't tried using yet... but the built finishes at least.

@nm17
Copy link

nm17 commented Sep 18, 2017

How about adding cotire to all of this?

@anton-danielsson
Copy link

Sorry to necropost but this would be great 😄

@nm17
Copy link

nm17 commented Apr 9, 2021

We still waiting...

@crroush
Copy link

crroush commented Nov 27, 2022

@jgaeddert instead of introducing CMAKE into the baseline, simply provide instructions on how to add this to an existing cmake project?

There are many ways to add third-party dependencies. I am using CPM.
First add fftw:

CPMAddPackage(
  NAME fftw3
  URL "http://fftw.org/fftw-3.3.10.tar.gz"
  OPTIONS "ENABLE_THREADS ON" "ENABLE_FLOAT ON" "BUILD_TESTS OFF"
)

Then add liquid-dsp.

CPMAddPackage(
  NAME liquid
  GITHUB_REPOSITORY jgaeddert/liquid-dsp
  GIT_TAG v1.5.0
  VERSION v1.5.0
  DOWNLOAD_ONLY YES
)
 
if (liquid_ADDED)
  set( liquid_LIBRARY "${liquid_BINARY_DIR}/lib/libliquid.so" )
  set(CONFIGURE_ARGS "--prefix=${liquid_BINARY_DIR}")
   
  execute_process( COMMAND "./bootstrap.sh"
                   WORKING_DIRECTORY ${liquid_SOURCE_DIR}
                   RESULT_VARIABLE BS_RESULT OUTPUT_VARIABLE
                   BS_OUTPUT ERROR_VARIABLE BS_ERROR)
 
  execute_process( COMMAND "./configure" ${CONFIGURE_ARGS}
                   WORKING_DIRECTORY ${liquid_SOURCE_DIR}
                   RESULT_VARIABLE BS_RESULT OUTPUT_VARIABLE
                   BS_OUTPUT ERROR_VARIABLE BS_ERROR)
 
  execute_process( COMMAND "make"
                   WORKING_DIRECTORY ${liquid_SOURCE_DIR}
                   RESULT_VARIABLE BS_RESULT OUTPUT_VARIABLE
                   BS_OUTPUT ERROR_VARIABLE BS_ERROR)
 
  execute_process( COMMAND "make" "install"
                   WORKING_DIRECTORY ${liquid_SOURCE_DIR}
                   RESULT_VARIABLE BS_RESULT OUTPUT_VARIABLE
                   BS_OUTPUT ERROR_VARIABLE BS_ERROR)
  add_library( liquid::liquid INTERFACE IMPORTED GLOBAL)
  target_include_directories( liquid::liquid INTERFACE ${liquid_BINARY_DIR}/include)
  target_link_libraries( liquid::liquid INTERFACE "${liquid_LIBRARY}")
endif()

Then to include it in a target:

target_link_libraries(my-program liquid::liquid  fftw3f )

@xerpi
Copy link

xerpi commented Aug 1, 2024

In case it helps, until official CMake support gets merged, I'm currently using liquid-dsp as an external project, which is kind of hacky:

ExternalProject_Add(liquid-dsp-project
    SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/liquid-dsp
    BUILD_IN_SOURCE TRUE
    CONFIGURE_COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/liquid-dsp/bootstrap.sh
        COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/liquid-dsp/configure
            --prefix=${CMAKE_BINARY_DIR}/liquid-dsp
            --enable-fftoverride
            CFLAGS=${CMAKE_C_FLAGS}
            CPPFLAGS=${CMAKE_C_FLAGS}
            CXXFLAGS=${CMAKE_CXX_FLAGS}
            LDFLAGS=${CMAKE_EXE_LINKER_FLAGS}
    INSTALL_COMMAND ""
    BUILD_BYPRODUCTS ${CMAKE_CURRENT_SOURCE_DIR}/liquid-dsp/libliquid.a
    BUILD_ALWAYS TRUE
)

add_library(liquid-dsp STATIC IMPORTED GLOBAL)

add_dependencies(liquid-dsp liquid-dsp-project)

set_target_properties(liquid-dsp PROPERTIES
    IMPORTED_LOCATION ${CMAKE_CURRENT_SOURCE_DIR}/liquid-dsp/libliquid.a
)

target_include_directories(liquid-dsp INTERFACE
    $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/liquid-dsp/include>
    $<INSTALL_INTERFACE:${CMAKE_BINARY_DIR}/liquid-dsp/include/liquid>
)

target_link_libraries(liquid-dsp INTERFACE
    m
)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.