I'm trying to compile a small project which has both BOOST and PETSc dependencies. I couldn't configure my top level CMakeList in a way to include and link these external libraries to my project. It seems that I can achieve this objective by configuring each CMakeList of each library / executable that I've built, however I'm looking for a more practical way to do so.
Is there any?
As requested, this is my top level CMakeList:
CMAKE_MINIMUM_REQUIRED(VERSION 3.2)
# WHERE THE FILES WILL BE
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/libs)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/shared_libs)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/apps)
# BOOST MANAGEMENT
find_package(Boost)
if(Boost_FOUND)
include_directories(${Boost_INCLUDE_DIR})
endif()
# COMPILER SETTINGS
set(CMAKE_C_COMPILER "mpicc")
set(CMAKE_CXX_COMPILER "mpicxx") # both compilers are in the path
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -Wall -Wextra -pedantic -std=c++11")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -pedantic -std=c++11")
# SET BUILD TYPE
set(CMAKE_BUILD_TYPE "RELEASE")
set(CMAKE_BUILD_DIR "Release")
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_ARCHIVE_OUTPUT_DIRECTORY}/${CMAKE_BUILD_DIR})
# ABOUT THE PROJECT
project(MinorTest)
set(VERSION_MAJOR "1")
set(VERSION_MINOR "0")
set(VERSION_PATCH "0")
set(VERSION "${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}")
# ADD SUBDIRECTORIES
add_subdirectory(MuParserLib)
add_subdirectory(UtilsLib)
#add_subdirectory(UtilsTest)
add_subdirectory(ScriptSystemLib)
add_subdirectory(ScriptSystemTest)
The following errors are shown when linking the executable from ScriptSystemTest project:
/usr/lib/gcc/x86_64-pc-linux-gnu/6.3.1/../../../../lib/crt1.o: In function `_start':
(.text+0x20): undefined reference to `main'
CMakeFiles/ScriptSystemTest.dir/source/TestScriptSystem.cpp.o: In function `init_unit_test_suite(int, char**)':
/home/felipe/Libraries/boost_1_63_0/boost/test/unit_test_suite.hpp:346: undefined reference to `boost::unit_test::framework::master_test_suite()'
CMakeFiles/ScriptSystemTest.dir/source/TestScriptSystem.cpp.o: In function `TestParser::test_method()':
/home/felipe/Workspace/Z_TestEFv/ScriptSystemTest/source/TestScriptSystem.cpp:20: undefined reference to `boost::unit_test::unit_test_log_t::set_checkpoint(boost::unit_test::basic_cstring<char const>, unsigned long, boost::unit_test::basic_cstring<char const>)'
/home/felipe/Workspace/Z_TestEFv/ScriptSystemTest/source/TestScriptSystem.cpp:20: undefined reference to `boost::test_tools::tt_detail::report_assertion(boost::test_tools::assertion_result const&, boost::unit_test::lazy_ostream const&, boost::unit_test::basic_cstring<char const>, unsigned long, boost::test_tools::tt_detail::tool_level, boost::test_tools::tt_detail::check_type, unsigned long, ...)'
Finally, this is the ScriptSystemTest CMakeList:
project(ScriptSystemTest)
#
include_directories(${CMAKE_SOURCE_DIR}/${PROJECT_NAME}/include)
include_directories(${CMAKE_SOURCE_DIR}/UtilsLib/include)
include_directories(${CMAKE_SOURCE_DIR}/ScriptSystemLib/include)
include_directories(${CMAKE_SOURCE_DIR}/MuParserLib/include)
#
link_directories(${CMAKE_SOURCE_DIR}/UtilsLib/source)
link_directories(${CMAKE_SOURCE_DIR}/ScriptSystemLib/source)
link_directories(${CMAKE_SOURCE_DIR}/MuParserLib/source)
# SEARCH FOR .CPP FILES
file(GLOB ${PROJECT_NAME}_sources ${CMAKE_SOURCE_DIR}/${PROJECT_NAME}/source/ *.cpp)
#
add_executable(${PROJECT_NAME} ${${PROJECT_NAME}_sources})
#
target_link_libraries(${PROJECT_NAME} UtilsLib)
target_link_libraries(${PROJECT_NAME} ScriptSystemLib)
target_link_libraries(${PROJECT_NAME} MuParserLib)
#
install(
TARGETS ${PROJECT_NAME}
RUNTIME DESTINATION apps
)