-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
50 lines (43 loc) · 1.75 KB
/
CMakeLists.txt
File metadata and controls
50 lines (43 loc) · 1.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
cmake_minimum_required(VERSION 3.25)
project(ModelecProject VERSION 1.1.0 LANGUAGES CXX DESCRIPTION "Modelec Lib")
# Define default install path if not provided
if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
set(CMAKE_INSTALL_PREFIX "/usr/local" CACHE PATH "..." FORCE)
endif()
# Library and executable paths
include(GNUInstallDirs)
# Function to safely add a component
function(add_component component_dir)
if(IS_DIRECTORY ${component_dir})
if(EXISTS ${component_dir}/CMakeLists.txt)
message(STATUS "Adding component: ${component_dir}")
add_subdirectory(${component_dir})
else()
message(WARNING "Skipping component: ${component_dir} (no CMakeLists.txt found)")
endif()
else()
message(WARNING "Skipping invalid directory: ${component_dir}")
endif()
endfunction()
# Automatically add subdirectories found in the components directory
file(GLOB children RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}/components ${CMAKE_CURRENT_SOURCE_DIR}/components/*)
foreach(child ${children})
add_component(${CMAKE_CURRENT_SOURCE_DIR}/components/${child})
endforeach()
# Configuration for installation and find_package()
include(CMakePackageConfigHelpers)
configure_package_config_file(
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/ModelecConfig.cmake.in"
"${CMAKE_CURRENT_BINARY_DIR}/ModelecConfig.cmake"
INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/Modelec
)
install(FILES
"${CMAKE_CURRENT_BINARY_DIR}/ModelecConfig.cmake"
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/Modelec
)
# Install the export set for later use by find_package()
install(EXPORT ModelecTargets
FILE ModelecTargets.cmake
NAMESPACE Modelec::
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/Modelec
)