Skip to content
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
6 changes: 6 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,9 @@ if(${BUILD_TESTING})
${PROJECT_NAME}
)
endif()

include(cmake/install_target.cmake)
install_library(
${PROJECT_NAME}
"${CMAKE_CURRENT_SOURCE_DIR}/include/${PROJECT_NAME}"
)
68 changes: 68 additions & 0 deletions cmake/install_target.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
# Copyright 2025 NWChemEx-Project
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

include_guard()

function(write_config_file wcf_file)
file(WRITE "${wcf_file}" "") # Erases it if it already exists
file(APPEND
"${wcf_file}"
"get_filename_component(_IL_CONFIG_DIR "
"\"\${CMAKE_CURRENT_LIST_FILE}\" PATH)\n"
)
file(APPEND
"${wcf_file}"
"include(\"\${_IL_CONFIG_DIR}/${il_name}Targets.cmake\")\n"
)
endfunction()

function(install_library il_name il_header_dir)
#TODO: Get these values programmatically
set(_il_archive_dir lib)
set(_il_library_dir lib)
set(_il_runtime_dir bin)
set(_il_includes_dir include)

# -- Install target that is a library --
install(TARGETS ${il_name}
EXPORT ${il_name}Targets
ARCHIVE DESTINATION "${_il_archive_dir}"
LIBRARY DESTINATION "${_il_library_dir}"
RUNTIME DESTINATION "${_il_runtime_dir}"
INCLUDES DESTINATION "${_il_includes_dir}"
)

# -- Install CMake Config Files --
install(EXPORT ${il_name}Targets
FILE ${il_name}Targets.cmake
NAMESPACE nwx::
DESTINATION "${_il_library_dir}/cmake/${il_name}"
)

set(_il_config_file "${CMAKE_CURRENT_BINARY_DIR}/${il_name}Config.cmake")
write_config_file("${_il_config_file}")

install(FILES "${_il_config_file}"
DESTINATION "${_il_library_dir}/cmake/${il_name}"
)

# -- Install Headers --
#TODO: Assert il_header_dir isn't empty
install(DIRECTORY "${il_header_dir}"
DESTINATION "${_il_includes_dir}"
FILES_MATCHING
PATTERN "*.hpp"
PATTERN "*.h"
)
endfunction()