Skip to content
Snippets Groups Projects
Commit cc6787ab authored by Christoph Hasse's avatar Christoph Hasse :cartwheel_tone1:
Browse files

CMake refactoring to support monobuild

parent 4146842a
No related branches found
No related tags found
1 merge request!2699FunctorFactory, replace CLING backend with native compiler
......@@ -27,7 +27,7 @@
#]========================================================================]
function(thor_functor_cache cache_name)
set(CACHE_LIB_DIR ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR})
set(CACHE_LIB_DIR "${CMAKE_CURRENT_BINARY_DIR}/${cache_name}")
CMAKE_PARSE_ARGUMENTS(ARG "" "" "OPTIONS;DEPENDS" ${ARGN})
......@@ -42,9 +42,9 @@ function(thor_functor_cache cache_name)
add_custom_command(OUTPUT ${cache_name}.stamp
DEPENDS ${ARG_OPTIONS} ${ARG_DEPENDS}
# make sure that the intall directory already exists otherwise the
# compilation job will fail!
COMMAND mkdir -p ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}
# make sure that the directory already exists otherwise the compilation job
# will fail!
COMMAND mkdir -p ${CACHE_LIB_DIR}
# set FUNCTOR_JIT_EXTRA_ARGS to overwrite the default value of "-g0"
COMMAND ${CMAKE_BINARY_DIR}/run env FUNCTOR_JIT_EXTRA_ARGS="" FUNCTOR_JIT_LIBDIR=${CACHE_LIB_DIR} gaudirun.py ${ARG_OPTIONS}
# This file is only created as dependency proxy as we don't know the output
......@@ -52,5 +52,12 @@ function(thor_functor_cache cache_name)
COMMAND touch ${cache_name}.stamp
)
install(
DIRECTORY "${CACHE_LIB_DIR}/"
TYPE LIB
# we don't need to install the *.cpp files
PATTERN "*.cpp" EXCLUDE
PATTERN "*.so" PERMISSIONS OWNER_EXECUTE OWNER_WRITE OWNER_READ GROUP_EXECUTE GROUP_READ WORLD_EXECUTE WORLD_READ
)
add_custom_target(FUNCTOR_CACHE_${cache_name} ALL DEPENDS ${cache_name}.stamp)
endfunction()
......@@ -94,9 +94,26 @@ gaudi_add_tests(pytest ${CMAKE_CURRENT_SOURCE_DIR}/python)
string(TOUPPER ${CMAKE_BUILD_TYPE} CMAKE_BUILD_TYPE_UPPER)
set(preprocessed_header_name "preprocessed_functorfactory_header.ii")
set(preprocessed_header "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_INCLUDEDIR}/${preprocessed_header_name}")
lhcb_env(SET FUNCTORFACTORY_PREPROCESSED_HEADER ${preprocessed_header})
# When building the FunctorCache or when using a monobuild there is no install
# directory, thus we need to support running from the build directory and from
# the InstallArea. Executables like the below functor_jitter script and
# libraries are easy because the `CMAKE_CURRENT_BINARY_DIR` and the
# InstallArea are automatically in the `PATH` and `LD_LIBRARY_PATH` env
# variables. But to find the preprocessed header we need to play a small trick:
# The lhcb_env command sets an env variable for the build environment and the
# installed project, so that's what we do first and point to the InstallArea.
# Then we issue the command again but pass the PRIVATE flag which will only set
# the variable for the build directory thus overwriting the previously set env
# var for the build directory only.
lhcb_env(SET
FUNCTORFACTORY_PREPROCESSED_HEADER
"${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_INCLUDEDIR}/${preprocessed_header_name}"
)
lhcb_env(PRIVATE SET
FUNCTORFACTORY_PREPROCESSED_HEADER
"${CMAKE_CURRENT_BINARY_DIR}/${preprocessed_header_name}"
)
# # generate temporary file because I don't want to waste more time tyring to
# figure out how to freaking handle stupid whitespace in generator expressions
......@@ -111,17 +128,19 @@ ${CMAKE_CXX_FLAGS_${CMAKE_BUILD_TYPE_UPPER}} \
-I$<JOIN:$<FILTER:$<REMOVE_DUPLICATES:$<TARGET_PROPERTY:FunctorCoreLib,INCLUDE_DIRECTORIES>>,INCLUDE,/Rec/>, -I> \
-isystem $<JOIN:$<FILTER:$<FILTER:$<REMOVE_DUPLICATES:$<TARGET_PROPERTY:FunctorCoreLib,INCLUDE_DIRECTORIES>>,EXCLUDE,/usr/include>,EXCLUDE,/Rec/>, -isystem > \
-E ${CMAKE_CURRENT_SOURCE_DIR}/include/Functors/JIT_includes.h \
-o ${preprocessed_header}"
-o ${preprocessed_header_name}"
)
# generate the preprocessed header which depends on JIT_INCLUDE_TEST
add_custom_command(OUTPUT ${preprocessed_header}
add_custom_command(OUTPUT ${preprocessed_header_name}
COMMAND sh tmp_preprocessor.sh
DEPENDS ${generated_header_name} "tmp_preprocessor.sh"
JIT_INCLUDES_TEST
)
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/${preprocessed_header_name}" TYPE INCLUDE)
# avoid "warning: style of line directive is a GCC extension" because we
# include a preprocessed header. Are there better solutions? We could first
# precompile the preprocessed header in initalize() and then use that pch...
......@@ -133,14 +152,14 @@ string(REPLACE " \"$@\"" "" CMAKE_CXX_COMPILER_CONTENT ${CMAKE_CXX_COMPILER_CONT
string(STRIP ${CMAKE_CXX_COMPILER_CONTENT} CMAKE_CXX_COMPILER_CONTENT)
file(GENERATE
OUTPUT "functor_jitter"
OUTPUT "functor_jitter_tmp"
CONTENT "#!/usr/bin/env python
# Auto-generated script to create a jitter for the FunctorFactory
import os
import subprocess as sp
import sys
base_dir = os.path.join(os.path.dirname(os.path.dirname(os.path.realpath(__file__))))
header = os.environ['FUNCTORFACTORY_PREPROCESSED_HEADER']
# we know all our libs will be on the LD_LIBRARY_PATH so just point the linker there
my_env = os.environ.copy()
......@@ -162,19 +181,24 @@ cmd = cmd + ' -std=c++${GAUDI_CXX_STANDARD} \
-D$<JOIN:$<REMOVE_DUPLICATES:$<TARGET_PROPERTY:FunctorCoreLib,COMPILE_DEFINITIONS>>, -D> \
${no_pedantic} \
${CMAKE_CXX_FLAGS_${CMAKE_BUILD_TYPE_UPPER}} -fPIC -shared \
{3} -include {0}/include/${preprocessed_header_name} \
{3} -include {0} \
-lFunctorCore -lParticleCombiners -lTrackEvent -lPhysEvent -lMCEvent -lRecEvent -lHltEvent \
-o {1} {2}'.format(base_dir, sys.argv[2], sys.argv[1], extra_args)
-o {1} {2}'.format(header, sys.argv[2], sys.argv[1], extra_args)
exit(sp.call(cmd, shell=True, env=my_env))
")
set(JIT_CMD_FILE "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_BINDIR}/functor_jitter")
add_custom_command(OUTPUT ${JIT_CMD_FILE} DEPENDS "functor_jitter"
COMMAND cp "functor_jitter" ${JIT_CMD_FILE}
COMMAND chmod +x ${JIT_CMD_FILE}
# we don't yet have cmake 3.20 so file(GENERATE) doesn't accept permissions yet
# thus we add a proxy command that copies the generated file and makes it
# executable
add_custom_command(OUTPUT "functor_jitter" DEPENDS "functor_jitter_tmp"
COMMAND cp "functor_jitter_tmp" "functor_jitter"
COMMAND chmod a+x "functor_jitter"
)
add_custom_target(FunctorCoreJit ALL DEPENDS ${preprocessed_header} ${JIT_CMD_FILE})
install(PROGRAMS "${CMAKE_CURRENT_BINARY_DIR}/functor_jitter" TYPE BIN)
add_custom_target(FunctorCoreJit ALL DEPENDS ${preprocessed_header_name} "functor_jitter")
# this is only here to handle dependencies of a FunctorCache outside Rec e.g. in Moore
add_dependencies(FunctorCore FunctorCoreJit)
......@@ -170,8 +170,7 @@ struct FunctorFactory : public extends<Service, Functors::IFactory> {
{
std::ofstream out{cpp_filename};
if ( !out.is_open() ) {
throw GaudiException{ "Failed to open file " + cpp_filename, "FunctorFactory",
StatusCode::FAILURE };
throw GaudiException{"Failed to open file " + cpp_filename, "FunctorFactory", StatusCode::FAILURE};
}
out << full_lib_code;
out.close();
......
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