Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify CMake code on linking against required dependencies #43

Merged
merged 2 commits into from
Oct 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 8 additions & 24 deletions ThermoFun/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,32 +25,16 @@ endif()

# Create a library using the collected source files
add_library(ThermoFun ${HEADER_FILES} ${SOURCE_FILES})

# Add aliases for ThermoFun shared and static libraries
add_library(ThermoFun::ThermoFun ALIAS ThermoFun)

if(ChemicalFun_FOUND)
target_link_libraries(ThermoFun PUBLIC ChemicalFun::ChemicalFun)
endif()

target_link_libraries(ThermoFun PRIVATE spdlog::spdlog)


if (CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
#link_directories("/usr/local/lib")
else()
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
# build options for MacOS
else()
# build options for Linux
# Find library and software dependencies
#find_package(Boost 1.58.0 REQUIRED)
find_package(nlohmann_json REQUIRED)
# Specify the dependency libraries to link against
target_link_libraries(ThermoFun
# PRIVATE Boost::boost
PRIVATE nlohmann_json::nlohmann_json)
endif()
endif()
# Link ThermoFun against all required dependencies
target_link_libraries(ThermoFun
PUBLIC ChemicalFun::ChemicalFun
PRIVATE spdlog::spdlog
PRIVATE nlohmann_json::nlohmann_json
)

# Specify the include directories of the library target
target_include_directories(ThermoFun
Expand All @@ -64,7 +48,7 @@ install(TARGETS ThermoFun
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT libraries
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT libraries
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT libraries)

# Install debug symbols
if(MSVC)
install(
Expand Down
17 changes: 7 additions & 10 deletions cmake/modules/ThermoFunFindDeps.cmake
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
# Find Boost library
#find_package(Boost REQUIRED)


# Find pybind11 library (if needed)
if(TFUN_BUILD_PYTHON)
find_package(pybind11 REQUIRED)
Expand All @@ -13,16 +9,17 @@ if(TFUN_BUILD_PYTHON)
endif()
endif()

find_package(nlohmann_json REQUIRED)
if(NOT nlohmann_json_FOUND)
message(FATAL_ERROR "nlohmann_json library not found")
endif()

find_package(ChemicalFun REQUIRED)
if(NOT ChemicalFun_FOUND)
message(FATAL_ERROR "ChemicalFun library not found")
else()
message(STATUS "Found ChemicalFun v${ChemicalFun_VERSION}")
message(FATAL_ERROR "ChemicalFun library not found")
endif()

find_package(spdlog REQUIRED)
if(NOT spdlog_FOUND)
message(FATAL_ERROR "spdlog not found")
else()
message(STATUS "Found spdlog v${spdlog_VERSION}")
message(FATAL_ERROR "spdlog not found")
endif()