I'm building a C++ program using CGAL, and I'm writing CMake install rules to deploy said program so that I can CPack the result and the end user doesn't have to install CGAL or any of its dependencies to use it. In order to do that, I need to include every shared library (DLLs on Windows etc) but I can't find a CMake variable that lets me do that. I searched around in the CGAL repo, but no luck. I tried using ${CGAL_LIBRARIES} but those don't give paths, and it doesn't seem like ${CGAL_LIBRARIES_DIRS} is a thing.
My current CMakeLists is based off the one generated by the dedicated CGAL script :
# Created by the script cgal_create_CMakeLists
# This is the CMake script for compiling a set of CGAL applications.
project( MeshCleaner )
cmake_minimum_required(VERSION 2.8.11)
set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)
# CGAL and its components
find_package( CGAL QUIET COMPONENTS )
if ( NOT CGAL_FOUND )
message(STATUS "This project requires the CGAL library, and will not be compiled.")
return()
endif()
# Boost and its components
find_package( Boost REQUIRED )
if ( NOT Boost_FOUND )
message(STATUS "This project requires the Boost library, and will not be compiled.")
return()
endif()
# include for local directory
include_directories( BEFORE include )
# include for local package
# Creating entries for target: meshCleaner
# ############################
add_executable( ${PROJECT_NAME} main.cpp )
add_to_cached_list( CGAL_EXECUTABLE_TARGETS ${PROJECT_NAME} )
# Link the executable to CGAL and third-party libraries
target_link_libraries(${PROJECT_NAME} ${CGAL_LIBRARIES} ${CGAL_3RD_PARTY_LIBRARIES} )
install(TARGETS ${PROJECT_NAME} DESTINATION . COMPONENT Libraries)
message(${CGAL_LIBRARIES} ${CGAL_3RD_PARTY_LIBRARIES})
if(WIN32)
set(CMAKE_INSTALL_OPENMP_LIBRARIES TRUE)
include(InstallRequiredSystemLibraries)
endif()
include(${PROJECT_NAME}CPack)
The simplest way to "fix" that issue is to use CGAL as header-only. Please check the manual. Here is the direct link to the installation manual of CGAL-4.14, section "Header-only with CMake Configuration".
Related
I have been trying to add SDL2 to my project using CMake.
My CMakeLists.txt looks like this.
...
include_directories(
${PROJECT_SOURCE_DIR}/src
${PROJECT_SOURCE_DIR}/test
${PROJECT_SOURCE_DIR}/external
${PROJECT_SOURCE_DIR}/external/KHR
${PROJECT_SOURCE_DIR}/external/glm
${PROJECT_SOURCE_DIR}/external/nvToolsExt
${PROJECT_SOURCE_DIR}/external/stb_image
${PROJECT_SOURCE_DIR}/external/SDL2/include
${PROJECT_SOURCE_DIR}/external/assimp/include
)
# Setup dependencies
link_directories(
${PROJECT_SOURCE_DIR}/external/SDL2/lib/x64
${PROJECT_SOURCE_DIR}/external/assimp/lib
)
# Glad
add_subdirectory(external/glad)
# ImGui
add_subdirectory(external/imgui)
# Assimp
add_subdirectory(external/assimp ${EXECUTABLE_OUTPUT_PATH}/external/assimp)
# SDL2
add_subdirectory(external/SDL2 ${EXECUTABLE_OUTPUT_PATH}/external/SDL2)
# Setup build
set(TARGET_NAME sre)
set_property(DIRECTORY PROPERTY VS_STARTUP_PROJECT ${TARGET_NAME})
add_executable(${TARGET_NAME} ${SRC_FILES})
set_target_properties(sre PROPERTIES
VS_DEBUGGER_WORKING_DIRECTORY "${PROJECT_SOURCE_DIR}"
)
target_link_libraries(
${TARGET_NAME}
opengl32
SDL2Main
SDL2
glad
imgui
assimp
)
It generates the VS solution correctly but when I build it I get the following error from SDL2:
external\sdl2\include\sdl_config.h(52): fatal error C1189: #error: Wrong SDL_config.h, check your include path?
As a result, my build fails. I'm kind of a noob using cmake so any sort of advice is welcome.
I am trying to make a cross-platform CMake for my project (Windows and Linux).
I need to use external libraries (yaml-cpp). On Linux, I just had to do an apt get and use find_package. But on Windows, I need to append the CMAKE_MODULE_PATH in order for my program to find the yaml-cpp-config.cmake.
So I start by installing yaml-cpp (https://github.com/jbeder/yaml-cpp) with CMake GUI 3.16 and mingw32 (mingw32-make install).
I have tried the library on a hello world project, and it works fine.
cmake_minimum_required(VERSION 3.1)
project (yaml_test)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
message (STATUS "Yaml-cpp include = $ENV{YAML_CPP_INCLUDE_DIR}")
message (STATUS "Yaml-cpp library = $ENV{YAML_CPP_LIBRARIES}")
include_directories ($ENV{YAML_CPP_INCLUDE_DIR})
add_executable(yaml_test main.cpp)
target_link_libraries(yaml_test $ENV{YAML_CPP_LIBRARIES})
But now, I want to include the library in my project and use find_package. But the yaml-cpp-config.cmake looks like this:
# - Config file for the yaml-cpp package
# It defines the following variables
# YAML_CPP_INCLUDE_DIR - include directory
# YAML_CPP_LIBRARIES - libraries to link against
# Compute paths
get_filename_component(YAML_CPP_CMAKE_DIR "${CMAKE_CURRENT_LIST_FILE}" PATH)
set(YAML_CPP_INCLUDE_DIR "")
# Our library dependencies (contains definitions for IMPORTED targets)
include("${YAML_CPP_CMAKE_DIR}/yaml-cpp-targets.cmake")
# These are IMPORTED targets created by yaml-cpp-targets.cmake
set(YAML_CPP_LIBRARIES "")
The YAML_CPP_INCLUDE_DIR and YAML_CPP_LIBRARIES variables are empty, and even if CMake found yaml-cpp-config.cmake, It doesn't work. So what do I have missing in the installation of yaml-cpp? Should I have set the paths by hand?
The absence of definition of YAML_CPP_INCLUDE_DIR and YAML_CPP_LIBRARIES variables is the issue with the yaml-cpp project which is already reported here.
Instead of variables described in this config file, use target yaml-cpp:
add_executable(yaml_test main.cpp)
# This provides both include directories and libraries.
target_link_libraries(yaml_test yaml-cpp)
Linking with an IMPORTED target (yaml-cpp in this case) is known as CMake "modern way".
I have a project with a CMakeLists.txt at the root, which includes a project in a subdirectory test/ using add_subdirectory with the flag EXCLUDE_FROM_ALL. The tests need all of the include directories of the parent project. What would be the most elegant way to do this?
CMakeLists.txt
CMAKE_MINIMUM_REQUIRED(VERSION 3.1)
SET(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/Modules")
PROJECT(autoffi CXX)
SET(CMAKE_CXX_STANDARD 11)
SET(AutoFFI_VERSION_MAJOR 0)
SET(AutoFFI_VERSION_MINOR 1)
SET(Boost_USE_STATIC_LIBS OFF)
FIND_PACKAGE(BOOST 1.50 COMPONENTS system filesystem REQUIRED)
FIND_PACKAGE(LLVM 3.9 REQUIRED CONFIG)
ADD_DEFINITIONS(${LLVM_DEFINITIONS})
FIND_PACKAGE(Clang REQUIRED)
CONFIGURE_FILE(
"${PROJECT_SOURCE_DIR}/include/env.h.in"
#"${PROJECT_BINARY_DIR}/include/env.h"
"${PROJECT_SOURCE_DIR}/include/env.h" # added to VCS
)
INCLUDE_DIRECTORIES(
#"${PROJECT_BINARY_DIR}"
"${PROJECT_SOURCE_DIR}/include"
"${CLANG_INCLUDE_DIRS}"
"${Boost_INCLUDE_DIRS}"
)
# The C++ interface
ADD_LIBRARY(autoffiCore src/Type.cpp)
# FIXME: boost package finder seems to be broken
TARGET_LINK_LIBRARIES(autoffiCore boost_filesystem boost_system)
ADD_LIBRARY(autoffiBin src/BinFormat.cpp)
TARGET_LINK_LIBRARIES(autoffiBin autoffiCore)
ADD_LIBRARY(autoffiClang src/ClangEngine.cpp)
llvm_map_components_to_libnames(llvm_libs all)
TARGET_LINK_LIBRARIES(autoffiClang autoffiCore ${llvm_libs} ${CLANG_LIBS})
# The C interface
ADD_LIBRARY(autoffi src/PrettyPrinter.cpp src/libautoffi.cpp)
TARGET_LINK_LIBRARIES(autoffi autoffiBin autoffiClang)
set_target_properties(autoffiCore autoffiBin autoffiClang autoffi PROPERTIES DEFINE_SYMBOL BUILDING_SHARED)
# CLI Tools
ADD_EXECUTABLE(afdump src/dump.cpp src/PrettyPrinter.cpp)
TARGET_LINK_LIBRARIES(afdump autoffiBin)
ADD_EXECUTABLE(afconvert src/convert.cpp)
TARGET_LINK_LIBRARIES(afconvert autoffiBin)
ADD_EXECUTABLE(afcompile src/tooling.cpp src/PrettyPrinter.cpp)
TARGET_LINK_LIBRARIES(afcompile autoffiClang ${CLANG_LIBS} autoffiBin)
# Testing
ENABLE_TESTING()
ADD_TEST(headerASTDump afcompile test/assets/basic.h)
test/CMakeLists.txt
CMAKE_MINIMUM_REQUIRED(VERSION 2.8)
project("AutoFFI Tests")
SET(CMAKE_CXX_STANDARD 11)
SET(GTEST_ROOT "${CMAKE_CURRENT_LIST_DIR}/gtest")
find_package(GTest REQUIRED)
INCLUDE_DIRECTORIES(${AUTOFFI_INCLUDE_DIRS} ${GTEST_INCLUDE_DIRS})
ADD_EXECUTABLE(autoffiTest libautoffi.cpp core.cpp formats.cpp clang.cpp)
TARGET_LINK_LIBRARIES(autoffiTest ${GTEST_BOTH_LIBRARIES})
SET_TARGET_PROPERTIES(autoffiTest PROPERTIES OUTPUT_NAME runtests)
You are keeping your main directory and your subdirectory test in completely separated projects. I suppose you are building test by invoking separately cmake and make a second time. No surprise that the include_directories of your main project as no impact on the test project.
You mention the command add_subdirectory, (that should be used to include test in from your main directory) but you are actually not using it...
If you're using include_directories() to add dirs, those should propagate down into targets in the test subdir. Beware though that relative paths are relative to the current source dir:
include_directories: Add include directories to the build.
include_directories([AFTER|BEFORE] [SYSTEM] dir1 dir2 ...)
Add the given directories to those the compiler uses to search for include files. Relative paths are interpreted as relative to the current source directory.
cmake docs
I am a total noob concerning cmake. My CMakeLists is really basic:
cmake_minimum_required(VERSION 2.4.6)
#set the default path for built executables to the "bin" directory
set(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/bin)
#set the default path for built libraries to the "lib" directory
set(LIBRARY_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/lib)
#For the Curses library to load:
SET(CURSES_USE_NCURSES TRUE)
include_directories(
"src/"
)
add_subdirectory(src)
when I make the linker does not find the ncurses commands and in the verbose mode of make I see that the compiler did not add the -lncurses. What do I have to add to the CMakeLists to make it work?
For the super noob, remember target_link_libraries() needs to be below add_executable():
cmake_minimum_required(VERSION 2.8) project(main)
find_package(Curses REQUIRED)
include_directories(${CURSES_INCLUDE_DIR})
add_executable(main main.cpp)
target_link_libraries(main ${CURSES_LIBRARIES})
before use some third party libs, you ought to find it!
in case of ncurses you need to add find_package(Curses REQUIRED) and then use ${CURSES_LIBRARIES} in a call to target_link_libraries() and target_include_directories(... ${CURSES_INCLUDE_DIR}).
I have a problem with CMake. I have wrote a CMakeList.txt file. But when I run it with Cmake I got a strange error "CMake Error at CMakeLists.txt:17 (target_link_libraries):
Cannot specify link libraries for target "debug" which is not built by this
project.".
Is it possible to create a Cmake file that can build a project file for Debug and Release mode at the same time? Or is there a simple way to fix this error?
My CMakeLists.txt looks like this:
cmake_minimum_required (VERSION 2.8)
project (SimuVille)
# Import required CMake files
set (CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake/Modules")
file(GLOB_RECURSE files
"*.cpp"
)
add_executable(debug ${files})
# Find the find Modules
set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake_modules" ${CMAKE_MODULE_PATH})
#Find any version 2.X of SFML
#See the FindSFML.cmake file for additional details and instructions
find_package(SFML 2 REQUIRED system window graphics network audio)
if(SFML_FOUND)
include_directories(${SFML_INCLUDE_DIR})
target_link_libraries(${EXECUTABLE_NAME} ${SFML_LIBRARIES})
endif()
#Find SfeMovie
find_package(sfeMovie REQUIRED)
if(SFEMOVIE_FOUND)
include_directories(${SFEMOVIE_INCLUDE_DIR})
target_link_libraries(${EXECUTABLE_NAME} ${SFEMOVIE_LIBRARY})
endif()
#Find Assimp
find_package(ASSIMP REQUIRED)
if(ASSIMP_FOUND)
include_directories(${ASSIMP_INCLUDE_DIR})
target_link_libraries(${EXECUTABLE_NAME} ${ASSIMP_LIBRARY})
endif()
#Find DevIL
find_package(DevIL REQUIRED)
if(IL_FOUND)
include_directories(${IL_INCLUDE_DIR})
target_link_libraries(${EXECUTABLE_NAME} ${IL_LIBRARY})
target_link_libraries(${EXECUTABLE_NAME} ${ILU_LIBRARY})
target_link_libraries(${EXECUTABLE_NAME} ${ILUT_LIBRARY})
endif()
#Find opengl libs
find_package(OpenGL REQUIRED)
include_directories(${OpenGL_INCLUDE_DIRS})
link_directories(${OpenGL_LIBRARY_DIRS})
add_definitions(${OpenGL_DEFINITIONS})
if(NOT OPENGL_FOUND)
message(ERROR " OPENGL not found!")
endif(NOT OPENGL_FOUND)
#file(GLOB_RECURSE hfiles
# "*.h"
#)
#add_executable(SimuVille ${hfiles})
LINK_DIRECTORIES(${CMAKE_SOURCE_DIR}/Game)
LINK_DIRECTORIES(${CMAKE_SOURCE_DIR}/GameEngine)
LINK_DIRECTORIES(${CMAKE_SOURCE_DIR}/GameEngine/SfmlObject)
LINK_DIRECTORIES(${CMAKE_SOURCE_DIR}/GameEngine/Camera)
LINK_DIRECTORIES(${CMAKE_SOURCE_DIR}/GameEngine/OpenglObject)
LINK_DIRECTORIES(${CMAKE_SOURCE_DIR}/GameEngine/Playable)
Edit: Added new source code.
Looks like your CMakeLists.txt doesn't contain either of two lines (which depends you are creating a library or a executable)
add_library(debug <files Name>)
OR
add_executable(debug <files Name>)
If you have these lines in your file, place it before target_link_libraries ()