How to configure TGUI + SFML with CMake - c++

I'm currently working on a project and I decided to use TGUI with SFML for creating a menu. SFML works fine with CMake and I thought that configuring TGUI would be pretty much the same thing but I am not sure... How do configure TGUI?
My code looks like this at the moment:
#documentation for configuring SFML with CMake : https://en.sfml-dev.org/forums/index.php?topic=24070.0
cmake_minimum_required(VERSION 3.17.3)
set(CMAKE_CXX_STANDARD 14)
project(AlgorithmsSimulator)
#location of project's files
include_directories(${CMAKE_SOURCE_DIR})
#directory for excutables
file(MAKE_DIRECTORY ${CMAKE_SOURCE_DIR}/bin)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/bin)
#object files
file(MAKE_DIRECTORY ${CMAKE_SOURCE_DIR}/lib)
set(LIBRARY_OUTPUT_PATH ${CMAKE_SOURCE_DIR}/lib)
#configuring SFML for windows
if(${CMAKE_SYSTEM_NAME} MATCHES "Windows")
set(WINDOWS TRUE)
set(SFML_STATIC_LIBRARIES TRUE)
set(SFML_DIR "./SFML_Win/lib/cmake/SFML")
#MacOS
elseif(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
set(MACOSX TRUE)
set(SFML_INCLUDE_DIR "./SFML_macOS/include")
set(SFML_LIBRARY_DIR "./SFML_macOS/lib")
link_directories(SFML_LIBRARY_DIR)
include_directories(SFML_INCLUDE_DIR)
#Linux
elseif(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
set(LINUX TRUE)
#set(SFML_STATIC_LIBRARIES TRUE)
set(SFML_DIR "./SFML_Linux/lib/cmake/SFML")
else()
message(FATAL_ERROR "Your Operating System is not supported")
endif()
# TGUI configuration
set(TGUI_DIR "./TGUI/lib/cmake/TGUI")
#after configuring the paths of sfml for windows, macOS and linux cmake needs only to find the below packages
find_package(SFML 2.5 COMPONENTS audio graphics window system network REQUIRED)
find_package(TGUI 0.8 REQUIRED)
#compiling & list the header an source files in the solution explorer
set(HEADERS AlgorithmsImplementation.h)
set(SOURCES AlgorithmsImplementation.cpp Main.cpp)
add_executable(${PROJECT_NAME} ${HEADERS} ${SOURCES})
# sfml .dll files and the .dll files for tgui; when tgui-d is added I get this linking error: tgui-d.lib cannot be opened and when I exclude it, it says that it cannot found tgui-d.dll
target_link_libraries(${PROJECT_NAME} sfml-audio sfml-graphics sfml-window sfml-system sfml-network tgui tgui-d)
#this will allow us to install an .exe file of the project
install(TARGETS ${PROJECT_NAME} DESTINATION bin) #${CMAKE_INSTALL_PREFIX}/bin
install(FILES Main.cpp DESTINATION src) #${CMAKE_INSTALL_PREFIX}/src

Related

Cannot find package GLFW using CMake

My project structure looks like this:
CMakeLists.txt
deps
glew
glfw
include
src
...
graphics
...
CMakeLists.txt
Two CMakeLists.txt files that deserve attention:
CMakeLists.txt
cmake_minimum_required(VERSION 3.9)
project(noam_engine)
find_package(glfw3 REQUIRED)
find_package(OpenGL REQUIRED)
find_package(GLEW REQUIRED)
set(CMAKE_CXX_STANDARD 11)
set(NE_LIBRARIES common math graphics)
FOREACH(lib ${NE_LIBRARIES})
add_subdirectory(src/${lib})
ENDFOREACH(lib)
add_executable(noam_engine src/main.cpp)
if(OPENGL_FOUND AND GLEW_FOUND)
target_include_directories(noam_engine PUBLIC include ${OPENGL_INCLUDE_DIR} ${GLEW_INCLUDE_DIRS})
target_link_libraries(noam_engine ${NE_LIBRARIES})
endif()
src/graphics/CMakeLists.txt
cmake_minimum_required(VERSION 3.9)
find_package(glfw3 REQUIRED)
find_package(OpenGL REQUIRED)
find_package(GLEW REQUIRED)
file(GLOB SRC "*.cpp")
add_library(graphics ${SRC})
if(OPENGL_FOUND AND GLEW_FOUND)
target_include_directories(graphics PUBLIC ${PROJECT_SOURCE_DIR}/include ${OPENGL_INCLUDE_DIR} ${GLEW_INCLUDE_DIRS})
target_link_libraries(graphics ${OPENGL_gl_LIBRARY} ${GLFW3_LIBRARY} ${GLEW_LIBRARIES})
message(STATUS "GLFW and GLEW successfully linked")
message(STATUS ${OPENGL_gl_LIBRARY})
message(STATUS ${GLFW3_LIBRARY})
message(STATUS ${GLEW_LIBRARIES})
else()
message(STATUS "Cannot find GL libraries")
endif()
In a few words I want to create a bunch of static libraries of the engine, in particular, link graphics library with GL's, and finally link all of them with the executable in a root CMakeLists.txt.
But I noticed that ${GLFW3_LIBRARY} is empty and I got a linker error, for example, when I call glfwInit(). I followed the guide during building and installation of GLFW
cmake .
make
make install
I believe headers and libraries are in /usr/local/*, but apparently CMake cannot find them or maybe I did something wrong.
The only hypothesis I have is that find_package doesn't know about glfw3Config.cmake which is in deps/glfw/*
I took the script from https://github.com/JoeyDeVries/LearnOpenGL/blob/master/cmake/modules/FindGLFW3.cmake and put it into cmake folder. Then in CMakeLists.txt I added
list(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake")
Now everything works properly
Thanks #Tsyvarev

What configurations do I need in CMake so that I can build the project?

I want to build the following project: https://github.com/reo7sp/tgbot-cpp
I get these errors: https://imgur.com/S9kgWyv
Makefile part 1: https://imgur.com/O222bJR
Makefile part 2: https://imgur.com/i68QLdC
Now, I think that I need zlib, openssl and boost. Curl seems to be optional.
What is "threads"?
And what is the difference between ...LIBRARY_DEBUG and ...LIBRARY_RELEASE?
What doe LIB and SSL mean in the gui? These "libraries" are not mentioned in the makefile?
I am desperate for days now. Please, help me.
Error:
CMake Error at D:/Programme/CMake/share/cmake-3.13/Modules/FindPackageHandleStandardArgs.cmake:137 (message):
Could NOT find OpenSSL, try to set the path to OpenSSL root folder in the
system variable OPENSSL_ROOT_DIR (missing: OPENSSL_CRYPTO_LIBRARY) (found
version "1.1.0j")
Call Stack (most recent call first):
D:/Programme/CMake/share/cmake-3.13/Modules/FindPackageHandleStandardArgs.cmake:378 (_FPHSA_FAILURE_MESSAGE)
D:/Programme/CMake/share/cmake-3.13/Modules/FindOpenSSL.cmake:412 (find_package_handle_standard_args)
CMakeLists.txt:47 (find_package)
CMakeLists.txt:
cmake_minimum_required(VERSION 2.8.4)
project(TgBot)
if (${CONAN_EXPORTED})
include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup()
endif()
set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON)
# options
option(ENABLE_TESTS "Set to ON to enable building of tests" OFF)
option(BUILD_SHARED_LIBS "Build tgbot-cpp shared/static library." OFF)
# sources
if(WIN32)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11") # Do not activate all warnings in VS (too much output for Appveyor)
else()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wall")
endif()
include_directories(include)
set(SRC_LIST
src/Api.cpp
src/EventHandler.cpp
src/TgException.cpp
src/TgTypeParser.cpp
src/net/BoostHttpOnlySslClient.cpp
src/net/CurlHttpClient.cpp
src/net/HttpParser.cpp
src/net/TgLongPoll.cpp
src/net/Url.cpp
src/tools/FileTools.cpp
src/tools/StringTools.cpp
src/types/InlineQueryResult.cpp
src/types/InputFile.cpp
)
# libs
## threads
find_package(Threads REQUIRED)
# zlib
find_package(ZLIB REQUIRED)
## openssl
find_package(OpenSSL REQUIRED)
include_directories(${OPENSSL_INCLUDE_DIR})
## curl
find_package(CURL)
if (CURL_FOUND)
include_directories(${CURL_INCLUDE_DIRS})
add_definitions(-DHAVE_CURL)
endif()
## boost
set(Boost_USE_MULTITHREADED ON)
if (ENABLE_TESTS)
find_package(Boost 1.59.0 COMPONENTS system unit_test_framework REQUIRED)
else()
find_package(Boost 1.59.0 COMPONENTS system REQUIRED)
endif()
include_directories(${Boost_INCLUDE_DIR})
set(LIB_LIST
${CMAKE_THREAD_LIBS_INIT}
${ZLIB_LIBRARIES}
${OPENSSL_LIBRARIES}
${Boost_LIBRARIES}
${CURL_LIBRARIES}
)
# building project
add_library(${PROJECT_NAME} ${SRC_LIST})
target_include_directories(${PROJECT_NAME} PUBLIC include)
target_link_libraries(${PROJECT_NAME} ${LIB_LIST})
install(TARGETS ${PROJECT_NAME}
RUNTIME DESTINATION bin
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib)
install(DIRECTORY include/ DESTINATION include)
# tests
if (ENABLE_TESTS)
message(STATUS "Building of tests is enabled")
enable_testing()
add_subdirectory(test)
endif()
It turned out that I needed to set some system variables for OpenSSL, ZLib, Boost, curl. For Zlib just do the same procedure. drescherjm was a huge help. So thanks!
Tutorial for this:
OpenSSL: https://www.youtube.com/watch?v=3I7eL2Mm6Ps&index=34&t=0s&list=PLcmZ3Jkh7taY1ensPUAJ4VfMEicDcihhg
and
curl: How do I install and use curl on Windows?
Setting up curl library path in cmake

Compiling SFML program with CMake on windows

For the past few days I've been searching everywhere and can't seem to fix this problem or maybe I just didn't understand some answers.
I have an application (a game to be precise) built with SFML that I managed to compile on Linux with 2.4.2 version. I want to migrate to 2.5.1 and be able to compile on Windows so I changed the CMakeLists.txt file to this:
cmake_minimum_required(VERSION 3.0)
# There is no real need for C++17 or 14, but I like to use up-to-date versions
if(CMAKE_MAJOR_VERSION VERSION_GREATER 3.8.0)
set(CMAKE_CXX_STANDARD 17)
else()
set(CMAKE_CXX_STANDARD 14)
endif(CMAKE_MAJOR_VERSION VERSION_GREATER 3.8.0)
if (WIN32)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/Binaries/)
endif(WIN32)
# Includes
include_directories(include)
# Source files
set(SOURCE_FILES
source/main.cpp
source/Game.cpp
)
# Assets
set(ASSETS
assets/Fonts/xolonium.ttf
)
# Debug Mode
project(HexDebug VERSION 1.0 LANGUAGES CXX)
set(CMAKE_BUILD_TYPE DEBUG) # This is ignored by MSVC
#SFML Package
find_package(SFML 2.5 CONFIG COMPONENTS system window graphics network audio REQUIRED)
if(SFML_FOUND)
set(SFML_STATIC_LIBRARIES TRUE)
if(WIN32)
set(SFML_USE_STATIC_STD_LIBS TRUE)
endif(WIN32)
endif(SFML_FOUND)
if(UNIX)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/Binaries/Debug/)
endif(UNIX)
foreach(asset ${ASSETS})
configure_file(${asset} ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${asset} COPYONLY)
endforeach(asset)
add_executable(${PROJECT_NAME} ${SOURCE_FILES})
target_compile_options(${PROJECT_NAME} PRIVATE -g -Wall -O0 -D_DEBUG)
if(SFML_FOUND)
target_link_libraries(${PROJECT_NAME} sfml-system sfml-window sfml-graphics sfml-network sfml-audio)
endif(SFML_FOUND)
#Release Mode
project(Hex VERSION 1.0 LANGUAGES CXX)
set(CMAKE_BUILD_TYPE RELEASE) # This is ignored by MSVC
if(UNIX)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/Binaries/Release/)
endif(UNIX)
foreach(asset ${ASSETS})
configure_file(${asset} ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${asset} COPYONLY)
endforeach(asset)
add_executable(${PROJECT_NAME} ${SOURCE_FILES})
target_compile_options(${PROJECT_NAME} PRIVATE "-O3")
if(SFML_FOUND)
target_link_libraries(${PROJECT_NAME} sfml-system sfml-window sfml-graphics sfml-network sfml-audio)
endif(SFML_FOUND)
The cmake works and generates the VS solution, that I can build with msbuild (note that I don't want to launch Visual Studio, but only use msbuild). But once I try to run it, it asks for dlls and I don't want that.
I thought that would be solved by linking statically (I don't know much about static or dynamic linking) but it still asks for them.
In this link they say that we don't need to include the ${SFML_INCLUDE_DIR} and ${SFML_LIBRARIES} anymore: https://en.sfml-dev.org/forums/index.php?topic=24070.0
How can I avoid that? I want to be completely independant from DLL's or at least be able to include the bin directory installed from SFML compiled and installed binaries (that I compiled, not the precompiled).
Thank you.

Creation of a cmake module for using a library

I am new to C++ and have just started to use Cmake for linking the libraries to my project. I need to use a library:
https://github.com/Gnimuc/FastPD
Fortunately, I managed to build the library using Cmake (in my build there is no *.lib file at all), but I don't know how to link it to my project. I mean that I don't know how to add it to my cmakelists.txt :
(PS. I'm also using two other libraries ITK and VTK; but I can't link the above mentioned library to my project or main.cpp.)
################################################
cmake_minimum_required(VERSION 2.8)
project(My_project)
find_package(ITK REQUIRED)
include(${ITK_USE_FILE})
if (ITKVtkGlue_LOADED)
find_package(VTK REQUIRED)
include(${VTK_USE_FILE})
else()
find_package(ItkVtkGlue REQUIRED)
include(${ItkVtkGlue_USE_FILE})
set(Glue ItkVtkGlue)
endif()
add_executable(My_project MACOSX_BUNDLE main.cpp)
target_link_libraries(My_project
${Glue} ${VTK_LIBRARIES} ${ITK_LIBRARIES})
################################################
Thanks in advance for your helps,
Assuming you installed the library and its header files, you can then search for the header files using find_path, and add the found path to the include directories. Then you can search for the library by using find_library, and add the library with the target_link_libraries command.
I tried both shared and static types for creation of the library. In the case of shared, no *.lib file was created, and in the case of static, my project couldn't link to the library. Therefore, in my project's CmakeLists.txt, I decided to add all the *.cpp and headers as libraries and then link them together (as I didn't know the dependency among them!!!), and finally, I linked them to my project. Perhaps it does not make sense but it works; hope it helps you:
CmakeLists.txt
##############################################
cmake_minimum_required(VERSION 2.6)
set(PROJ_NAME PROJECT46)
PROJECT(${PROJ_NAME})
# Prevent compilation in-source
if( ${CMAKE_BINARY_DIR} STREQUAL ${PROJECT_SOURCE_DIR} )
Message( " " )
Message( FATAL_ERROR "Source and build directories are the same.
Create an empty build directory,
change into it and re-invoke cmake")
endif()
include(CheckCXXCompilerFlag)
CHECK_CXX_COMPILER_FLAG("-std=c++11" COMPILER_SUPPORTS_CXX11)
CHECK_CXX_COMPILER_FLAG("-std=c++0x" COMPILER_SUPPORTS_CXX0X)
if(COMPILER_SUPPORTS_CXX11)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
elseif(COMPILER_SUPPORTS_CXX0X)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x")
else()
message(STATUS "The compiler ${CMAKE_CXX_COMPILER} has no C++11 support.
Please use a different C++ compiler.")
endif()
##############################################
## External libraries
##############################################
list( APPEND CMAKE_MODULE_PATH
${PROJECT_SOURCE_DIR}/cmake
)
# Blitz
find_package( Blitz++ REQUIRED )
list( APPEND PROJ_INCLUDE_DIRS
${Blitz++_INCLUDE_DIR}
)
list( APPEND
PROJ_LIB
${Blitz++_LIBRARIES}
)
# ITK and VTK
find_package(ITK REQUIRED)
include(${ITK_USE_FILE})
if (ITKVtkGlue_LOADED)
find_package(VTK REQUIRED)
include(${VTK_USE_FILE})
else()
find_package(ItkVtkGlue REQUIRED)
include(${ItkVtkGlue_USE_FILE})
set(Glue ItkVtkGlue)
endif()
##############################################
# FASTPD
add_library(FASTPD Fast_PD.cpp Fast_PD.h common.h block.h)
add_library(GRAPH graph.h graph.cpp)
add_library(linked LinkedBlockList.h LinkedBlockList.cpp)
add_library(MAXFLOW maxflow.cpp)
include_directories(${PROJ_INCLUDE_DIRS})
add_executable(${PROJ_NAME} main.cpp)
target_link_libraries(linked MAXFLOW)
target_link_libraries(GRAPH linked)
target_link_libraries(FASTPD GRAPH)
target_link_libraries(${PROJ_NAME} FASTPD)
target_link_libraries(${PROJ_NAME}
${PROJ_LIB} ${Glue} ${VTK_LIBRARIES} ${ITK_LIBRARIES}
)

Setting the library path for Boosts tests with CMake in Windows

I've started a little project on GitHub for an OpenSceneGraph plugin. Here, I plan on learning how to setup projects with CMake, unit testing with Boost.Test and continuous integration, with Travis-CI.
It has this structure:
root
|-> cmake
|-> conf [Create the `library`-config.cmake and `library`-depends.cmake files]
|-> find [Find module for the custom `Boost` installation at work]
|-> examples
|-> include [*.h]
|-> src [*.src]
|-> test
|-> options [CMakeFile.txt and .cpp file for the test]
|
|-> CMakeFile.txt [Root file]
I have two machines: my laptop, with Linux Mint 16 and g++ 4.8, and my work computer, with Windows 8.1, the MinGW suite and g++ 4.5.
The project (development branch!) builds fine with make, but afterwards, when I try to run the tests with make test in Windows I always end getting these errors:
The program can't start because libboost_unit_test_framework-mgw45-mt-1_51.dll is missing
and in the terminal:
Running tests...
"C:\Program Files (x86)\CMake 2.8\bin\ctest.exe" --force-new-ctest-process
Test project D:/PROJECTS/osgGML/build
Start 1: testOptions
1/1 Test #1: testOptions ......................***Exception: Other 1.84 sec
0% tests passed, 1 tests failed out of 1
Total Test time (real) = 1.84 sec
The following tests FAILED:
1 - testOptions (OTHER_FAULT)
Errors while running CTest
mingw32-make: *** [test] Error 8
Whereas in Linux (tried in Linux Mint 16 and in the Travis-CI machine, it works).
The "root" CMakeFile:
cmake_minimum_required(VERSION 2.8 FATAL_ERROR)
project(osgGML)
option(BUILD_SHARED_LIBS "Build shared libs" ON)
option(BUILD_EXAMPLES OFF)
option(BUILD_TESTS OFF)
option(BUILD_USE_LAMBDAS OFF)
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Release CACHE STRING "Type of build" FORCE)
endif(NOT CMAKE_BUILD_TYPE)
set(LIBRARY_NAME "osgGML")
set(EXPORT_NAME "depends")
set(CMAKE_VERBOSE_MAKEFILE ON CACHE BOOL "" FORCE)
set(CMAKE_COLOR_MAKEFILE ON)
mark_as_advanced(CMAKE_VERBOSE_MAKEFILE)
# Common locatoins for Unix and Mac OS X
set(DEFAULT_BIN_SUBDIR bin)
set(DEFAULT_LIB_SUBDIR lib)
set(DEFAULT_SHARE_SUBDIR share/cmake)
set(DEFAULT_INCLUDE_SUBDIR include)
set(OSGGML_BIN_SUBDIR ${DEFAULT_BIN_SUBDIR} CACHE STRING
"Subdirectory where executables will be installed")
set(OSGGML_LIB_SUBDIR ${DEFAULT_LIB_SUBDIR} CACHE STRING
"Subdirectory where libraries will be installed")
set(OSGGML_INCLUDE_SUBDIR ${DEFAULT_INCLUDE_SUBDIR} CACHE STRING
"Subdirectory where header files will be installed")
set(OSGGML_SHARE_SUBDIR ${DEFAULT_SHARE_SUBDIR} CACHE STRING
"Subdirectory where data will be installed")
# Full paths for the installation
set(OSGGML_BIN_DIR ${OSGGML_BIN_SUBDIR})
set(OSGGML_LIB_DIR ${OSGGML_LIB_SUBDIR})
set(OSGGML_INCLUDE_DIR ${OSGGML_INCLUDE_SUBDIR})
set(OSGGML_SHARE_DIR ${OSGGML_SHARE_SUBDIR})
##
# Set the build postfix extension according to what configuration is being built.
set(CMAKE_DEBUG_POSTFIX "d" CACHE STRING "add a postfix, usually d")
set(CMAKE_RELEASE_POSTFIX "" CACHE STRING "add a postfix, usually empty")
set(CMAKE_RELWITHDEBINFO_POSTFIX "rd" CACHE STRING "empty")
set(CMAKE_MINSIZEREL_POSTFIX "s" CACHE STRING "add a postfix, empty")
if(CMAKE_BUILD_TYPE MATCHES "Release")
set(CMAKE_BUILD_POSTFIX "${CMAKE_RELEASE_POSTFIX}")
elseif(CMAKE_BUILD_TYPE MATCHES "MinSizeRel")
set(CMAKE_BUILD_POSTFIX "${CMAKE_MINSIZEREL_POSTFIX}")
elseif(CMAKE_BUILD_TYPE MATCHES "RelWithDebInfo")
set(CMAKE_BUILD_POSTFIX "${CMAKE_RELWITHDEBINFO_POSTFIX}")
elseif(CMAKE_BUILD_TYPE MATCHES "Debug")
set(CMAKE_BUILD_POSTFIX "${CMAKE_DEBUG_POSTFIX}")
else()
set(CMAKE_BUILD_POSTFIX "")
endif()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra")
if(BUILD_USE_LAMBDAS)
if("${CMAKE_CXX_COMPILER_ID}" MATCHES "GNU")
execute_process(
COMMAND ${CMAKE_CXX_COMPILER} -dumpversion OUTPUT_VARIABLE GCC_VERSION)
if((GCC_VERSION VERSION_GREATER 4.7 OR GCC_VERSION VERSION_EQUAL 4.7))
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
else()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x")
endif()
endif()
endif()
find_package(OpenSceneGraph REQUIRED COMPONENTS
osg
osgDB
OpenThreads
)
include_directories(${OPENSCENEGRAPH_INCLUDE_DIRS})
link_directories(${OPENSCENEGRAPH_LIBRARY_DIRS})
# HACK!!!! DO THIS PROPERLY!!!
link_directories(${OPENSCENEGRAPH_BINARY_DIRS}/osgPlugins-3.2.1/)
set(DEPENDENCIES ${OPENSCENEGRAPH_LIBRARIES})
##
set(osgGML_INCLUDE_DIRS "${PROJECT_SOURCE_DIR}/include")
set(osgGML_SOURCE_DIRS "${PROJECT_SOURCE_DIR}/src")
set(HEADERS ${osgGML_INCLUDE_DIRS}/DebugUtils.h
${osgGML_INCLUDE_DIRS}/GmlOptions.h
${osgGML_INCLUDE_DIRS}/GmlOptionsIO.h
${osgGML_INCLUDE_DIRS}/GraphVisitor.h
${osgGML_INCLUDE_DIRS}/ReaderWriterGML.h
${osgGML_INCLUDE_DIRS}/Setup.h
)
set(SOURCES ${osgGML_SOURCE_DIRS}/GmlOptions.cpp
${osgGML_SOURCE_DIRS}/GmlOptionsIO.cpp
${osgGML_SOURCE_DIRS}/GraphVisitor.cpp
${osgGML_SOURCE_DIRS}/ReaderWriterGML.cpp
)
include_directories(${osgGML_INCLUDE_DIRS})
add_library(${LIBRARY_NAME} ${SOURCES})
target_link_libraries(${LIBRARY_NAME} ${DEPENDENCIES})
#
install(TARGETS ${LIBRARY_NAME}
EXPORT ${EXPORT_NAME}
RUNTIME DESTINATION ${OSGGML_BIN_DIR}
LIBRARY DESTINATION ${OSGGML_LIB_DIR}
ARCHIVE DESTINATION ${OSGGML_LIB_DIR}
)
install(FILES ${HEADERS} DESTINATION ${OSGGML_INCLUDE_DIR})
if(BUILD_EXAMPLES)
message(STATUS "Building EXAMPLES.")
set(OSGGML_EXAMPLES_BIN_DIR share/examples)
add_subdirectory(examples/options)
add_subdirectory(examples/visitor)
endif()
if(BUILD_TESTS)
enable_testing()
message(STATUS "Building TESTS")
set(OSGGML_TESTS_BIN_DIR share/tests)
add_subdirectory(test/options)
endif()
###########
add_subdirectory(cmake/conf)
###########
The CMakeFile for the test:
cmake_minimum_required(VERSION 2.8 FATAL_ERROR)
project(OptionsTesting)
set(CMAKE_BUILD_TYPE "RELEASE")
set(EXECUTABLE_OUTPUT_PATH ${CMAKE_BINARY_DIR}/bin)
set(LIBRARY_OUTPUT_PATH ${CMAKE_BINARY_DIR}/lib)
link_directories(${CMAKE_BINARY_DIR}/lib)
include_directories(../../include)
set(DEPENDENCIES ${DEPENDENCIES} ${LIBRARY_NAME})
# Hack for my weird Boost installation in Windows.
if(WIN32 AND MINGW)
set(BOOST_ROOT "D:/PROYECTOS/SITEGI/LIBRERIAS/Boost")
include(../../cmake/find/find_boost.cmake)
else()
find_package(Boost REQUIRED COMPONENTS unit_test_framework)
endif()
include_directories (${Boost_INCLUDE_DIRS})
set(DEPENDENCIES ${DEPENDENCIES} ${Boost_LIBRARIES})
set(Boost_USE_STATIC_LIBS OFF)
set(Boost_USE_MULTITHREADED ON)
set(Boost_USE_STATIC_RUNTIME OFF)
set(BOOST_ALL_DYN_LINK ON)
find_package(OpenSceneGraph REQUIRED COMPONENTS osg osgDB OpenThreads)
include_directories(${OPENSCENEGRAPH_INCLUDE_DIRS})
link_directories(${OPENSCENEGRAPH_LIBRARY_DIRS})
set(DEPENDENCIES ${DEPENDENCIES} ${OPENSCENEGRAPH_LIBRARIES})
file(GLOB TEST_SRCS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} *.cpp)
set(TEST_DEST ${CMAKE_BINARY_DIR}/testBinaries)
set(TEST_LINK_DEPS ${TEST_LINK_DEPS} "-Wl,-rpath,${CMAKE_BINARY_DIR}")
set(TEST_LINK_DEPS ${TEST_LINK_DEPS} "-Wl,-rpath,${Boost_LIBRARY_DIRS}")
foreach(testSrc ${TEST_SRCS})
#Extract the filename without an extension (NAME_WE)
get_filename_component(testName ${testSrc} NAME_WE)
add_executable(${testName} ${testSrc})
target_link_libraries(${testName} ${DEPENDENCIES})
set_target_properties(${testName} PROPERTIES
RUNTIME_OUTPUT_DIRECTORY ${TEST_DEST}
LINK_FLAGS "${TEST_LINK_DEPS}"
)
add_test(NAME ${testName}
WORKING_DIRECTORY ${TEST_DEST}
COMMAND ${TEST_DEST}/${testName}
)
endforeach(testSrc)
I'm trying to tell CMake to use the newly-generated osgGML library in the build directory when linking the test executable (I have checked, libosgGML.dll is in ${CMAKE_BINARY_DIR}.
In this version of the file, I added the rpath to the library. In a previous one, aside from -Wl,-rpath,<library_dirs> I also specified the -L<library_dirs> right after that.
I've tried to link directly the dll's too, but nothing worked.
How can I tell the test executable to "find" the libraries in their respective directories, instead of copying them to the executable dir?