I am trying to generate .msi installer with cmake. I am able to generate .dll and .lib files with some configuration in CMakeLists.txt. Please provide an example CMakeLists.txt to generate an .msi installer. What are the commands that I need to use in the command prompt ?
The commands that I am using so far are:
> cmake -G"Visual Studio 10" -H"Root CMakeLists.txt path" -B"path to generate the sln"
> cmake --build "path of the sln" --config Release
> cpack -C Release
output: CPack Error: CPack generator not specified
I used the following configuration to generate the .dll and .lib files.
Here is my CMakeLists.txt:
CMAKE_MINIMUM_REQUIRED(VERSION 2.8)
PROJECT(mydll)
INCLUDE_DIRECTORIES(common/include)
SET(my_lib_src dllmain.cpp mydll.cpp )
SET_SOURCE_FILES_PROPERTIES(${my_lib_src} PROPERTIES LANGUAGE C)
ADD_LIBRARY(mydll SHARED ${my_lib_src})
SET_TARGET_PROPERTIES(mydll PROPERTIES
LINKER_LANGUAGE C
RUNTIME_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/common/bin
RUNTIME_OUTPUT_DIRECTORY_DEBUG ${CMAKE_SOURCE_DIR}/common/bin
ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/common/lib
ARCHIVE_OUTPUT_DIRECTORY_DEBUG ${CMAKE_SOURCE_DIR}/common/lib)
install(TARGETS mydll
ARCHIVE
DESTINATION lib
COMPONENT libraries)
install(FILES mydll.h
DESTINATION include
COMPONENT headers)
set(CPACK_GENERATOR WIX)
set(CPACK_PACKAGE_NAME "mydll")
set(CPACK_PACKAGE_VENDOR "CMake.org")
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "MyLib - CPack Component Installation Example")
set(CPACK_PACKAGE_VERSION "1.0.0")
set(CPACK_PACKAGE_VERSION_MAJOR "1")
set(CPACK_PACKAGE_VERSION_MINOR "0")
set(CPACK_PACKAGE_VERSION_PATCH "0")
set(CPACK_PACKAGE_INSTALL_DIRECTORY "CPack Component Example")
INCLUDE(CPack)
You need to set the generator when you run cpack so instead of
3) cpack -C Release
output: CPack Error: CPack generator not specified
You should specify
cpack -G WIX -C Release
The WiX capability was added in CMake 2.8.11
It appears that MSI is not in the list of CPack Generators, although there are patches to CPack that enable this functionality.
See:
http://annealingtechnologies.blogspot.com/2010/02/wix-and-cpack-integration.html
Related
I am writng a script for appveyor.
I need to use boost libraries in my c++ project.
In my appveyor script I have written these lines:
set INCLUDE=C:\Libraries\boost_1_67_0;%INCLUDE%
cd C:\Libraries\boost_1_67_0
dir
.\bootstrap.bat
.\b2 --with-iostreams runtime-link=static --build-type=complete
set LIB=C:\Libraries\boost_1_67_0\stage\lib;%LIB%
but that gives an error on .\bootstrap.bat
.\bootstrap.bat
Building Boost.Build engine
Failed to build Boost.Build engine.
Please consult bootstrap.log for further diagnostics.
Command exited with code 1
you could find the log of appveyor at https://ci.appveyor.com/project/srbcheema1/vcf-demo/build/1.0.32
my CMakeLists.txt is like :
cmake_minimum_required (VERSION 2.8.9)
project (reader-demo CXX C)
set (CMAKE_BUILD_TYPE "Release" CACHE STRING "Choose the type of build" FORCE)
set (CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /MT")
set(Boost_USE_STATIC_LIBS ON)
add_executable(reader uncompress.cpp)
how could I use the boost libraries in appveyor ?
There is no need to manually install a recent version of boost. It is already there and precompiled. Just make sure your to pass the correct path to your build configuration for using boost headers and the appropriate linkder flag. For a cmake build, this would be
cmake -DBOOST_ROOT=C:\Libraries\boost_1_67_0 path\to\your\source
this is a simplified version of my cmake
cmake_minimum_required(VERSION 2.8.4)
project(math)
add_library(math math.cpp)
function(install_package)
install(TARGETS math
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib)
add_custom_command(TARGET math
POST_BUILD
COMMAND cmake ARGS -P cmake_install.cmake)
endfunction()
install_package()
But when I build Debug version I get the following error
CMake Error at cmake_install.cmake:55 (file):
file INSTALL cannot find
"<my project's root>/build/Release/math.lib".
Why is it looking in Release folder despite that I build for Debug?
When I build for Release then, obviously, everything works.
I tried to add CONFIGURATIONS option to install method, but it doesn't help.
I'm using Visual Studio 15.
If I look into my cmake_install.cmake, Release is the default if you don't specify anything in your add_custom_command() call:
# Set the install configuration name.
if(NOT DEFINED CMAKE_INSTALL_CONFIG_NAME)
if(BUILD_TYPE)
string(REGEX REPLACE "^[^A-Za-z0-9_]+" ""
CMAKE_INSTALL_CONFIG_NAME "${BUILD_TYPE}")
else()
set(CMAKE_INSTALL_CONFIG_NAME "Release")
endif()
message(STATUS "Install configuration: \"${CMAKE_INSTALL_CONFIG_NAME}\"")
endif()
So if you look into INSTALL.vcxproj the call that CMake is generating looks like:
"C:\Program Files\CMake\bin\cmake.exe" -DBUILD_TYPE=$(Configuration) -P cmake_install.cmake
Which would translate into:
add_custom_command(TARGET math
POST_BUILD
COMMAND ${CMAKE_COMMAND} ARGS -D BUILD_TYPE=$<CONFIG> -P cmake_install.cmake)
I have a simple setup with main.cpp, mainwindows.cpp, mainwindow.h, and mainwindow.ui with this cmake file :
cmake_minimum_required(VERSION 3.1.0 FATAL_ERROR)
project(test_qt_with_cmake)
set(CMAKE_CXX_STANDARD 11) # use c++11
# Find includes in corresponding build directories
set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_PREFIX_PATH "C:/Qt/5.8/msvc2015_64")
# Instruct CMake to run moc automatically when needed.
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTOUIC ON)
find_package(Qt5Widgets)
set(PROJECT_INCLUDE_DIR "${PROJECT_SOURCE_DIR}")
######## PROJECT DEPENDENCIES #########
if(WIN32)
set(CMAKE_PREFIX_PATH ${CMAKE_PREFIX_PATH} ${PROJECT_SOURCE_DIR}/windows)
endif()
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${PROJECT_SOURCE_DIR}/cmake")
#=====================================
include_directories(
${PROJECT_INCLUDE_DIR}
)
add_executable(test_qt WIN32 main.cpp mainwindow.cpp mainwindow.h)
target_link_libraries(test_qt Qt5::Widgets)
add_custom_command(TARGET test_qt POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_directory
"${PROJECT_SOURCE_DIR}/windows/bin"
$<TARGET_FILE_DIR:test_qt>)
The ui_xxx.h is generated the first time i build the project and regenerated if the .ui file and one of source file is changed. What i would like is to get the ui_xxx.h to get regenerated everytime .ui file is changed with or without source change.
I've taken a look at https://github.com/euler0/mini-cmake-qt but the example_automoc project is always out of date and vs always ask to rebuild the project.
Is there something wrong in my cmake file? or is it a bug in cmake?
note: i'm using qt 5.8 with cmake 3.6 on windows 10 using visual studio 14 2015 generator
update : removing set(CMAKE_AUTOUIC ON) and specifying the ui file with :
qt5_wrap_ui(UI_HEADERS mainwindow.ui)
seems to solve the problem. The original question is still valid, which is how to make this work without specifying the .ui file (by calling qt5_wrap_ui) ?
I'm using win7-32bit + cmake + vs2013's NMake.exe to build exe, I need the exe be able to run on WinXP, I know how to do that with vs2013 IDE(set the Platform-Toolset to v120xp), but I'm not using the IDE, I just use its NMake. This is how I generate the project file and exe:
build> cmake -G "NMake Makefiles" ..
build> nmake
Question 1: In the CMakeLists.txt, how to set it use v120xp?
Question 2: Is it necessary to build all static lib with the v120xp? Or just the exe?
Try setting CMAKE_GENERATOR_TOOLSET. It allows selecting the toolset for Genertors that support it. Generators that support Toolsets are Visual Studio and XCode.
Your call to CMake should look like this:
cmake -G "NMake Makefiles" -DCMAKE_GENERATOR_TOOLSET=v120_xp ..
Update 1: As pointed out in the comments NMake doesn't support Toolsets
Thes solution is to specify
SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /SUBSYSTEM:CONSOLE,5.01")
for console applications, or
SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /SUBSYSTEM:WINDOWS,5.01")
for windows applications.
I want to build the package uci for ubuntu.
I download the source package and I found into the C files, header files and CMakeLists.txt
How to build the uci project with cmake?
CMakeLists.txt:
cmake_minimum_required(VERSION 2.6)
PROJECT(uci C)
SET(CMAKE_INSTALL_PREFIX /usr)
ADD_DEFINITIONS(-Os -Wall -Werror --std=gnu99 -g3 -I. -DUCI_PREFIX="${CMAKE_INSTALL_PREFIX}")
OPTION(UCI_PLUGIN_SUPPORT "plugin support" ON)
OPTION(UCI_DEBUG "debugging support" OFF)
OPTION(UCI_DEBUG_TYPECAST "typecast debugging support" OFF)
OPTION(BUILD_LUA "build Lua plugin" ON)
CONFIGURE_FILE( ${CMAKE_SOURCE_DIR}/uci_config.h.in ${CMAKE_SOURCE_DIR}/uci_config.h )
SET(LIB_SOURCES libuci.c file.c util.c delta.c parse.c)
ADD_LIBRARY(uci-shared SHARED ${LIB_SOURCES})
SET_TARGET_PROPERTIES(uci-shared PROPERTIES OUTPUT_NAME uci)
TARGET_LINK_LIBRARIES(uci-shared dl)
ADD_LIBRARY(uci-static STATIC ${LIB_SOURCES})
SET_TARGET_PROPERTIES(uci-static PROPERTIES OUTPUT_NAME uci)
ADD_EXECUTABLE(cli cli.c)
SET_TARGET_PROPERTIES(cli PROPERTIES OUTPUT_NAME uci)
TARGET_LINK_LIBRARIES(cli uci-shared dl)
ADD_EXECUTABLE(cli-static cli.c)
SET_TARGET_PROPERTIES(cli-static PROPERTIES OUTPUT_NAME uci-static)
TARGET_LINK_LIBRARIES(cli-static uci-static dl)
ADD_LIBRARY(ucimap STATIC ucimap.c)
ADD_EXECUTABLE(ucimap-example ucimap-example.c)
TARGET_LINK_LIBRARIES(ucimap-example uci-static ucimap dl)
ADD_SUBDIRECTORY(lua)
INSTALL(FILES uci.h uci_config.h ucimap.h
DESTINATION include
)
INSTALL(TARGETS uci-shared uci-static cli cli-static
ARCHIVE DESTINATION lib
LIBRARY DESTINATION lib
RUNTIME DESTINATION bin
)
I don't know about this particular case, but the generic mode of operation with CMake is as follows. Let's assume you unpacked the package sources so that the CMakeList is located at /some/path/to/source/CMakeLists.txt. Then:
> cd /path/where/you/want/to/build
> mkdir package_name
> cd package_name
> cmake /some/path/to/source
Next, an optional step to launch (console) GUI to edit options, if necessary:
> ccmake
After you're happy with the setup:
> make
> make install
CMake also has a non-console GUI, but I've never used it on Unix, so I can't comment there. The basic idea would be the same, though: set up a build directory, point the GUI to the source directory (the one containing CMakeLists.txt), configure, modify uptions and reconfigure as necessary, generate Makefiles, exit GUI and run make.