From 5a599f1b27553878688e06c76e632bca26ab1d97 Mon Sep 17 00:00:00 2001 From: hobbes1069 Date: Sun, 28 Sep 2014 20:02:20 +0000 Subject: [PATCH] Update cmake config and fix Windows NSIS packager to find depdendencies automatically. git-svn-id: https://svn.code.sf.net/p/freetel/code@1864 01035d8c-6547-0410-b346-abe4f91aad63 --- fdmdv2/CMakeLists.txt | 115 +++++++++++--------------- fdmdv2/cmake/BuildWxWidgets.cmake | 11 ++- fdmdv2/cmake/GetDependencies.cmake.in | 25 ++++++ 3 files changed, 80 insertions(+), 71 deletions(-) create mode 100644 fdmdv2/cmake/GetDependencies.cmake.in diff --git a/fdmdv2/CMakeLists.txt b/fdmdv2/CMakeLists.txt index b83697d3..72cda743 100644 --- a/fdmdv2/CMakeLists.txt +++ b/fdmdv2/CMakeLists.txt @@ -39,12 +39,14 @@ if(FREEDV_VERSION_PATCH) set(FREEDV_VERSION ${FREEDV_VERSION}.${FREEDV_VERSION_PATCH}) endif(FREEDV_VERSION_PATCH) +message(STATUS "FreeDV version: ${FREEDV_VERSION}") + # Set default build type if(NOT CMAKE_BUILD_TYPE) set(CMAKE_BUILD_TYPE "Release") + message(STATUS "Build type not specified, defaulting to ${CMAKE_BUILD_TYPE}") endif(NOT CMAKE_BUILD_TYPE) -message(STATUS "FreeDV version: ${FREEDV_VERSION}") # Work around for not using a svn working copy. add_definitions(-D_NO_AUTOTOOLS_) @@ -65,7 +67,6 @@ add_definitions(-DSVN_REVISION="${SVN_REVISION}") else() add_definitions(-DSVN_REVISION="Unversioned directory") endif() - # Set default build flags. @@ -112,23 +113,16 @@ if(BOOTSTRAP_WXWIDGETS AND NOT EXISTS ${WXCONFIG}) message(STATUS "Will perform bootstrap build of wxWidgets. After make step completes, re-run cmake and make again to perform FreeDV build.") # -# Continue normal build if not bootstrapping wxWidgets or already built it. +# Continue normal build if not bootstrapping wxWidgets or is already built. # else(BOOTSTRAP_WXWIDGETS AND NOT EXISTS ${WXCONFIG}) -# Setup empty list to append to. -set(FREEDV_LINK_LIBS "") -set(FREEDV_STATIC_LIBS "") - # # Various hacks and work arounds for building under MinGW. # if(MINGW) message(STATUS "System is MinGW.") - # For some reason "Release" causes an error on exit. Force build type to be - # Debug for MINGW builds. - set(CMAKE_BUILD_TYPE Debug) # This sets up the exe icon for windows under mingw. set(RES_FILES "") set(RES_FILES "${CMAKE_SOURCE_DIR}/contrib/freedv.rc") @@ -136,26 +130,8 @@ if(MINGW) enable_language(RC) set(CMAKE_RC_COMPILE_OBJECT " -O coff -i -o ") - # Even using msys, cmake doesn't know it can use unix style paths... - set(CMAKE_LIBRARY_PATH ${CMAKE_LIBRARY_PATH};C:/MinGW/lib;C:/MinGW/msys/1.0/lib;C:/MinGW/msys/1.0/local/lib) - message("Library path: ${CMAKE_LIBRARY_PATH}") - # Try to build in libgcc and libstdc++ but it doesn't appear to work. - #add_definitions(-static-libgcc -static-libstdc++) - # Try to grab all the runtime dlls for the windows installer. - # This will break if the dll names change! + # These are DLOPEN'ed and can't be automatically pulled in by dependency. foreach(RUNTIME - libgcc_s_sjlj-1.dll - libstdc++-6.dll - libsndfile-1.dll - libsamplerate-0.dll - libcodec2.dll - libpng16-16.dll - libportaudio-2.dll - libportaudiocpp-0.dll - libsox-2.dll - zlib1.dll - libusb0.dll - libhamlib-2.dll hamlib-adat.dll hamlib-alinco.dll hamlib-amsat.dll @@ -185,6 +161,7 @@ if(MINGW) message(STATUS "runtime found: ${${RUNTIME}_LIB}") list(APPEND CMAKE_INSTALL_SYSTEM_RUNTIME_LIBS ${${RUNTIME}_LIB}) endforeach() + include(InstallRequiredSystemLibraries) endif(MINGW) # Math library is automatic on MinGW @@ -226,39 +203,26 @@ message(STATUS "Threads library flags: ${CMAKE_THREAD_LIBS_INIT}") if(NOT USE_STATIC_PORTAUDIO) message(STATUS "Looking for portaudio...") find_package(Portaudio REQUIRED) - if(PORTAUDIO_FOUND AND ${PORTAUDIO_VERSION} EQUAL 19) + if(PORTAUDIO_FOUND) + message(STATUS " portaudio library: ${PORTAUDIO_LIBRARIES}") + message(STATUS " portaudio headers: ${PORTAUDIO_INCLUDE_DIRS}") list(APPEND FREEDV_LINK_LIBS ${PORTAUDIO_LIBRARIES}) include_directories(${PORTAUDIO_INCLUDE_DIRS}) else() + message(FATAL_ERROR "portaudio library not found. +On Linux systems try installing: + portaudio-devel (RPM based systems) + libportaudio-dev (DEB based systems) +On Windows it's easiest to use the cmake option: USE_STATIC_PORTAUDIO" + ) + endif() + if(NOT ${PORTAUDIO_VERSION} EQUAL 19) message(WARNING "Portaudio versions other than 19 are known to have issues. You have been warned!") - list(APPEND FREEDV_LINK_LIBS ${PORTAUDIO_LIBRARIES}) - include_directories(${PORTAUDIO_INCLUDE_DIRS}) endif() -# find_library(PORTAUDIO_LIBS NAMES libportaudio-2.dll portaudio HINTS /usr/local/lib/portaudio2) -# find_path(PORTAUDIO_INCLUDE_DIR portaudio.h HINTS /usr/local/include/portaudio2) -# message(STATUS " portaudio library: ${PORTAUDIO_LIBS}") -# message(STATUS " portaudio headers: ${PORTAUDIO_INCLUDE_DIR}") -# if(PORTAUDIO_LIBS AND PORTAUDIO_INCLUDE_DIR) -# list(APPEND FREEDV_LINK_LIBS ${PORTAUDIO_LIBS}) -# include_directories(${PORTAUDIO_INCLUDE_DIR}) -# else(PORTAUDIO_LIBS AND PORTAUDIO_INCLUDE_DIR) -# message(FATAL_ERROR "portaudio library not found. -#On Linux systems try installing: -# portaudio-devel (RPM based systems) -# libportaudio-dev (DEB based systems) -#On Windows it's easiest to use the cmake option: USE_STATIC_PORTAUDIO" -# ) -# endif(PORTAUDIO_LIBS AND PORTAUDIO_INCLUDE_DIR) else(NOT USE_STATIC_PORTAUDIO) message(STATUS "Will attempt static build of portaudio.") include(cmake/BuildPortaudio.cmake) endif(NOT USE_STATIC_PORTAUDIO) -# Do we need this? -#find_library(PORTAUDIOCPP portaudiocpp) -#if(PORTAUDIOCPP) -# message(STATUS "portaudiocpp library: ${PORTAUDIOCPP}") -# list(APPEND FREEDV_LINK_LIBS ${PORTAUDIOCPP}) -#endif(PORTAUDIOCPP) # # Hamlib library @@ -380,6 +344,7 @@ set(WX_VERSION_MIN 3.0.0) find_package(wxWidgets REQUIRED core base aui html net adv) execute_process(COMMAND sh "${wxWidgets_CONFIG_EXECUTABLE}" --version OUTPUT_VARIABLE WX_VERSION) +string(STRIP ${WX_VERSION} WX_VERSION) if(WX_VERSION VERSION_EQUAL ${WX_VERSION_MIN} OR WX_VERSION VERSION_GREATER ${WX_VERSION_MIN}) message(STATUS "wxWidgets version: ${WX_VERSION}") @@ -401,22 +366,30 @@ endif(wxWidgets_FOUND) # if(NOT USE_STATIC_CODEC2) message(STATUS "Looking for codec2...") - find_path(CODEC2_INCLUDE_DIR codec2.h - PATH_SUFFIXES codec2) - find_library(CODEC2_LIBRARY NAMES codec2) - message(STATUS " codec2 library: ${CODEC2_LIBRARY}") - message(STATUS " codec2 headers: ${CODEC2_INCLUDE_DIR}") - if(CODEC2_INCLUDE_DIR AND CODEC2_LIBRARY) - include_directories(${CODEC2_INCLUDE_DIR}) - list(APPEND FREEDV_LINK_LIBS ${CODEC2_LIBRARY}) - else(CODEC2_INCLUDE_DIR AND CODEC2_LIBRARY) - message(FATAL_ERROR "codec2 library not found. + find_package(codec2 CONFIG QUIET) + if(codec2_FOUND) + get_target_property(CODEC2_BRARY codec2 LOCATION) + message(STATUS " codec2 library: ${CODEC2_LIBRARY}") + message(STATUS " codec2 headers: ${codec2_INCLUDE_DIRS}") + else() + # Try to find manually + find_path(CODEC2_INCLUDE_DIRS codec2.h + PATH_SUFFIXES codec2) + find_library(CODEC2_LIBRARY NAMES codec2) + if(CODEC2_LIBRARY AND CODEC2_INCLUDE_DIRS) + message(STATUS " codec2 library: ${CODEC2_LIBRARY}") + message(STATUS " codec2 headers: ${CODEC2_INCLUDE_DIRS}") + list(APPEND FREEDV_LINK_LIBS ${CODEC2_LIBRARY}) + include_directories(${CODEC2_INCLUDE_DIRS}) + else() + message(FATAL_ERROR "codec2 library not found. Linux: Codec2 may not be in your distribution so build yourself or use the cmake option to build statically into FreeDV. Windws: It's easiest to use the cmake option: USE_STATIC_CODEC2" ) - endif(CODEC2_INCLUDE_DIR AND CODEC2_LIBRARY) + endif() + endif() else(NOT USE_STATIC_CODEC2) message(STATUS "Will attempt static build of codec2.") include(cmake/BuildCodec2.cmake) @@ -432,10 +405,13 @@ add_subdirectory(contrib) message(STATUS "Build type will be: ${CMAKE_BUILD_TYPE}") # -# Cpack NSIS configuration for Windows. EXPERIMENTAL!!! +# Cpack NSIS configuration for Windows. # if(WIN32) - include(InstallRequiredSystemLibraries) + configure_file(cmake/GetDependencies.cmake.in cmake/GetDependencies.cmake + @ONLY + ) + install(SCRIPT ${CMAKE_BINARY_DIR}/cmake/GetDependencies.cmake) set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "HF Digital Voice for Radio Amateurs") set(CPACK_PACKAGE_VENDOR "CMake") set(CPACK_PACKAGE_DESCRIPTION_FILE "${CMAKE_CURRENT_SOURCE_DIR}/README") @@ -444,7 +420,9 @@ if(WIN32) set(CPACK_PACKAGE_VERSION_MINOR ${FREEDV_VERSION_MINOR}) if(FREEDV_VERSION_PATCH) set(CPACK_PACKAGE_VERSION_PATCH ${FREEDV_VERSION_PATCH}) - endif(FREEDV_VERSION_PATCH) + else() + set(CPACK_PACKAGE_VERSION_PATCH "0") + endif() set(CPACK_PACKAGE_INSTALL_DIRECTORY "FreeDV") set(CPACK_PACKAGE_EXECUTABLES freedv;FreeDV) # There is a bug in NSI that does not handle full unix paths properly. Make @@ -452,8 +430,9 @@ if(WIN32) #set(CPACK_PACKAGE_ICON "${CMake_SOURCE_DIR}/Utilities/Release\\\\InstallIcon.bmp") set(CPACK_NSIS_INSTALLED_ICON_NAME "bin\\\\freedv.exe") set(CPACK_NSIS_DISPLAY_NAME "${CPACK_PACKAGE_INSTALL_DIRECTORY}") - set(CPACK_NSIS_URL_INFO_ABOUT "http:\\\\\\\\freedv.org") + set(CPACK_NSIS_URL_INFO_ABOUT "http://freedv.org") set(CPACK_NSIS_MODIFY_PATH OFF) + set(CPACK_NSIS_MENU_LINKS "http://freedv.org" "FreeDV Homepage") include(CPack) endif(WIN32) diff --git a/fdmdv2/cmake/BuildWxWidgets.cmake b/fdmdv2/cmake/BuildWxWidgets.cmake index 1a1c4104..c921eae7 100644 --- a/fdmdv2/cmake/BuildWxWidgets.cmake +++ b/fdmdv2/cmake/BuildWxWidgets.cmake @@ -5,7 +5,11 @@ ExternalProject_Add(wxWidgets URL http://downloads.sourceforge.net/wxwindows/${WXWIDGETS_TARBALL}.tar.bz2 BUILD_IN_SOURCE 1 INSTALL_DIR external/dist - CONFIGURE_COMMAND ./configure --disable-shared --prefix=${CMAKE_BINARY_DIR}/external/dist + if(MINGW) + CONFIGURE_COMMAND mingw32-make -f ${source_dir}/build/msw/makefile.gcc SHARED=0 UNICODE=1 BUILD=release PREFIX=${CMAKE_BINARY_DIR}/external/dist + else(MINGW) + CONFIGURE_COMMAND ./configure --disable-shared --prefix=${CMAKE_BINARY_DIR}/external/dist + endif(MINGW) BUILD_COMMAND $(MAKE) INSTALL_COMMAND $(MAKE) install ) @@ -13,5 +17,6 @@ ExternalProject_Add(wxWidgets ExternalProject_Get_Property(wxWidgets install_dir) set(WXCONFIG "${install_dir}/bin/wx-config") set(WXRC "${install_dir}/bin/wxrc") -#list(APPEND FREEDV_LINK_LIBS ${wxWidgets_LIBRARIES}) -#list(APPEND FREEDV_STATIC_DEPS wxWidgets) +if(EXISTS ${WXCONFIG}) + set(BS_WX_DONE TRUE) +endif() diff --git a/fdmdv2/cmake/GetDependencies.cmake.in b/fdmdv2/cmake/GetDependencies.cmake.in new file mode 100644 index 00000000..93204dd7 --- /dev/null +++ b/fdmdv2/cmake/GetDependencies.cmake.in @@ -0,0 +1,25 @@ +# As this script is run in a new cmake instance, it does not have access to +# the existing cache variables. Pass them in via the configure_file command. +set(CMAKE_BINARY_DIR @CMAKE_BINARY_DIR@) +set(CMAKE_SOURCE_DIR @CMAKE_SOURCE_DIR@) +set(UNIX @UNIX@) +set(WIN32 @WIN32@) +set(CMAKE_CROSSCOMPILING @CMAKE_CROSSCOMPILING@) +set(CMAKE_FIND_LIBRARY_SUFFIXES @CMAKE_FIND_LIBRARY_SUFFIXES@) +set(CMAKE_FIND_LIBRARY_PREFIXES @CMAKE_FIND_LIBRARY_PREFIXES@) +set(CMAKE_SYSTEM_LIBRARY_PATH @CMAKE_SYSTEM_LIBRARY_PATH@) +set(CMAKE_FIND_ROOT_PATH @CMAKE_FIND_ROOT_PATH@) + +set(FREEDV_EXE ${CMAKE_BINARY_DIR}/src/freedv.exe) + +include(GetPrerequisites) +get_prerequisites("${FREEDV_EXE}" _deps 1 1 "" "${CMAKE_SYSTEM_LIBRARY_PATH}") +foreach(_runtime ${_deps}) + message("Looking for ${_runtime}") + find_library(RUNTIME_${_runtime} ${_runtime}) + message("${RUNTIME_${_runtime}}") + if(RUNTIME_${_runtime}) + file(INSTALL DESTINATION "${CMAKE_INSTALL_PREFIX}/bin" + TYPE EXECUTABLE FILES "${RUNTIME_${_runtime}}") + endif() +endforeach() -- 2.25.1