I am trying copy certain dll's to Output folder where the generated binary resides and some of the dll's are visual studio version specific. I tried something similar to below template but it gives me errors.
INSTALL(FILES
../x.dll
../y.dll
../z.dll
IF(${CMAKE_GENERATOR} STREQUAL "Visual Studio 12 2013")
../xyz.dll
ELSE()
../xy.dll
ENDIF()
DESTINATION ${CMAKE_CURRENT_SOURCE_DIR}/Release)
Where am i going wrong? (I am new to CMAKE)
I solved my issue with below template.
IF(${CMAKE_GENERATOR} STREQUAL "Visual Studio 12 2013")
SET (VS_DEPENDENT_DLL ../xyz.dll)
ELSE()
SET (VS_DEPENDENT_DLL ../xy.dll)
ENDIF()
INSTALL(FILES
../x.dll
../y.dll
../z.dll
${VS_DEPENDENT_DLL}
DESTINATION ${CMAKE_CURRENT_SOURCE_DIR}/Release)
Related
I've written a CMakeLists.txt as shown below:
cmake_minimum_required (VERSION 3.22)
project(tutorial)
set(wxWidgets_CONFIGURATION mswu)
find_package(wxWidgets REQUIRED COMPONENTS net core base)
include(${wxWidgets_USE_FILE})
add_executable(tutorial main.cpp)
target_link_libraries(tutorial ${wxWidgets_LIBRARIES})
install(TARGETS tutorial DESTINATION bin)
include(InstallRequiredSystemLibraries)
set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/License.txt")
set(CPACK_PACKAGE_VERSION_MAJOR "0")
set(CPACK_PACKAGE_VERSION_MINOR "1")
include(CPack)
As you might guess, this is WxWidgets application.
Look at the bottom. It includes InstallRequiredSystemLibraries and CPack.
With this cmake I have generated a NSIS Cpack installer "tutorial-0.1.1-win64.exe".
But this installer only installs the project binary and some runtime libraries. It doesn't install any WxWidgets library. So the project binary fails to run on other systems that is not installed WxWidgets libraries.
I'd like to make NSIS Cpack installer installs WxWidgets DLL libraries also.
How can I make it?
See! Those binaries are needed to be installed! But NSIS Cpack installer doesn't install wxbase315ud_vc14x_x64.dll and wxmsw315ud_core_vc14x_x64.dll
I am working on Windows 10
I don't want to statically link to the WxWidgets libraries. I'd like to make it link dynamically with shared libraries.
There exists a previous talk for the similar subject :
Including external libraries in cpack output
I tried this way and it works :
cmake_minimum_required (VERSION 3.22)
project(tutorial)
if(CMAKE_BUILD_TYPE MATCHES Release)
message("release mode")
set(wxWidgets_CONFIGURATION mswu)
else()
message("debug mode")
set(wxWidgets_CONFIGURATION mswud)
endif()
find_package(wxWidgets REQUIRED COMPONENTS net core base)
include(${wxWidgets_USE_FILE})
add_executable(tutorial main.cpp)
target_link_libraries(tutorial ${wxWidgets_LIBRARIES})
install(TARGETS tutorial DESTINATION bin)
if(CMAKE_BUILD_TYPE MATCHES Release)
install(FILES ${wxWidgets_LIB_DIR}/wxbase315u_vc_custom.dll DESTINATION bin)
install(FILES ${wxWidgets_LIB_DIR}/wxmsw315u_core_vc_custom.dll DESTINATION bin)
else()
install(FILES ${wxWidgets_LIB_DIR}/wxbase315ud_vc_custom.dll DESTINATION bin)
install(FILES ${wxWidgets_LIB_DIR}/wxmsw315ud_core_vc_custom.dll DESTINATION bin)
endif()
include(InstallRequiredSystemLibraries)
set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/License.txt")
set(CPACK_PACKAGE_VERSION_MAJOR "0")
set(CPACK_PACKAGE_VERSION_MINOR "1")
include(CPack)
Look I added this below :
if(CMAKE_BUILD_TYPE MATCHES Release)
install(FILES ${wxWidgets_LIB_DIR}/wxbase315u_vc_custom.dll DESTINATION bin)
install(FILES ${wxWidgets_LIB_DIR}/wxmsw315u_core_vc_custom.dll DESTINATION bin)
else()
install(FILES ${wxWidgets_LIB_DIR}/wxbase315ud_vc_custom.dll DESTINATION bin)
install(FILES ${wxWidgets_LIB_DIR}/wxmsw315ud_core_vc_custom.dll DESTINATION bin)
endif()
And It works as I wanted!
Currently looking into testing for windows and linux with cmake. I've made a small project that I want to build and test on both. Building works for me. And I've added a dependency to boost test to add a very simple test.
For windows, this test shows up in the test explorer of visual studio and I can run the test fine from there or use the command line.
For Linux, I can run the testproject from the commandline, but my test don't show up in the Test Explorer.
Question
Is adding boost test for a linux build to the Test Explorer not possible at the moment with visual studio? Or is there something wrong with my approach?
I'll include the CMake of the testproject below. If you'd like to see the whole project pls visit https://github.com/gertkommer/BoostTestCmakeExample
Using Visual Studio 2019 pro 16.5.3
cmake_minimum_required (VERSION 3.16)
find_package( Boost 1.70.0 REQUIRED COMPONENTS system filesystem unit_test_framework)
project(MyProject_test)
add_executable (${PROJECT_NAME}
"BoostTest_test.cpp"
)
add_definitions(-DBOOST_TEST_DYN_LINK)
#set(BOOST_LIBRARIES Boost::unit_test_framework Boost::system Boost::filesystem)
if (WIN32)
if (CMAKE_BUILD_TYPE MATCHES "Debug")
set(BOOST_LIBRARIES ${Boost_LIBRARY_DIR_DEBUG}/boost_unit_test_framework-vc140-mt-gd.lib
${Boost_LIBRARY_DIR_DEBUG}/boost_system-vc140-mt-gd.lib
${Boost_LIBRARY_DIR_DEBUG}/boost_filesystem-vc140-mt-gd.lib
)
endif()
endif()
if(UNIX)
set(BOOST_LIB_DIR ${Boost_LIBRARY_DIRS}/libboost_unit_test_framework.so)
if (CMAKE_BUILD_TYPE MATCHES "Debug")
set(BOOST_LIBRARIES ${Boost_LIBRARY_DIR_DEBUG}/libboost_unit_test_framework.so
${Boost_LIBRARY_DIR_DEBUG}/libboost_system.so
${Boost_LIBRARY_DIR_DEBUG}/libboost_filesystem.so
)
endif()
endif()
target_include_directories(${PROJECT_NAME}
PUBLIC ${Boost_INCLUDE_DIR}
)
target_link_libraries(${PROJECT_NAME}
${BOOST_LIBRARIES}
MyProject
)
add_test(MyBoostModule ${PROJECT_NAME})
I have a project, dependent on the rt library, that shows undeclared errors for functions ddefined in LIBRT when using make following running the "cmake .". I've looked at the plethora of suggestions for questions similar to this but none worked for me. Using the functions check_include_files() and check_library_exists() return TRUE, and it appears I succeed in finding the library using find_library(). I even get "-lrt" appended at the end of the link.txt file.
Anyways, I am a bit stumped and looking for some guidance. Below is my CMakeLists.txt file:
cmake_minimum_required (VERSION 3.5)
project (proj_name C)
enable_language(C)
set (SOURCES
/source/file/path
)
add_definitions (-std=c99)
add_executable (proj_name ${SOURCES})
find_library(LIBRT rt)
if(LIBRT)
target_include_directories (proj_name PUBLIC ${PROJECT_SOURCE_DIR}
/proj/includes/path #not including rt header path
${RT_INCLUDE_DIRS}
)
target_link_libraries(proj_name PUBLIC ${LIBRT})
endif(LIBRT)
set(CMAKE_C_COMPILER /usr/bin/gcc)
include(CheckIncludeFiles)
check_include_files(mqueue.h HAVE_MQUEUE_H)
if(NOT HAVE_MQUEUE_H)
message(FATAL_ERROR "mqueue.h not found")
endif(NOT HAVE_MQUEUE_H)
include(CheckLibraryExists)
check_library_exists(rt timer_gettime "" HAVE_RT)
if(NOT HAVE_RT)
message(FATAL_ERROR "timer_gettime not found")
endif(NOT HAVE_RT)
Running on WSL Ubuntu.
Thanks for any insight possible!
I need to install SFML by sources but I can't run cmake because a package is not installed (xcb-image)
I installed this packages by sources, but how can I tell CMake that this package is installed, and that it needs to look at a special directory?
if(NOT SFML_OPENGL_ES)
find_package(OpenGL REQUIRED)
include_directories(${OPENGL_INCLUDE_DIR})
if(SFML_OS_LINUX OR SFML_OS_FREEBSD)
find_package(XCB COMPONENTS xlib_xcb image randr REQUIRED)
if(NOT LIBXCB_FOUND)
message(FATAL_ERROR "Xcb library not found")
endif()
include_directories(${LIBXCB_INCLUDE_DIRS})
endif()
endif()
I don't have root access.
Try adding your xcb /include and /lib directory to your CMakeLists, by adding the following lines :
INCLUDE_DIRECTORIES(/path/to/your/xcb/include)
LINK_DIRECTORIES(/path/to/your/xcb/lib)
Otherwise, if that didn't work and you have a cmake file for cxb (sth like xcb.cmake), Create a folder named cmake/Modules/ under your project root, add xcb.cmake under that folder, and in the root CMakeLists.txt, include the following code:
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/Modules/")
For a better understanding, take a look at CMake:How To Find Libraries
Hope that helps !
My question is very similar to CMake : Changing name of Visual Studio and Xcode exectuables depending on configuration in a project generated by CMake. In that post the output file name will change according to the project configuration (Debug, Release and so on). I want to go further. When I know the configuration of the project, I want to tell the executable program to link different library names depending on project configurations. I was wondering whether there is a variable in CMake that can tell the project configuration. If there exists such a variable, my task will become easier:
if (Project_Configure_Name STREQUAL "Debug")
#do some thing
elseif (Project_Configure_Name STREQUAL "Release")
#do some thing
endif()
According to http://cmake.org/cmake/help/v2.8.8/cmake.html#command:target_link_libraries, you can specify libraries according to the configurations, for example:
target_link_libraries(mytarget
debug mydebuglibrary
optimized myreleaselibrary
)
Be careful that the optimized mode means every configuration that is not debug.
Following is a more complicated but more controllable solution:
Assuming you are linking to an imported library (not compiled in your cmake project), you can add it using:
add_library(foo STATIC IMPORTED)
set_property(TARGET foo PROPERTY IMPORTED_LOCATION_RELEASE c:/path/to/foo.lib)
set_property(TARGET foo PROPERTY IMPORTED_LOCATION_DEBUG c:/path/to/foo_d.lib)
add_executable(myexe src1.c src2.c)
target_link_libraries(myexe foo)
See http://www.cmake.org/Wiki/CMake/Tutorials/Exporting_and_Importing_Targets for more details.
There is always another way:
if(CMAKE_BUILD_TYPE MATCHES "release")
SET(CMAKE_BUILD_TYPE ${CMAKE_BUILD_TYPE})
else(CMAKE_BUILD_TYPE MATCHES "debug")
SET(CMAKE_BUILD_TYPE "debug")
endif(CMAKE_BUILD_TYPE MATCHES "release")
We can use the variable CMAKE_BUILD_TYPE. We can also change this variable at the beginning of invoking CMAKE:
cmake .. -DCMAKE_BUILD_TYPE:STRING=debug
Then we can use this variable as an indicator of build configuration.