How could I add a shared libraray (Qt6Core.dll) to CPack? I tested the following snipped:
set(MY_DEPENDENCY_PATHS "C:/Qt/6.0.0/msvc2019_64/bin/")
install(CODE "set(MY_DEPENDENCY_PATHS \"${MY_DEPENDENCY_PATHS}\")")
install(CODE [[
file(GET_RUNTIME_DEPENDENCIES
LIBRARIES $<TARGET_FILE:Qt6::Core>
RESOLVED_DEPENDENCIES_VAR _r_deps
UNRESOLVED_DEPENDENCIES_VAR _u_deps
DIRECTORIES ${MY_DEPENDENCY_PATHS}
)
foreach(_file ${_r_deps})
file(INSTALL
DESTINATION "${CMAKE_INSTALL_PREFIX}/lib"
TYPE SHARED_LIBRARY
FILES "${_file}"
)
endforeach()
list(LENGTH _u_deps _u_length)
if("${_u_length}" GREATER 0)
message("Anzahl: ${_u_length}")
message(WARNING "Unresolved dependencies detected!")
endif()
]])
But it shows me:
CMake Warning at C:/CPP/Projects/beans/build/packaging/cmake_install.cmake:89 (message):
Unresolved dependencies detected!
Call Stack (most recent call first):
C:/CPP/Projects/beans/build/cmake_install.cmake:57 (include)
Now are over 200 other shared libraries in my /lib directory but no Qt6Core.dll.
I solved my Problem.
set(MY_DEPENDENCY_PATHS "C:/Qt/6.0.0/msvc2019_64/bin/")
install(CODE "set(MY_DEPENDENCY_PATHS \"${MY_DEPENDENCY_PATHS}\")")
install(CODE [[
file(GET_RUNTIME_DEPENDENCIES
LIBRARIES $<TARGET_FILE:MYPROJECT>
RESOLVED_DEPENDENCIES_VAR _r_deps
UNRESOLVED_DEPENDENCIES_VAR _u_deps
DIRECTORIES ${MY_DEPENDENCY_PATHS}
PRE_EXCLUDE_REGEXES "api-ms-" "ext-ms-"
POST_EXCLUDE_REGEXES ".*system32/.*\\.dll"
)
foreach(_file ${_r_deps})
file(INSTALL
DESTINATION "${CMAKE_INSTALL_PREFIX}/lib"
TYPE SHARED_LIBRARY
FILES "${_file}"
)
endforeach()
list(LENGTH _u_deps _u_length)
if("${_u_length}" GREATER 0)
message(WARNING "Unresolved dependencies detected!")
endif()
]])
Related
I got the error message:
:-1: Fehler: error: gegl-0.4: linker input file not found: No such file or directory
:-1: Fehler: error: babl-01: linker input file not found: No such file or directory
So the linker cant find the libaries or can't link them for unknown reason.
I have tried:
cmake_minimum_required(VERSION 3.5)
project(perspective_lines LANGUAGES C)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -lm gegl-0.4 babl-01 ")
#export (PKG_CONFIG_PATH="${GIMP_PREFIX}/share/pkgconfig:${GIMP_PREFIX}/lib64/pkgconfig${PKG_CONFIG_PATH:+:$PKG_CONFIG_PATH}"")
#add_compile_options( -L/usr/lib64/libm.so -lm -std=gnu11 -v)
find_package(GTK2 REQUIRED)
include_directories(${GTK2_ATK_INCLUDE_DIR})
include_directories(${GTK2_CAIRO_INCLUDE_DIR})
include_directories(${GTK2_GDKCONFIG_INCLUDE_DIR})
include_directories(${GTK2_GDK_PIXBUF_INCLUDE_DIR})
include_directories(${GTK2_GLIBCONFIG_INCLUDE_DIR})
include_directories(${GTK2_GLIB_INCLUDE_DIR})
include_directories(${GTK2_GTK_INCLUDE_DIR})
include_directories(${GTK2_PANGO_INCLUDE_DIR})
include_directories("${ROOT_SOURCE_DIR}/usr/include/gegl-0.4")
include_directories("${ROOT_SOURCE_DIR}/usr/include/babl-0.1")
include_directories("${ROOT_SOURCE_DIR}/usr/lib64")
include_directories("${ROOT_SOURCE_DIR}/usr/src/debug/glibc-2.34-2.1.x86_64/cc-base/math")
include_directories("${ROOT_SOURCE_DIR}/usr/src/debug/glibc-2.34-2.1.x86_64/")
find_path(LIBGIMP_INCLUDE_DIR libgimp PATH_SUFFIXES gimp-2.0)
find_library(LIBGIMP_LIBRARY NAMES gimp-2.0 libgimp-2.0 PATH_SUFFIXES lib)
find_library(LIBGIMP_UI_LIBRARY NAMES gimpui-2.0 libgimpui-2.0 PATH_SUFFIXES lib)
find_library(LIBGIMP_WIDGETS_LIBRARY NAMES gimpwidgets-2.0 libgimpwidgets-2.0 PATH_SUFFIXES lib)
include_directories(${LIBGIMP_INCLUDE_DIR})
#find_path(LIBGEGL_INCLUDE_DIR libgegl PATH_SUFFIXES gegl-0.4)
#find_library(LIBGEGL_LIBRARY NAMES gegl-0.4 libgegl-0.4 PATH_SUFFIXES lib)
#include_directories(${LIBGEGL_INCLUDE_DIR})
include_directories(${CMAKE_SOURCE_DIR}/src)
set(CMAKE_C_IMPLICIT_LINK_DIRECTORIES "/usr/lib64/gcc/x86_64-suse-linux/9;/usr/lib64;/lib64;/usr/x86_64-suse-linux/lib")
set(SOURCES perspective_lines.c )
add_executable(perspective_lines perspective_lines.c)
target_link_libraries(perspective_lines
${GTK2_GLIB_LIBRARY_RELEASE}
${GTK2_ATK_LIBRARY_RELEASE}
${GTK2_CAIRO_LIBRARY_RELEASE}
${GTK2_GDK_LIBRARY_RELEASE}
${GTK2_GDK_PIXBUF_LIBRARY_RELEASE}
${GTK2_GIO_LIBRARY_RELEASE}
${GTK2_GMODULE_LIBRARY_RELEASE}
${GTK2_GOBJECT_LIBRARY_RELEASE}
${GTK2_GTHREAD_LIBRARY_RELEASE}
${GTK2_GTK_LIBRARY_RELEASE}
${GTK2_PANGOCAIRO_LIBRARY_RELEASE}
${GTK2_PANGO_LIBRARY_RELEASE}
${LIBGIMP_LIBRARY}
${LIBGIMP_UI_LIBRARY}
${LIBGIMP_WIDGETS_LIBRARY})
target_link_libraries(perspective_lines "/usr/lib64/libbabl-0.1.so")
target_link_libraries(perspective_lines "/usr/lib64/libgegl-04.so")
#target_link_libraries(perspective_lines gegl)
install(TARGETS perspective_lines DESTINATION ~/.config/GIMP/2.10/plug-ins/)
This doesn't work also:
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -lm gegl-0.4 -L /usr/lib64/libgegl-04.so")
Where is my mistake ?
Thank you very much for your answer.
That was the problem and ... (its embarrassing) a wrong filename:
target_link_libraries(perspective_lines "/usr/lib64/libgegl-0.4.so")
I downloaded nitroshare.tar.gz file as i want to install it on my Kali Linux.
I followed up instructions as said on there github page to install it & downloaded all the packages that are required for the installation.
When i use cmake command it is showing me this error:
Unknown cmake command qt5_wrap_ui
Here is CMakeList.txt file:
cmake_minimum_required(VERSION 3.7)
configure_file(config.h.in "${CMAKE_CURRENT_BINARY_DIR}/config.h")
set(SRC
application/aboutdialog.cpp
application/application.cpp
application/splashdialog.cpp
bundle/bundle.cpp
device/device.cpp
device/devicedialog.cpp
device/devicelistener.cpp
device/devicemodel.cpp
icon/icon.cpp
icon/trayicon.cpp
settings/settings.cpp
settings/settingsdialog.cpp
transfer/transfer.cpp
transfer/transfermodel.cpp
transfer/transferreceiver.cpp
transfer/transfersender.cpp
transfer/transferserver.cpp
transfer/transferwindow.cpp
util/json.cpp
util/platform.cpp
main.cpp
)
if(WIN32)
set(SRC ${SRC} data/resource.rc)
endif()
if(APPLE)
set(SRC ${SRC}
data/icon/nitroshare.icns
transfer/transferwindow.mm
)
set_source_files_properties("data/icon/nitroshare.icns" PROPERTIES
MACOSX_PACKAGE_LOCATION Resources
)
endif()
if(QHttpEngine_FOUND)
set(SRC ${SRC}
api/apihandler.cpp
api/apiserver.cpp
)
endif()
if(APPINDICATOR_FOUND)
set(SRC ${SRC}
icon/indicatoricon.cpp
)
endif()
qt5_wrap_ui(UI
application/aboutdialog.ui
application/splashdialog.ui
device/devicedialog.ui
settings/settingsdialog.ui
transfer/transferwindow.ui
)
# Update the TS files from the source directory
file(GLOB TS data/ts/*.ts)
add_custom_target(ts
COMMAND "${Qt5_LUPDATE_EXECUTABLE}"
-silent
-locations relative
"${CMAKE_CURRENT_SOURCE_DIR}"
-ts ${TS}
)
# Create a directory for the compiled QM files
file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/data/qm")
# Create commands for each of the translation files
set(QM_XML)
set(QM)
foreach(_ts_path ${TS})
get_filename_component(_ts_name "${_ts_path}" NAME)
get_filename_component(_ts_name_we "${_ts_path}" NAME_WE)
set(_qm_name "${_ts_name_we}.qm")
set(_qm_path "${CMAKE_CURRENT_BINARY_DIR}/data/qm/${_qm_name}")
set(QM_XML "${QM_XML}<file>qm/${_qm_name}</file>")
list(APPEND QM "${_qm_path}")
add_custom_command(OUTPUT "${_qm_path}"
COMMAND "${Qt5_LRELEASE_EXECUTABLE}"
-compress
-removeidentical
-silent
"${_ts_path}"
-qm "${_qm_path}"
COMMENT "Generating ${_ts_name}"
)
endforeach()
# Create a target for compiling all of the translation files
add_custom_target(qm DEPENDS ${QM})
# Configure the i18n resource file
set(QRC_QM "${CMAKE_CURRENT_BINARY_DIR}/data/resource_qm.qrc")
configure_file(data/resource_qm.qrc.in "${QRC_QM}")
qt5_add_resources(QRC
data/resource.qrc
"${QRC_QM}"
)
add_executable(nitroshare WIN32 MACOSX_BUNDLE ${SRC} ${UI} ${QRC})
target_compile_features(nitroshare PRIVATE
cxx_lambdas
cxx_nullptr
cxx_strong_enums
cxx_uniform_initialization
)
# In order to support Retina, a special tag is required in Info.plist.
if(APPLE)
set_target_properties(nitroshare PROPERTIES
MACOSX_BUNDLE_INFO_PLIST "${CMAKE_CURRENT_SOURCE_DIR}/Info.plist.in"
MACOSX_BUNDLE_ICON_FILE "nitroshare.icns"
MACOSX_BUNDLE_GUI_IDENTIFIER "com.NathanOsman.NitroShare"
MACOSX_BUNDLE_BUNDLE_NAME "NitroShare"
)
target_link_libraries(nitroshare "-framework ApplicationServices")
endif()
target_link_libraries(nitroshare Qt5::Widgets Qt5::Network Qt5::Svg)
if(Qt5WinExtras_FOUND)
target_link_libraries(nitroshare Qt5::WinExtras)
endif()
if(Qt5MacExtras_FOUND)
target_link_libraries(nitroshare Qt5::MacExtras)
endif()
if(QHttpEngine_FOUND)
target_link_libraries(nitroshare QHttpEngine)
endif()
if(APPINDICATOR_FOUND)
target_include_directories(nitroshare PRIVATE ${APPINDICATOR_INCLUDE_DIRS})
target_link_libraries(nitroshare ${APPINDICATOR_LIBRARIES})
endif()
include(GNUInstallDirs)
install(TARGETS nitroshare
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
BUNDLE DESTINATION .
)
if(WIN32)
# If windeployqt is available, use it immediately after the build completes to
# ensure that the dependencies are available.
include(DeployQt)
if(WINDEPLOYQT_EXECUTABLE)
windeployqt(nitroshare)
endif()
# If QHttpEngine was used, include it in the installer
if(QHttpEngine_FOUND)
add_custom_command(TARGET nitroshare POST_BUILD
COMMAND "${CMAKE_COMMAND}" -E
copy_if_different "$<TARGET_FILE:QHttpEngine>" "$<TARGET_FILE_DIR:nitroshare>"
COMMENT "Copying QHttpEngine..."
)
endif()
# If Inno Setup is available, provide a target for building an EXE installer.
find_package(InnoSetup)
if(INNOSETUP_EXECUTABLE)
configure_file(dist/setup.iss.in "${CMAKE_CURRENT_BINARY_DIR}/setup.iss")
add_custom_target(exe
COMMAND "${INNOSETUP_EXECUTABLE}"
/Q
/DTARGET_FILE_NAME="$<TARGET_FILE_NAME:nitroshare>"
"${CMAKE_CURRENT_BINARY_DIR}/setup.iss"
DEPENDS nitroshare
COMMENT "Building installer..."
)
endif()
endif()
if(APPLE)
# If QHttpEngine was used, copy the dynlib over and correct its RPATH
if(QHttpEngine_FOUND)
add_custom_command(TARGET nitroshare POST_BUILD
COMMAND "${CMAKE_COMMAND}" -E
make_directory "$<TARGET_FILE_DIR:nitroshare>/../Frameworks"
COMMAND "${CMAKE_COMMAND}" -E
copy_if_different
"$<TARGET_FILE:QHttpEngine>"
"$<TARGET_FILE_DIR:nitroshare>/../Frameworks/$<TARGET_SONAME_FILE_NAME:QHttpEngine>"
COMMAND install_name_tool
-change
"$<TARGET_SONAME_FILE_NAME:QHttpEngine>"
"#rpath/$<TARGET_SONAME_FILE_NAME:QHttpEngine>"
"$<TARGET_FILE:nitroshare>"
COMMENT "Copying QHttpEngine and correcting RPATH..."
)
endif()
# If macdeployqt is available, use it immediately after the build completes to
# copy the Qt frameworks into the application bundle.
include(DeployQt)
if(MACDEPLOYQT_EXECUTABLE)
macdeployqt(nitroshare)
endif()
# Create a target for building a DMG that contains the application bundle and a
# symlink to the /Applications folder.
set(sym "${CMAKE_BINARY_DIR}/out/Applications")
set(dmg "${CMAKE_BINARY_DIR}/nitroshare-${PROJECT_VERSION}-osx.dmg")
add_custom_target(dmg
COMMAND rm -f "${sym}" "${dmg}"
COMMAND ln -s /Applications "${sym}"
COMMAND hdiutil create
-srcfolder "${CMAKE_BINARY_DIR}/out"
-volname "${PROJECT_NAME}"
-fs HFS+
-size 30m
"${dmg}"
DEPENDS nitroshare
COMMENT "Building disk image..."
)
endif()
# On Linux, include the icons, manpage, .desktop file, and file manager extensions when installing.
if(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/dist/icons"
DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}"
)
install(FILES "${CMAKE_CURRENT_SOURCE_DIR}/dist/nitroshare.1"
DESTINATION "${CMAKE_INSTALL_MANDIR}/man1"
)
install(FILES "${CMAKE_CURRENT_SOURCE_DIR}/dist/nitroshare.desktop"
DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/applications"
)
# Configure and install Python extensions for Nautilus-derived file managers
foreach(_file_manager Nautilus Nemo Caja)
string(TOLOWER ${_file_manager} _file_manager_lower)
set(_py_filename "${CMAKE_CURRENT_BINARY_DIR}/dist/nitroshare_${_file_manager_lower}.py")
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/dist/nitroshare.py.in" "${_py_filename}")
install(FILES "${_py_filename}"
DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/${_file_manager_lower}-python/extensions"
RENAME nitroshare.py
)
endforeach()
endif()
CMake doesn't know the function qt5_wrap_ui because you did not import Qt5 or any of the functions it defines.
Before calling qt5_wrap_ui, add this:
find_package(Qt5 COMPONENTS Widgets REQUIRED)
I used this line
find_package(Qt5Widgets)
In my Cmakelist.txt file
I found this on their Document Page of Qt5
Similar to this question I'm trying to build a project with SFML using CMake.
My CMakeLists.txt file is:
cmake_minimum_required(VERSION 2.6)
project(pong)
# Specify C++11 flag for g++
if(CMAKE_COMPILER_IS_GNUCXX OR "${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -O2")
endif()
# Add directory containing FindSFML.cmake to module path
set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake/Modules/" ${CMAKE_MODULE_PATH})
# Add sources
file(GLOB SOURCES
"${PROJECT_SOURCE_DIR}/*.cpp"
)
# Find SFML
set(SFML_ROOT "C:/Users/usr/Downloads/_ Downloads (new)_/SFML-2.4.2-linux-gcc-64-bit/SFML-2.4.2")
find_package( SFML COMPONENTS audio graphics window system REQUIRED )
if(SFML_FOUND)
include_directories(${SFML_INCLUDE_DIR})
target_link_libraries(pong ${SFML_LIBRARIES})
else()
#set(SFML_ROOT "" CACHE PATH "SFML top-level directory")
message("\n-> SFML directory not found. Set SFML_ROOT to SFML's top-level path (containing \"include\" and \"lib\"
directories).")
message("-> Make sure the SFML libraries with the same configuration (Release/Debug, Static/Dynamic) exist.\n")
endif()
add_executable(pong ${SOURCES})
When I try to build it [using MinGW-w64 + MSYS2] on Windows, I get the following error:
CMake Error at cmake/Modules/FindSFML.cmake:307 (message):
Could NOT find SFML (missing: SFML_AUDIO_LIBRARY SFML_GRAPHICS_LIBRARY
SFML_WINDOW_LIBRARY SFML_SYSTEM_LIBRARY)
Call Stack (most recent call first):
CMakeLists.txt:19 (find_package)
I don't know why the libraries are not found.
Please help me.
Sun Studio 12.5 on Solaris 11.3. Solve one problem and move to the next... Building our project with CMake results the link error below.
I believe its a simple matter of detecting SunCC and adding -lnsl -lsocket to LDLIBS. However, the method to detect the SunCC compiler escapes me. I found an old post from 2006 that states (from Error detecting sun studio compiler under linux):
I am trying to use the sun studio compiler under linux and I am having a
terrible time getting past the cmake compiler tests.
AFAIK no one has tried CMake with this compiler before.... CMake is invoking the compiler assuming that it accepts the flags other Linux compilers (such as GNU and Intel) accept... You'll have to setup a platform file to configure this compiler.
I tried to use SunPro from CMake Compiler IDs, but it results in the same error shown below.
if(SunPro)
target_link_libraries(cryptopp-shared nsl socket)
target_link_libraries(cryptest nsl socket)
endif()
My question is, how do I detect the Sun Studio compiler in CMakeList.txt? Or how do I detect Solaris?
/opt/developerstudio12.5/bin/CC -DNDEBUG -g2 -O2 -D__SSE2__ -D__SSE3__ -D__SSSE3__
-D__SSE4_1__ -D__SSE4_2__ -D__AES__ -D__PCLMUL__ -D__RDRND__ -D__RDSEED__ -D__AVX__
-D__AVX2__ -D__BMI__ -D__BMI2__ -D__ADX__ -xarch=avx2_i
CMakeFiles/cryptest.dir/bench1.cpp.o CMakeFiles/cryptest.dir/bench2.cpp.o
CMakeFiles/cryptest.dir/test.cpp.o CMakeFiles/cryptest.dir/validat1.cpp.o
CMakeFiles/cryptest.dir/validat2.cpp.o CMakeFiles/cryptest.dir/validat3.cpp.o
CMakeFiles/cryptest.dir/datatest.cpp.o CMakeFiles/cryptest.dir/regtest.cpp.o
CMakeFiles/cryptest.dir/fipsalgt.cpp.o CMakeFiles/cryptest.dir/dlltest.cpp.o
CMakeFiles/cryptest.dir/fipstest.cpp.o -o cryptest.exe libcryptopp.a
Undefined first referenced
symbol in file
bind libcryptopp.a(socketft.cpp.o)
recv libcryptopp.a(socketft.cpp.o)
send libcryptopp.a(socketft.cpp.o)
getservbyname libcryptopp.a(socketft.cpp.o)
getsockname libcryptopp.a(socketft.cpp.o)
accept libcryptopp.a(socketft.cpp.o)
listen libcryptopp.a(socketft.cpp.o)
gethostbyname libcryptopp.a(socketft.cpp.o)
socket libcryptopp.a(socketft.cpp.o)
setsockopt CMakeFiles/cryptest.dir/test.cpp.o
connect libcryptopp.a(socketft.cpp.o)
getpeername libcryptopp.a(socketft.cpp.o)
inet_addr libcryptopp.a(socketft.cpp.o)
shutdown libcryptopp.a(socketft.cpp.o)
ld: fatal: symbol referencing errors
gmake[2]: *** [cryptest.exe] Error 2
gmake[2]: Leaving directory `/export/home/cryptopp-build'
gmake[1]: *** [CMakeFiles/cryptest.dir/all] Error 2
gmake[1]: Leaving directory `/export/home/cryptopp-build'
gmake: *** [all] Error 2
Here's the CMakeList.tx file. It has not been checked in yet, so I have to dump it here:
$ cat CMakeLists.txt
# Please ensure your changes or patch meets minimum requirements.
# The minimum requirements are below, and they are 2.8.5. Please
# do not check in something for 2.8.12. To test your changes,
# please set up a Ubuntu 12.04 LTS system. Then, manually install
# CMake 2.8.5 from http://cmake.org/Wiki/CMake_Released_Versions.
cmake_minimum_required(VERSION 2.8.5 FATAL_ERROR)
project(cryptopp)
set(cryptopp_VERSION_MAJOR 5)
set(cryptopp_VERSION_MINOR 6)
set(cryptopp_VERSION_PATCH 5)
include(GNUInstallDirs)
include(TestBigEndian)
#============================================================================
# Settable options
#============================================================================
option(BUILD_STATIC "Build static library" ON)
option(BUILD_SHARED "Build shared library" ON)
option(BUILD_TESTING "Build library tests" ON)
option(BUILD_DOCUMENTATION "Use Doxygen to create the HTML based API documentation" OFF)
option(DISABLE_ASM "Disable ASM" OFF)
option(DISABLE_SSSE3 "Disable SSSE3" OFF)
option(DISABLE_AESNI "Disable AES-NI" OFF)
set(CRYPTOPP_DATA_DIR "" CACHE PATH "Crypto++ test data directory")
#============================================================================
# Internal compiler options
#============================================================================
# Don't use RPATH's. The resulting binary could fail a security audit.
if (NOT CMAKE_VERSION VERSION_LESS 2.8.12)
set(CMAKE_MACOSX_RPATH 0)
endif()
set(LIB_VER ${cryptopp_VERSION_MAJOR}${cryptopp_VERSION_MINOR}${cryptopp_VERSION_PATCH})
if(CMAKE_CXX_COMPILER_ID MATCHES "Intel")
add_definitions(-wd68 -wd186 -wd279 -wd327 -wd161 -wd3180)
endif()
# Endianess
TEST_BIG_ENDIAN(IS_BIG_ENDIAN)
if(IS_BIG_ENDIAN)
add_definitions(-DIS_BIG_ENDIAN)
endif()
if(DISABLE_ASM)
add_definitions(-DCRYPTOPP_DISABLE_ASM)
endif()
if(DISABLE_SSSE3)
add_definitions(-DCRYPTOPP_DISABLE_SSSE3)
endif()
if(DISABLE_AESNI)
add_definitions(-DCRYPTOPP_DISABLE_AESNI)
endif()
if(NOT CRYPTOPP_DATA_DIR STREQUAL "")
add_definitions(-DCRYPTOPP_DATA_DIR="${CRYPTOPP_DATA_DIR}")
endif()
if(WINDOWS_STORE OR WINDOWS_PHONE)
if("${CMAKE_SYSTEM_VERSION}" MATCHES "10\\.0.*")
SET( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /D\"_WIN32_WINNT=0x0A00\"" )
endif()
SET( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /FI\"winapifamily.h\"" )
endif()
#============================================================================
# Sources & headers
#============================================================================
# Library headers
file(GLOB cryptopp_HEADERS *.h)
# Test sources. You can use the GNUmakefile to generate the list: `make sources`.
file(GLOB cryptopp_SOURCES_TEST bench1.cpp bench2.cpp test.cpp validat1.cpp validat2.cpp validat3.cpp adhoc.cpp datatest.cpp regtest.cpp fipsalgt.cpp dlltest.cpp fipstest.cpp)
# Library sources. You can use the GNUmakefile to generate the list: `make sources`.
file(GLOB cryptopp_SOURCES *.cpp)
list(REMOVE_ITEM cryptopp_SOURCES
${CMAKE_CURRENT_SOURCE_DIR}/cryptlib.cpp
${CMAKE_CURRENT_SOURCE_DIR}/cpu.cpp
${CMAKE_CURRENT_SOURCE_DIR}/pch.cpp
${CMAKE_CURRENT_SOURCE_DIR}/simple.cpp
${CMAKE_CURRENT_SOURCE_DIR}/winpipes.cpp
${CMAKE_CURRENT_SOURCE_DIR}/cryptlib_bds.cpp
${cryptopp_SOURCES_TEST}
)
set(cryptopp_SOURCES
${CMAKE_CURRENT_SOURCE_DIR}/cryptlib.cpp
${CMAKE_CURRENT_SOURCE_DIR}/cpu.cpp
${cryptopp_SOURCES}
)
if(MINGW OR WIN32)
list(APPEND cryptopp_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/winpipes.cpp)
endif()
if(MSVC AND NOT DISABLE_ASM)
if(${CMAKE_GENERATOR} MATCHES ".*ARM")
message(STATUS "Disabling ASM because ARM is specified as target platform.")
else()
if(CMAKE_SIZEOF_VOID_P EQUAL 8)
list(APPEND cryptopp_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/x64dll.asm)
list(APPEND cryptopp_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/x64masm.asm)
set_source_files_properties(${CMAKE_CURRENT_SOURCE_DIR}/x64dll.asm PROPERTIES COMPILE_FLAGS "/D_M_X64")
set_source_files_properties(${CMAKE_CURRENT_SOURCE_DIR}/x64masm.asm PROPERTIES COMPILE_FLAGS "/D_M_X64")
set_source_files_properties(${CMAKE_CURRENT_SOURCE_DIR}/rdrand.asm PROPERTIES COMPILE_FLAGS "/D_M_X64")
else()
set_source_files_properties(${CMAKE_CURRENT_SOURCE_DIR}/x64dll.asm PROPERTIES COMPILE_FLAGS "/D_M_X86 /safeseh")
set_source_files_properties(${CMAKE_CURRENT_SOURCE_DIR}/x64masm.asm PROPERTIES COMPILE_FLAGS "/D_M_X86 /safeseh")
set_source_files_properties(${CMAKE_CURRENT_SOURCE_DIR}/rdrand.asm PROPERTIES COMPILE_FLAGS "/D_M_X86 /safeseh")
endif()
list(APPEND cryptopp_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/rdrand.asm)
enable_language(ASM_MASM)
endif()
endif()
#============================================================================
# Compile targets
#============================================================================
# Set global includes BEFORE adding any targets for legacy CMake versions
if(CMAKE_VERSION VERSION_LESS 2.8.12)
include_directories("${CMAKE_CURRENT_SOURCE_DIR}")
endif()
if(NOT CMAKE_VERSION VERSION_LESS 2.8.8)
add_library(cryptopp-object OBJECT ${cryptopp_SOURCES})
endif()
if (BUILD_STATIC)
if(NOT CMAKE_VERSION VERSION_LESS 2.8.8)
add_library(cryptopp-static STATIC $<TARGET_OBJECTS:cryptopp-object>)
else()
add_library(cryptopp-static STATIC ${cryptopp_SOURCES})
endif()
if (NOT CMAKE_VERSION VERSION_LESS 2.8.12)
target_include_directories(cryptopp-static PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}> $<INSTALL_INTERFACE:include/cryptopp>)
endif()
endif()
if (BUILD_SHARED)
if(NOT CMAKE_VERSION VERSION_LESS 2.8.8)
add_library(cryptopp-shared SHARED $<TARGET_OBJECTS:cryptopp-object>)
else()
add_library(cryptopp-shared SHARED ${cryptopp_SOURCES})
endif()
if (NOT CMAKE_VERSION VERSION_LESS 2.8.12)
target_include_directories(cryptopp-shared PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}> $<INSTALL_INTERFACE:include/cryptopp>)
endif()
endif()
# Set PIC
if(CMAKE_SIZEOF_VOID_P EQUAL 8)
# Enables -fPIC on all 64-bit platforms
if(NOT CMAKE_VERSION VERSION_LESS 2.8.9) # POSITION_INDEPENDENT_CODE support
set_target_properties(cryptopp-object PROPERTIES POSITION_INDEPENDENT_CODE TRUE)
elseif(NOT CMAKE_VERSION VERSION_LESS 2.8.8) # Object library support
get_target_property(flags_old cryptopp-object COMPILE_FLAGS)
set_target_properties(cryptopp-object PROPERTIES COMPILE_FLAGS "${flags_old} -fPIC")
else()
if (BUILD_STATIC)
get_target_property(flags_old_static cryptopp-static COMPILE_FLAGS)
if(NOT flags_old_static)
set(flags_old_static "")
endif()
set_target_properties(cryptopp-static PROPERTIES COMPILE_FLAGS "${flags_old_static} -fPIC")
endif()
if (BUILD_SHARED)
get_target_property(flags_old_shared cryptopp-shared COMPILE_FLAGS)
if(NOT flags_old_shared)
set(flags_old_shared "")
endif()
set_target_properties(cryptopp-shared PROPERTIES COMPILE_FLAGS "${flags_old_shared} -fPIC")
endif()
endif()
endif()
# Set filenames for targets to be "cryptopp"
if(NOT MSVC)
set(COMPAT_VERSION ${cryptopp_VERSION_MAJOR}.${cryptopp_VERSION_MINOR})
if (BUILD_STATIC)
set_target_properties(cryptopp-static
PROPERTIES
OUTPUT_NAME cryptopp)
endif()
if (BUILD_SHARED)
set_target_properties(cryptopp-shared
PROPERTIES
SOVERSION ${COMPAT_VERSION}
OUTPUT_NAME cryptopp)
endif()
endif()
# Targets, compatible with Crypto++ GNUMakefile
if (BUILD_STATIC)
add_custom_target(static)
add_dependencies(static cryptopp-static)
endif()
if (BUILD_SHARED)
add_custom_target(dynamic)
add_dependencies(dynamic cryptopp-shared)
endif()
#============================================================================
# Third-party libraries
#============================================================================
if(WIN32)
if (BUILD_STATIC)
target_link_libraries(cryptopp-static ws2_32)
endif()
if (BUILD_SHARED)
target_link_libraries(cryptopp-shared ws2_32)
endif()
endif()
if(SunPro)
target_link_libraries(cryptopp-shared nsl socket)
target_link_libraries(cryptest nsl socket)
endif()
find_package(Threads)
if (BUILD_STATIC)
target_link_libraries(cryptopp-static ${CMAKE_THREAD_LIBS_INIT})
endif()
if (BUILD_SHARED)
target_link_libraries(cryptopp-shared ${CMAKE_THREAD_LIBS_INIT})
endif()
#============================================================================
# Tests
#============================================================================
enable_testing()
if(BUILD_TESTING)
add_executable(cryptest ${cryptopp_SOURCES_TEST})
target_link_libraries(cryptest cryptopp-static)
# Setting "cryptest" binary name to "cryptest.exe"
if(NOT WIN32)
set_target_properties(cryptest PROPERTIES OUTPUT_NAME cryptest.exe)
endif()
if(NOT TARGET cryptest.exe)
add_custom_target(cryptest.exe)
add_dependencies(cryptest.exe cryptest)
endif()
file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/TestData DESTINATION ${PROJECT_BINARY_DIR})
file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/TestVectors DESTINATION ${PROJECT_BINARY_DIR})
add_test(NAME build_cryptest COMMAND "${CMAKE_COMMAND}" --build ${CMAKE_BINARY_DIR} --target cryptest)
add_test(NAME cryptest COMMAND $<TARGET_FILE:cryptest> v)
set_tests_properties(cryptest PROPERTIES DEPENDS build_cryptest)
endif()
#============================================================================
# Doxygen documentation
#============================================================================
if(BUILD_DOCUMENTATION)
find_package(Doxygen REQUIRED)
set(in_source_DOCS_DIR "${CMAKE_CURRENT_SOURCE_DIR}/html-docs")
set(out_source_DOCS_DIR "${PROJECT_BINARY_DIR}/html-docs")
add_custom_target(docs ALL
COMMAND ${DOXYGEN_EXECUTABLE} Doxyfile -d CRYPTOPP_DOXYGEN_PROCESSING
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/Doxyfile
)
if(NOT ${in_source_DOCS_DIR} STREQUAL ${out_source_DOCS_DIR})
add_custom_command(
TARGET docs POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_directory "${in_source_DOCS_DIR}" "${out_source_DOCS_DIR}"
COMMAND ${CMAKE_COMMAND} -E remove_directory "${in_source_DOCS_DIR}"
)
endif()
endif()
#============================================================================
# Install
#============================================================================
set(export_name "cryptopp-targets")
# Runtime package
if (BUILD_SHARED)
install(
TARGETS cryptopp-shared
EXPORT ${export_name}
DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
)
endif()
# Development package
if (BUILD_STATIC)
install(TARGETS cryptopp-static EXPORT ${export_name} DESTINATION ${CMAKE_INSTALL_LIBDIR})
endif()
install(FILES ${cryptopp_HEADERS} DESTINATION include/cryptopp)
# CMake Package
if(NOT CMAKE_VERSION VERSION_LESS 2.8.8) # CMakePackageConfigHelpers is supported from 2.8.8
include(CMakePackageConfigHelpers)
write_basic_package_version_file("${PROJECT_BINARY_DIR}/cryptopp-config-version.cmake" VERSION ${cryptopp_VERSION_MAJOR}.${cryptopp_VERSION_MINOR}.${cryptopp_VERSION_PATCH} COMPATIBILITY SameMajorVersion)
install(FILES cryptopp-config.cmake ${PROJECT_BINARY_DIR}/cryptopp-config-version.cmake DESTINATION "lib/cmake/cryptopp")
install(EXPORT ${export_name} DESTINATION "lib/cmake/cryptopp")
endif()
# Tests
if(BUILD_TESTING)
install(TARGETS cryptest DESTINATION ${CMAKE_INSTALL_BINDIR})
install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/TestData DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/cryptopp)
install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/TestVectors DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/cryptopp)
endif()
# Documentation
if(BUILD_DOCUMENTATION)
install(DIRECTORY "${out_source_DOCS_DIR}" DESTINATION ${CMAKE_INSTALL_DOCDIR})
endif()
I would like to build a MPI program with VTK, Boost and SQLite3 library using CMake. First, I built a simple MPI program without other libraries using a CMakeLists.cmake file like this:
cmake_minimum_required(VERSION 2.6)
PROJECT(testMPI)
FIND_PATH(MPI_INTEL_C mpicc $ENV{PATH})
FIND_PATH(MPI_INTEL_CXX mpicxx $ENV{PATH})
IF(MPI_INTEL_C AND MPI_INTEL_CXX)
MESSAGE(STATUS "Intel MPI compiler is used.")
SET(CMAKE_CXX_COMPILER mpicxx)
SET(CMAKE_C_COMPILER mpicc)
ENDIF(MPI_INTEL_C AND MPI_INTEL_CXX)
SET(EXECUTABLE_OUTPUT_PATH ${testMPI_SOURCE_DIR}/bin)
SET(SRC_LIST testMPI.cpp)
ADD_EXECUTABLE(testMPI ${SRC_LIST})
FIND_PATH(MPI_H_INCLUDE mpi.h $ENV{PATH})
IF(NOT MPI_H_INCLUDE)
MESSAGE(FATAL_ERROR "mpi.h not found")
ENDIF(NOT MPI_H_INCLUDE)
INCLUDE_DIRECTORIES(${MPI_H_INCLUDE})
IF(MPI_INTEL_C AND MPI_INTEL_CXX)
SET_TARGET_PROPERTIES(testMPI PROPERTIES LINK_FLAGS -i-dynamic)
ELSE(MPI_INTEL_C AND MPI_INTEL_CXX)
FIND_LIBRARY(MPI_CXX_LIB mpichcxx $ENV{PATH})
IF(NOT MPI_CXX_LIB)
MESSAGE(FATAL_ERROR "mpich2 library not found")
ENDIF(NOT MPI_CXX_LIB)
TARGET_LINK_LIBRARIES(testMPI ${MPI_CXX_LIB})
FIND_LIBRARY(MPI_LIB mpich $ENV{PATH})
IF(NOT MPI_LIB)
MESSAGE(FATAL_ERROR "mpich2 library not found")
ENDIF(NOT MPI_LIB)
TARGET_LINK_LIBRARIES(testMPI ${MPI_LIB})
ENDIF(MPI_INTEL_C AND MPI_INTEL_CXX)
I used mpirun -np 8 -nolocal -machinefile ./machinefile ./testMPI to run the program successfully, and the returned number of processes was correct (=8).
And then, I just put some headers of VTK, Boost and SQLite3 library into this simple program (.cpp), and used the following CMakeLists.cmake to find, include and link these libraries. The program was built successfully, also I used mpirun -np 8 -nolocal -machinefile ./machinefile ./testMPI to run this program, but the returned number of processes was wrong (=1). So how to build a MPI program with other libraries using CMake? Thank you in advance!
cmake_minimum_required(VERSION 2.6)
PROJECT(testMPI)
SET(EXECUTABLE_OUTPUT_PATH ${testMPI_SOURCE_DIR}/bin)
aux_source_directory(. DIR_SRCS)
ADD_EXECUTABLE(testMPI ${DIR_SRCS})
install(TARGETS testMPI DESTINATION bin)
SET(VTK_DIR "/export/home/hh/hh/vtk/")
SET(VTK_LIBRARIES libLSDyna.so libMapReduceMPI.so libmpistubs.so libvtkalglib.so libvtkCharts.so libvtkCommon.so libvtkDICOMParser.so libvtkexoIIc.so libvtkexpat.so libvtkFiltering.so libvtkfreetype.so libvtkftgl.so libvtkGenericFiltering.so libvtkGeovis.so libvtkGraphics.so libvtkhdf5_hl.so libvtkhdf5.so libvtkHybrid.so libvtkImaging.so libvtkInfovis.so libvtkIO.so libvtkjpeg.so libvtklibxml2.so libvtkmetaio.so libvtkNetCDF_cxx.so libvtkNetCDF.so libvtkpng.so libvtkproj4.so libvtkRendering.so libvtksqlite.so libvtksys.so libvtktiff.so libvtkverdict.so libvtkViews.so libvtkVolumeRendering.so libvtkWidgets.so libvtkzlib.so)
SET(VTK_LIBRARIES_DIRS)
foreach(libs ${VTK_LIBRARIES})
set(FOUND "FOUND-NOTFOUND")
find_library(FOUND ${libs} "/export/home/hh/hh/vtk/lib/vtk-5.10")
list(APPEND VTK_LIBRARIES_DIRS ${FOUND})
endforeach(libs)
find_package(VTK REQUIRED)
IF(VTK_FOUND)
MESSAGE(STATUS "VTK IS USED")
INCLUDE(${VTK_USE_FILE})
ELSE()
MESSAGE(FATAL_ERROR "VTK IS NOT FOUND")
ENDIF(VTK_FOUND)
TARGET_LINK_LIBRARIES(testMPI ${VTK_LIBRARIES_DIRS})
LIST (APPEND CMAKE_INCLUDE_PATH "/export/home/hh/hh/boost/include")
LIST (APPEND CMAKE_LIBRARY_PATH "/export/home/hh/hh/boost/lib")
FIND_PACKAGE(Boost REQUIRED)
IF(Boost_FOUND)
MESSAGE(STATUS "Boost IS USED")
INCLUDE_DIRECTORIES(${Boost_INCLUDE_DIRS})
ELSE(Boost_FOUND)
MESSAGE(FATAL_ERROR "Boost IS NOT FOUND")
ENDIF(Boost_FOUND)
TARGET_LINK_LIBRARIES(testMPI ${Boost_LIBRARIES})
LIST(APPEND CMAKE_INCLUDE_PATH "/export/home/hh/hh/sqlite/include")
LIST(APPEND CMAKE_LIBRARY_PATH "/export/home/hh/hh/sqlite/lib")
LIST(APPEND CMAKE_MODULE_PATH "${testMPI_SOURCE_DIR}/cmake")
FIND_PACKAGE(SQLite3 REQUIRED)
IF(SQLITE3_FOUND)
MESSAGE(STATUS "SQLite3 IS USED")
INCLUDE_DIRECTORIES(${SQLITE3_INCLUDE_DIRS})
ELSE(SQLITE3_FOUND)
MESSAGE(FATAL_ERROR "SQLite3 IS NOT FOUND")
ENDIF(SQLITE3_FOUND)
TARGET_LINK_LIBRARIES(testMPI ${SQLITE3_LIBRARIES})
FIND_PACKAGE(MPI REQUIRED)
IF(MPI_FOUND)
MESSAGE(STATUS "MPI IS USED")
INCLUDE_DIRECTORIES(${MPI_INCLUDE_PATH})
ELSE(SQLITE3_FOUND)
MESSAGE(FATAL_ERROR "MPI IS NOT FOUND")
ENDIF(MPI_FOUND)
TARGET_LINK_LIBRARIES(testMPI ${MPI_LIBRARIES})