Skip to content
Snippets Groups Projects
Commit e39c79fb authored by Sebastian Eibl's avatar Sebastian Eibl
Browse files

reworked find_package

parent 5702f30d
No related branches found
No related tags found
No related merge requests found
cmake_minimum_required(VERSION 3.20) cmake_minimum_required(VERSION 3.20)
project(01_find_package project(02_find_package
LANGUAGES CXX) LANGUAGES CXX)
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake") list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
...@@ -8,8 +8,8 @@ list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake") ...@@ -8,8 +8,8 @@ list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
########################## ##########################
# EXECUTABLE # EXECUTABLE
########################## ##########################
find_package(Integrator REQUIRED) find_package(Math REQUIRED)
add_executable(calc_pi) add_executable(calculator)
target_sources(calc_pi PRIVATE app/main.cpp) target_sources(calculator PRIVATE app/main.cpp)
target_link_libraries(calc_pi PRIVATE Integrator::Integrator) target_link_libraries(calculator PRIVATE Math::Math)
#include <integrator/mc_pi.hpp> #include <add.hpp>
#include <iostream> #include <iostream>
int main(int argc, char** argv) int main(int /*argc*/, char** /*argv*/)
{ {
if (argc != 2) exit(EXIT_FAILURE); std::cout << add(2, 3) << std::endl;
std::cout << calcPI(std::stoll(argv[1])) << std::endl;
exit(EXIT_SUCCESS); exit(EXIT_SUCCESS);
} }
find_path(Integrator_INCLUDE_DIR integrator/mc_pi.hpp) find_path(Math_INCLUDE_DIR add.hpp)
find_library(Integrator_LIBRARY Integrator) find_library(Math_LIBRARY math)
include(FindPackageHandleStandardArgs) include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(Integrator DEFAULT_MSG find_package_handle_standard_args(Math DEFAULT_MSG
Integrator_INCLUDE_DIR Integrator_LIBRARY) Math_INCLUDE_DIR Math_LIBRARY)
if (Integrator_FOUND) if (Math_FOUND)
set(Integrator_LIBRARIES ${Integrator_LIBRARY}) set(Math_LIBRARIES ${Math_LIBRARY})
set(Integrator_INCLUDE_DIRS ${Integrator_INCLUDE_DIR}) set(Math_INCLUDE_DIRS ${Math_INCLUDE_DIR})
if (NOT TARGET Integrator::Integrator) if (NOT TARGET Math::Math)
add_library(Integrator::Integrator UNKNOWN IMPORTED) add_library(Math::Math UNKNOWN IMPORTED)
set_target_properties(Integrator::Integrator PROPERTIES set_target_properties(Math::Math PROPERTIES
IMPORTED_LOCATION "${Integrator_LIBRARY}") IMPORTED_LOCATION "${Math_LIBRARY}")
target_include_directories(Integrator::Integrator INTERFACE "${Integrator_INCLUDE_DIR}") target_include_directories(Math::Math INTERFACE "${Math_INCLUDE_DIR}")
endif () endif ()
endif () endif ()
mark_as_advanced( mark_as_advanced(
Integrator_INCLUDE_DIR Math_INCLUDE_DIR
Integrator_LIBRARY Math_LIBRARY
) )
\ No newline at end of file
all:
$(CC) -shared -fPIC -Iinclude -o lib/libmath.so src/add.cpp
#pragma once
int add(const int lhs, const int rhs);
\ No newline at end of file
#include "add.hpp"
int add(const int lhs, const int rhs) { return lhs + rhs; }
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment