Skip to content

Commit 382b53c

Browse files
committed
add cmake configuration
1 parent 090d448 commit 382b53c

File tree

4 files changed

+262
-28
lines changed

4 files changed

+262
-28
lines changed

compile/build.jl

Lines changed: 62 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,65 @@
11
using PackageCompiler
2-
using ArgParse
3-
4-
s = ArgParseSettings()
5-
@add_arg_table s begin
6-
"--source-dir"
7-
help = "Directory containing the source files"
8-
arg_type = String
9-
default = splitdir(@__DIR__) |> first
10-
11-
"--output-dir"
12-
help = "Directory to save the compiled library"
13-
arg_type = String
14-
default = joinpath(splitdir(@__DIR__) |> first, "JetReconstructionCompiled")
2+
import ArgParse
3+
import JetReconstruction
4+
5+
function parse_args(args)
6+
s = ArgParse.ArgParseSettings()
7+
ArgParse.@add_arg_table s begin
8+
"--source-dir"
9+
help = "Directory containing the source files"
10+
arg_type = String
11+
default = splitdir(@__DIR__) |> first
12+
13+
"--output-dir", "-o"
14+
help = "Directory to save the compiled library"
15+
arg_type = String
16+
default = joinpath(splitdir(@__DIR__) |> first, "JetReconstructionCompiled")
17+
end
18+
19+
return ArgParse.parse_args(args, s)
20+
end
21+
22+
function configure_file(template_path::String, output_path::String,
23+
replacements::Dict{String, String})
24+
template = read(template_path, String)
25+
for (key, value) in replacements
26+
template = replace(template, "@$(key)@" => value)
27+
end
28+
open(output_path, "w") do io
29+
write(io, template)
30+
end
1531
end
1632

17-
parsed_args = parse_args(s)
18-
source_dir = parsed_args["source-dir"]
19-
output_dir = parsed_args["output-dir"]
20-
21-
@info "Compiling package from $source_dir"
22-
@info "Creating library in $output_dir"
23-
PackageCompiler.create_library(source_dir, output_dir;
24-
lib_name = "jetreconstruction",
25-
header_files = [joinpath(@__DIR__, "include",
26-
"JetReconstruction.h")],
27-
precompile_execution_file = [joinpath(@__DIR__,
28-
"precompile_execution.jl")],
29-
incremental = false,
30-
filter_stdlibs = true,
31-
force = true)
33+
function (@main)(args)
34+
parsed_args = parse_args(args)
35+
source_dir = parsed_args["source-dir"]
36+
output_dir = parsed_args["output-dir"]
37+
38+
@info "Compiling package from $source_dir"
39+
@info "Creating library in $output_dir"
40+
PackageCompiler.create_library(source_dir, output_dir;
41+
lib_name = "jetreconstruction",
42+
header_files = [joinpath(@__DIR__, "include",
43+
"JetReconstruction.h")],
44+
precompile_execution_file = [joinpath(@__DIR__,
45+
"precompile_execution.jl")],
46+
incremental = false,
47+
filter_stdlibs = true,
48+
force = true)
49+
50+
cmake_input = joinpath(@__DIR__, "cmake", "JetReconstruction")
51+
cmake_output = joinpath(output_dir, "lib", "cmake", "JetReconstruction")
52+
53+
version = pkgversion(JetReconstruction)
54+
cmake_project_version = "$(version.major).$(version.minor).$(version.patch)"
55+
56+
@info "Copying CMake file to $cmake_output"
57+
mkpath(cmake_output)
58+
cp_file(input_dir, basename, output_dir) = cp(joinpath(input_dir, basename),
59+
joinpath(output_dir, basename))
60+
cp_file(cmake_input, "JetReconstructionConfig.cmake", cmake_output)
61+
cp_file(cmake_input, "JetReconstructionTargets.cmake", cmake_output)
62+
configure_file(joinpath(cmake_input, "JetReconstructionConfigVersion.cmake.in"),
63+
joinpath(cmake_output, "JetReconstructionConfigVersion.cmake"),
64+
Dict("PROJECT_VERSION" => cmake_project_version))
65+
end
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# Config file for the JetReconstruction.jl package
2+
# Manualy adjusted from standard cmake generated config file
3+
get_filename_component(PACKAGE_PREFIX_DIR "${CMAKE_CURRENT_LIST_DIR}/../../../" ABSOLUTE)
4+
5+
macro(set_and_check _var _file)
6+
set(${_var} "${_file}")
7+
if(NOT EXISTS "${_file}")
8+
message(FATAL_ERROR "File or directory ${_file} referenced by variable ${_var} does not exist !")
9+
endif()
10+
endmacro()
11+
12+
macro(check_required_components _NAME)
13+
foreach(comp ${${_NAME}_FIND_COMPONENTS})
14+
if(NOT ${_NAME}_${comp}_FOUND)
15+
if(${_NAME}_FIND_REQUIRED_${comp})
16+
set(${_NAME}_FOUND FALSE)
17+
endif()
18+
endif()
19+
endforeach()
20+
endmacro()
21+
22+
####################################################################################
23+
24+
# - Create relocatable paths to headers.
25+
# NOTE: Do not strictly need paths as all usage requirements are encoded in
26+
# the imported targets created later.
27+
set_and_check(JetReconstruction_INCLUDE_DIR "${PACKAGE_PREFIX_DIR}/include")
28+
29+
# - Create path to installed read-only data files (e.g. yaml files)
30+
set_and_check(JetReconstruction_DATA_DIR "${PACKAGE_PREFIX_DIR}/share/julia")
31+
32+
# - Include the targets file to create the imported targets that a client can
33+
# link to (libraries) or execute (programs)
34+
include("${CMAKE_CURRENT_LIST_DIR}/JetReconstructionTargets.cmake")
35+
36+
# print the default "Found:" message and check library location
37+
include(FindPackageHandleStandardArgs)
38+
get_property(TEST_JETRECONSTRUCTION_LIBRARY TARGET JetReconstruction::JetReconstruction PROPERTY LOCATION)
39+
find_package_handle_standard_args(JetReconstruction DEFAULT_MSG CMAKE_CURRENT_LIST_FILE TEST_JETRECONSTRUCTION_LIBRARY)
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
# This is a basic version file for the Config-mode of find_package().
2+
# It is used by write_basic_package_version_file() as input file for configure_file()
3+
# to create a version-file which can be installed along a config.cmake file.
4+
#
5+
# The created file sets PACKAGE_VERSION_EXACT if the current version string and
6+
# the requested version string are exactly the same and it sets
7+
# PACKAGE_VERSION_COMPATIBLE if the current version is >= requested version,
8+
# but only if the requested major version is the same as the current one.
9+
# The variable CVF_VERSION must be set before calling configure_file().
10+
11+
12+
set(PACKAGE_VERSION "@PROJECT_VERSION@")
13+
14+
if(PACKAGE_VERSION VERSION_LESS PACKAGE_FIND_VERSION)
15+
set(PACKAGE_VERSION_COMPATIBLE FALSE)
16+
else()
17+
18+
if(PACKAGE_VERSION MATCHES "^([0-9]+)\\.")
19+
set(CVF_VERSION_MAJOR "${CMAKE_MATCH_1}")
20+
if(NOT CVF_VERSION_MAJOR VERSION_EQUAL 0)
21+
string(REGEX REPLACE "^0+" "" CVF_VERSION_MAJOR "${CVF_VERSION_MAJOR}")
22+
endif()
23+
else()
24+
set(CVF_VERSION_MAJOR ${PACKAGE_VERSION})
25+
endif()
26+
27+
if(PACKAGE_FIND_VERSION_RANGE)
28+
# both endpoints of the range must have the expected major version
29+
math (EXPR CVF_VERSION_MAJOR_NEXT "${CVF_VERSION_MAJOR} + 1")
30+
if (NOT PACKAGE_FIND_VERSION_MIN_MAJOR STREQUAL CVF_VERSION_MAJOR
31+
OR ((PACKAGE_FIND_VERSION_RANGE_MAX STREQUAL "INCLUDE" AND NOT PACKAGE_FIND_VERSION_MAX_MAJOR STREQUAL CVF_VERSION_MAJOR)
32+
OR (PACKAGE_FIND_VERSION_RANGE_MAX STREQUAL "EXCLUDE" AND NOT PACKAGE_FIND_VERSION_MAX VERSION_LESS_EQUAL CVF_VERSION_MAJOR_NEXT)))
33+
set(PACKAGE_VERSION_COMPATIBLE FALSE)
34+
elseif(PACKAGE_FIND_VERSION_MIN_MAJOR STREQUAL CVF_VERSION_MAJOR
35+
AND ((PACKAGE_FIND_VERSION_RANGE_MAX STREQUAL "INCLUDE" AND PACKAGE_VERSION VERSION_LESS_EQUAL PACKAGE_FIND_VERSION_MAX)
36+
OR (PACKAGE_FIND_VERSION_RANGE_MAX STREQUAL "EXCLUDE" AND PACKAGE_VERSION VERSION_LESS PACKAGE_FIND_VERSION_MAX)))
37+
set(PACKAGE_VERSION_COMPATIBLE TRUE)
38+
else()
39+
set(PACKAGE_VERSION_COMPATIBLE FALSE)
40+
endif()
41+
else()
42+
if(PACKAGE_FIND_VERSION_MAJOR STREQUAL CVF_VERSION_MAJOR)
43+
set(PACKAGE_VERSION_COMPATIBLE TRUE)
44+
else()
45+
set(PACKAGE_VERSION_COMPATIBLE FALSE)
46+
endif()
47+
48+
if(PACKAGE_FIND_VERSION STREQUAL PACKAGE_VERSION)
49+
set(PACKAGE_VERSION_EXACT TRUE)
50+
endif()
51+
endif()
52+
endif()
53+
54+
55+
# if the installed or the using project don't have CMAKE_SIZEOF_VOID_P set, ignore it:
56+
if("${CMAKE_SIZEOF_VOID_P}" STREQUAL "" OR "8" STREQUAL "")
57+
return()
58+
endif()
59+
60+
# check that the installed version has the same 32/64bit-ness as the one which is currently searching:
61+
if(NOT CMAKE_SIZEOF_VOID_P STREQUAL "8")
62+
math(EXPR installedBits "8 * 8")
63+
set(PACKAGE_VERSION "${PACKAGE_VERSION} (${installedBits}bit)")
64+
set(PACKAGE_VERSION_UNSUITABLE TRUE)
65+
endif()
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
# Generated by CMake
2+
3+
if("${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}" LESS 2.8)
4+
message(FATAL_ERROR "CMake >= 2.8.0 required")
5+
endif()
6+
if(CMAKE_VERSION VERSION_LESS "3.0.0")
7+
message(FATAL_ERROR "CMake >= 3.0.0 required")
8+
endif()
9+
cmake_policy(PUSH)
10+
cmake_policy(VERSION 3.0.0...3.28)
11+
12+
# Commands may need to know the format version.
13+
set(CMAKE_IMPORT_FILE_VERSION 1)
14+
15+
# Protect against multiple inclusion, which would fail when already imported targets are added once more.
16+
set(_cmake_targets_defined "")
17+
set(_cmake_targets_not_defined "")
18+
set(_cmake_expected_targets "")
19+
foreach(_cmake_expected_target IN ITEMS JetReconstruction::JetReconstruction)
20+
list(APPEND _cmake_expected_targets "${_cmake_expected_target}")
21+
if(TARGET "${_cmake_expected_target}")
22+
list(APPEND _cmake_targets_defined "${_cmake_expected_target}")
23+
else()
24+
list(APPEND _cmake_targets_not_defined "${_cmake_expected_target}")
25+
endif()
26+
endforeach()
27+
unset(_cmake_expected_target)
28+
if(_cmake_targets_defined STREQUAL _cmake_expected_targets)
29+
unset(_cmake_targets_defined)
30+
unset(_cmake_targets_not_defined)
31+
unset(_cmake_expected_targets)
32+
unset(CMAKE_IMPORT_FILE_VERSION)
33+
cmake_policy(POP)
34+
return()
35+
endif()
36+
if(NOT _cmake_targets_defined STREQUAL "")
37+
string(REPLACE ";" ", " _cmake_targets_defined_text "${_cmake_targets_defined}")
38+
string(REPLACE ";" ", " _cmake_targets_not_defined_text "${_cmake_targets_not_defined}")
39+
message(FATAL_ERROR "Some (but not all) targets in this export set were already defined.\nTargets Defined: ${_cmake_targets_defined_text}\nTargets not yet defined: ${_cmake_targets_not_defined_text}\n")
40+
endif()
41+
unset(_cmake_targets_defined)
42+
unset(_cmake_targets_not_defined)
43+
unset(_cmake_expected_targets)
44+
45+
46+
# Compute the installation prefix relative to this file.
47+
get_filename_component(_IMPORT_PREFIX "${CMAKE_CURRENT_LIST_FILE}" PATH)
48+
get_filename_component(_IMPORT_PREFIX "${_IMPORT_PREFIX}" PATH)
49+
get_filename_component(_IMPORT_PREFIX "${_IMPORT_PREFIX}" PATH)
50+
get_filename_component(_IMPORT_PREFIX "${_IMPORT_PREFIX}" PATH)
51+
if(_IMPORT_PREFIX STREQUAL "/")
52+
set(_IMPORT_PREFIX "")
53+
endif()
54+
55+
# Create imported target JetReconstruction::JetReconstruction
56+
add_library(JetReconstruction::JetReconstruction SHARED IMPORTED)
57+
set_target_properties(JetReconstruction::JetReconstruction PROPERTIES
58+
INTERFACE_INCLUDE_DIRECTORIES "${_IMPORT_PREFIX}/include"
59+
IMPORTED_LOCATION "${_IMPORT_PREFIX}/lib/libjetreconstruction.so"
60+
IMPORTED_SONAME "libjetreconstruction.so"
61+
)
62+
63+
# Cleanup temporary variables.
64+
set(_IMPORT_PREFIX)
65+
66+
# Loop over all imported files and verify that they actually exist
67+
foreach(_cmake_target IN LISTS _cmake_import_check_targets)
68+
if(CMAKE_VERSION VERSION_LESS "3.28"
69+
OR NOT DEFINED _cmake_import_check_xcframework_for_${_cmake_target}
70+
OR NOT IS_DIRECTORY "${_cmake_import_check_xcframework_for_${_cmake_target}}")
71+
foreach(_cmake_file IN LISTS "_cmake_import_check_files_for_${_cmake_target}")
72+
if(NOT EXISTS "${_cmake_file}")
73+
message(FATAL_ERROR "The imported target \"${_cmake_target}\" references the file
74+
\"${_cmake_file}\"
75+
but this file does not exist. Possible reasons include:
76+
* The file was deleted, renamed, or moved to another location.
77+
* An install or uninstall procedure did not complete successfully.
78+
* The installation package was faulty and contained
79+
\"${CMAKE_CURRENT_LIST_FILE}\"
80+
but not all the files it references.
81+
")
82+
endif()
83+
endforeach()
84+
endif()
85+
unset(_cmake_file)
86+
unset("_cmake_import_check_files_for_${_cmake_target}")
87+
endforeach()
88+
unset(_cmake_target)
89+
unset(_cmake_import_check_targets)
90+
91+
# This file does not depend on other imported targets which have
92+
# been exported from the same project but in a separate export set.
93+
94+
# Commands beyond this point should not need to know the version.
95+
set(CMAKE_IMPORT_FILE_VERSION)
96+
cmake_policy(POP)

0 commit comments

Comments
 (0)