How to add allegro Library in CMake? - cmake

What's the path I must to put in cmakelist?
cmake_minimum_required(VERSION 3.17)
project(trabajo)
set(CMAKE_CXX_STANDARD 14)
add_executable(trabajo main.cpp)
target_link_libraries(trabajo - lmingw32 - allegro_acodec-5.0.10-md-debug)

Related

target_link_libraries(${target} PUBLIC CGAL::Eigen3_support), what libs linked in this one?

My question is what libs linked about CGAL::Eigen3_support?
# CMakeList.txt : CMake project for XXX, include source and define
project specific logic here.
cmake_minimum_required (VERSION 3.8)
include_directories("/usr/include/eigen3")
TODO: Add tests and install targets if needed.
find_package(CGAL REQUIRED)
find_package(Eigen3 3.4.0 REQUIRED) #(3.1.0 or greater)
include(CGAL_Eigen3_support)
if(NOT TARGET CGAL::Eigen3_support)
message(
STATUS "This project requires the Eigen library, and will not be compiled.")
return()
endif()
create_single_source_cgal_program("XXX.cpp")
foreach(target XXX)
target_link_libraries(${target} PUBLIC CGAL::Eigen3_support)
endforeach()

How can I make CPACK include 3rd party DLLs into the installer?

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!

Problem using FetchContent_Declare together with shared library

I'm having problem using FetchContent_Declare with a shared library. I'm trying to apply a modular design (instead of creating one mega-repository with 20 modules I'm allocating a dedicated repository to each module). I'm trying to use FetchContent_Declare in order to link dependant modules together (I'm not a fan of git-submodules since those require that user manually initialises them). The problem I'm having is that the DLL generated by the project fetched via the mentioned function isn't copied to the binary output of the parent project. Here is a dependency graph to make it more clear.
Repo A:
- bin
- bin-etc
- lib
- include
- project_a
.. header files ..
- src
- CMakeLists.txt : 1
.. source files ..
- CMakeLists.txt : 2
Repo B: Includes A
- bin
- bin-etc
- lib
- output
.. cmake files are built from here ..
- _deps
- project_a-src
- bin
.. here the DLL file is being generated ..
- include
- project_a
.. header files ..
- src
- CMakeLists.txt : 3
.. source files ..
- CMakeLists.txt : 4
The DLL file is being generated in ./output/_deps/project_a-src/bin instead of ./bin.
Here are my CMakeLists.txt files:
# CMakeLists.txt : 1
cmake_minimum_required(VERSION 3.16)
set(PROJECTNAME project_a)
set(PROJECTDIR "${CMAKE_CURRENT_SOURCE_DIR}")
file(GLOB_RECURSE inc "${CMAKE_CURRENT_SOURCE_DIR}/../include/*.hpp")
file(GLOB_RECURSE src "${CMAKE_CURRENT_SOURCE_DIR}/*.cpp")
source_group(TREE "${CMAKE_CURRENT_SOURCE_DIR}/../include" FILES ${inc})
source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR} FILES ${src})
if (MSVC)
add_compile_options(/W3) # warning level 3
add_compile_options(/MP) # Multi-processor compilation
endif()
add_library(
${PROJECTNAME}
SHARED
${inc}
${src}
)
target_include_directories(${PROJECTNAME} PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/../include/")
# CMakeLists.txt : 2 and 4
cmake_minimum_required(VERSION 3.16)
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
set(CMAKE_SYSTEM_VERSION 10.0.19041.0)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/bin-etc")
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/lib")
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/bin")
project(project_a LANGUAGES CXX)
set(CMAKE_CXX_STANDARD 23)
set(CMAKE_CXX_STANDARD_REQUIRED)
add_subdirectory(src)
# CMakeLists.txt : 3
cmake_minimum_required(VERSION 3.16)
set(PROJECTNAME project_b)
set(PROJECTDIR "${CMAKE_CURRENT_SOURCE_DIR}")
file(GLOB_RECURSE inc "${CMAKE_CURRENT_SOURCE_DIR}/../include/*.hpp")
file(GLOB_RECURSE inc_src "${CMAKE_CURRENT_SOURCE_DIR}/*.hpp")
file(GLOB_RECURSE src "${CMAKE_CURRENT_SOURCE_DIR}/*.cpp")
source_group(TREE "${CMAKE_CURRENT_SOURCE_DIR}/../include" FILES ${inc})
source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR} FILES ${inc_src})
source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR} FILES ${src})
if (MSVC)
add_compile_options(/W3) # warning level 3
add_compile_options(/MP) # Multi-processor compilation
endif()
add_library(
${PROJECTNAME}
SHARED
${inc}
${inc_src}
${src}
)
target_include_directories(${PROJECTNAME} PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/../include/")
include(FetchContent)
FetchContent_Declare(project_a
GIT_REPOSITORY <REPO LINK>
GIT_TAG master)
FetchContent_MakeAvailable(project_a)
target_link_libraries(${PROJECTNAME} project_a)
What would be the solution to this problem? Should I use another approach for the design like this? Is adding a simple copy command to cmake the right solution?
Variables like CMAKE_RUNTIME_OUTPUT_DIRECTORY affects on the output directory for all further created libraries ... unless the variable is changed.
The project_a in CMakeLists.txt(2) does
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/bin")
unconditionally, so it changes the variable even if it is built as a subproject (with FetchContent).
Generally, any project in its root CMakeLists.txt could check, whether it is actually top-level project. And perform some settings only in case it is:
cmake_minimum_required(VERSION 3.21)
project(project_a LANGUAGES CXX)
if (PROJECT_IS_TOP_LEVEL)
# Do global settings only if we are top-level project.
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
set(CMAKE_SYSTEM_VERSION 10.0.19041.0)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/bin-etc")
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/lib")
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/bin")
endif()
# Other settings are treated as project-specific,
# so could be done in "subproject mode" too.
set(CMAKE_CXX_STANDARD 23)
set(CMAKE_CXX_STANDARD_REQUIRED)
add_subdirectory(src)
Note, that variable PROJECT_IS_TOP_LEVEL appears only in CMake 3.21. For detect, whether the project is top-level in older CMake versions, consult that question and its answers: How to detect if current scope has a parent in CMake?.

CMake builds library without needing target_link_libraries for dependencies (wxWidgets in the case)

Below is a working CMakeLists.txt, the application simply display a wxWidget frame.
If target_link_libraries is removed, it'll fail to be built.
cmake_minimum_required(VERSION 3.5)
project(TestCMake LANGUAGES CXX)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
add_definitions(-DBOOST_ASIO_DISABLE_CONCEPTS)
set(CMAKE_DEBUG_POSTFIX "-d")
set(CMAKE_INSTALL_PREFIX "/usr/local")
find_package(wxWidgets REQUIRED core base)
include(${wxWidgets_USE_FILE})
include_directories(.
..
${wxWidgets_INCLUDE_DIRS})
file(GLOB_RECURSE header_files *.h)
file(GLOB_RECURSE source_files *.cpp)
add_executable(TestCMake ${header_files} ${source_files})
target_link_libraries(TestCMake ${wxWidgets_LIBRARIES})
Now change the last two lines, it becomes as below.
No target_link_libraries, but it can be built succesfully, why?
cmake_minimum_required(VERSION 3.5)
project(TestCMake LANGUAGES CXX)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
add_definitions(-DBOOST_ASIO_DISABLE_CONCEPTS)
set(CMAKE_DEBUG_POSTFIX "-d")
set(CMAKE_INSTALL_PREFIX "/usr/local")
find_package(wxWidgets REQUIRED core base)
include(${wxWidgets_USE_FILE})
include_directories(.
..
${wxWidgets_INCLUDE_DIRS})
file(GLOB_RECURSE header_files *.h)
file(GLOB_RECURSE source_files *.cpp)
add_library(TestCMake ${header_files} ${source_files})

Change default CMakeLists.txt created by KDevelop?

When I create a project, my CMakeLists.txt file looks like this:
cmake_minimum_required(VERSION 2.6)
project(testttt)
add_executable(testttt main.cpp)
install(TARGETS testttt RUNTIME DESTINATION bin)
But I want it to looks like this:
cmake_minimum_required(VERSION 2.6)
project(testttt)
add_executable(testttt main.cpp)
install(TARGETS testttt RUNTIME DESTINATION bin)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
so that I have C++11 support by default. How do I do it?
KDevelop project templates are implemented using Grantlee templating engine. Here is a manual how to add your own template.
Built-in templates are located in /share/apps/kdevfiletemplates/templates, you can use "Basic C++ project` as an example.