From cf83aba7c48b1e000e4cf9ef425eb7f1d5fab80d Mon Sep 17 00:00:00 2001 From: Stephanie Brink Date: Fri, 16 Feb 2024 15:40:39 -0800 Subject: [PATCH 1/2] move find dependencies to cmake directory --- src/c/CMakeLists.txt | 43 ++++++------------ src/c/cmake/CMakeBasics.cmake | 21 +++++++++ src/c/cmake/Setup3rdParty.cmake | 21 +++++++++ src/c/cmake/thirdparty/FindBison.cmake | 1 + src/c/cmake/thirdparty/FindCUDA.cmake | 5 +++ src/c/cmake/thirdparty/FindFlex.cmake | 1 + src/c/cmake/thirdparty/FindJansson.cmake | 55 ++++++++++++++++++++++++ src/c/cmake/thirdparty/FindLLVM.cmake | 1 + src/c/cmake/thirdparty/FindMPI.cmake | 5 +++ src/c/cmake/thirdparty/FindOpenSSL.cmake | 1 + src/c/cmake/thirdparty/FindThreads.cmake | 5 +++ src/c/parser/CMakeLists.txt | 3 -- src/c/runtime/CMakeLists.txt | 7 +-- src/c/test/CMakeLists.txt | 7 ++- src/c/weaver/CMakeLists.txt | 9 ++-- src/c/weaver/weave/CMakeLists.txt | 3 +- 16 files changed, 139 insertions(+), 49 deletions(-) create mode 100644 src/c/cmake/CMakeBasics.cmake create mode 100644 src/c/cmake/Setup3rdParty.cmake create mode 100644 src/c/cmake/thirdparty/FindBison.cmake create mode 100644 src/c/cmake/thirdparty/FindCUDA.cmake create mode 100644 src/c/cmake/thirdparty/FindFlex.cmake create mode 100644 src/c/cmake/thirdparty/FindJansson.cmake create mode 100644 src/c/cmake/thirdparty/FindLLVM.cmake create mode 100644 src/c/cmake/thirdparty/FindMPI.cmake create mode 100644 src/c/cmake/thirdparty/FindOpenSSL.cmake create mode 100644 src/c/cmake/thirdparty/FindThreads.cmake diff --git a/src/c/CMakeLists.txt b/src/c/CMakeLists.txt index 543a7e23..26baeeb7 100644 --- a/src/c/CMakeLists.txt +++ b/src/c/CMakeLists.txt @@ -2,12 +2,10 @@ cmake_minimum_required(VERSION 3.12) project(PerfFlowAspect VERSION "0.1.0") -# Fail if someone tries to config an in-source build. -if("${CMAKE_SOURCE_DIR}" STREQUAL "${CMAKE_BINARY_DIR}") - message(FATAL_ERROR "In-source builds are not supported. Please remove " - "CMakeCache.txt from the 'src' dir and configure an " - "out-of-source build in another directory.") -endif() +# Build Options +option(PERFFLOWASPECT_WITH_CUDA "Build CUDA smoketest" ON) +option(PERFFLOWASPECT_WITH_MPI "Build MPI smoketest" ON) +option(PERFFLOWASPECT_WITH_MULTITHREADS "Build multi-threaded smoketest" ON) # Fail if using Clang < 9.0 if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") @@ -24,30 +22,15 @@ else() message(WARNING "Unsupported CXX compiler: please use Clang >= 9.0") endif() -# Always use position independent code -set(CMAKE_POSITION_INDEPENDENT_CODE ON) - -# Set build type -set(default_build_type "Debug") - -if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES) - message(STATUS "Using default build type: \"${default_build_type}\"") - set(CMAKE_BUILD_TYPE "${default_build_type}" CACHE - STRING "Choose the type of build." FORCE) - # Set the possible values of build type for cmake-gui - set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release" "MinSizeRel" "RelWithDebInfo") -else() - message(STATUS "Setting build type to \"${CMAKE_BUILD_TYPE}\"") -endif() +include(cmake/CMakeBasics.cmake) +include(cmake/Setup3rdParty.cmake) include(GNUInstallDirs) set(CMAKE_SKIP_BUILD_RPATH FALSE) set(CMAKE_BUILD_WITH_INSTALL_RPATH FALSE) set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE) set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}") -message(STATUS "CMAKE_INSTALL_RPATH = ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}") - # the RPATH to be used when installing, but only if it's not a system directory list(FIND CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES @@ -56,7 +39,6 @@ if("${isSystemDir}" STREQUAL "-1") set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}") endif("${isSystemDir}" STREQUAL "-1") - add_subdirectory(parser) add_subdirectory(runtime) add_subdirectory(weaver) @@ -66,19 +48,20 @@ add_library(perfflowaspect INTERFACE) target_link_libraries(perfflowaspect INTERFACE perfflow_runtime perfflow_parser WeavePassPlugin) install(TARGETS perfflowaspect EXPORT perfflow_export - LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} - ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} - RUNTIME DESTINATION ${CMAKE_INSTALL_LIBDIR} + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} + RUNTIME DESTINATION ${CMAKE_INSTALL_LIBDIR} ) add_subdirectory(config) -message(STATUS "Config Dir: ${PERFFLOWASPECT_INSTALL_CONFIG_DIR}") - -if (NOT DEFINED PERFFLOWASPECT_INSTALL_CONFIG_DIR) +if(NOT DEFINED PERFFLOWASPECT_INSTALL_CONFIG_DIR) set(PERFFLOWASPECT_INSTALL_CONFIG_DIR "share") endif() +message(STATUS "CMAKE_INSTALL_RPATH = ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}") +message(STATUS "Config Dir: ${CMAKE_INSTALL_PREFIX}/${PERFFLOWASPECT_INSTALL_CONFIG_DIR}") + install(EXPORT perfflow_export FILE perfflowaspect_targets.cmake NAMESPACE perfflowaspect:: diff --git a/src/c/cmake/CMakeBasics.cmake b/src/c/cmake/CMakeBasics.cmake new file mode 100644 index 00000000..d1a0a5c0 --- /dev/null +++ b/src/c/cmake/CMakeBasics.cmake @@ -0,0 +1,21 @@ +# Fail if someone tries to config an in-source build. +if("${CMAKE_SOURCE_DIR}" STREQUAL "${CMAKE_BINARY_DIR}") + message(FATAL_ERROR "In-source builds are not supported. Please remove " + "CMakeCache.txt from the 'src' dir and configure an " + "out-of-source build in another directory.") +endif() + +# Always use position independent code +set(CMAKE_POSITION_INDEPENDENT_CODE ON) + +# Set build type +set(default_build_type "Debug") + +if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES) + message(STATUS "Using default build type: \"${default_build_type}\"") + set(CMAKE_BUILD_TYPE "${default_build_type}" CACHE STRING "Choose the type of build." FORCE) + # Set the possible values of build type for cmake-gui + set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release" "MinSizeRel" "RelWithDebInfo") +else() + message(STATUS "Setting build type to \"${CMAKE_BUILD_TYPE}\"") +endif() diff --git a/src/c/cmake/Setup3rdParty.cmake b/src/c/cmake/Setup3rdParty.cmake new file mode 100644 index 00000000..d7f203a6 --- /dev/null +++ b/src/c/cmake/Setup3rdParty.cmake @@ -0,0 +1,21 @@ +include(cmake/thirdparty/FindBison.cmake) + +if(PERFFLOWASPECT_WITH_CUDA) + include(cmake/thirdparty/FindCUDA.cmake) +endif() + +include(cmake/thirdparty/FindFlex.cmake) + +include(cmake/thirdparty/FindJansson.cmake) + +include(cmake/thirdparty/FindLLVM.cmake) + +if(PERFFLOWASPECT_WITH_MPI) + include(cmake/thirdparty/FindMPI.cmake) +endif() + +include(cmake/thirdparty/FindOpenSSL.cmake) + +if(PERFFLOWASPECT_WITH_MULTITHREADS) + include(cmake/thirdparty/FindThreads.cmake) +endif() diff --git a/src/c/cmake/thirdparty/FindBison.cmake b/src/c/cmake/thirdparty/FindBison.cmake new file mode 100644 index 00000000..853d7d7a --- /dev/null +++ b/src/c/cmake/thirdparty/FindBison.cmake @@ -0,0 +1 @@ +find_package(BISON REQUIRED) diff --git a/src/c/cmake/thirdparty/FindCUDA.cmake b/src/c/cmake/thirdparty/FindCUDA.cmake new file mode 100644 index 00000000..481ed6ea --- /dev/null +++ b/src/c/cmake/thirdparty/FindCUDA.cmake @@ -0,0 +1,5 @@ +find_package(CUDA) + +if(PERFFLOWASPECT_WITH_CUDA) + message(STATUS "Building CUDA smoketest (PERFFLOWASPECT_WITH_CUDA == ON)") +endif() diff --git a/src/c/cmake/thirdparty/FindFlex.cmake b/src/c/cmake/thirdparty/FindFlex.cmake new file mode 100644 index 00000000..f8a3d3fd --- /dev/null +++ b/src/c/cmake/thirdparty/FindFlex.cmake @@ -0,0 +1 @@ +find_package(FLEX REQUIRED) diff --git a/src/c/cmake/thirdparty/FindJansson.cmake b/src/c/cmake/thirdparty/FindJansson.cmake new file mode 100644 index 00000000..c411ec08 --- /dev/null +++ b/src/c/cmake/thirdparty/FindJansson.cmake @@ -0,0 +1,55 @@ +# First check for user-specified JANSSON_DIR +if(JANSSON_DIR) + message(STATUS "Looking for Jansson using JANSSON_DIR = ${JANSSON_DIR}") + + find_path(JANSSON_INCLUDE_DIRS + NAMES jansson.h + HINTS ${JANSSON_DIR}/include + ) + if(NOT JANSSON_INCLUDE_DIRS) + MESSAGE(FATAL_ERROR "Could not find jansson.h in ${JANSSON_DIR}/include") + endif() + + find_library(JANSSON_LIBRARY + NAMES libjansson.so + HINTS ${JANSSON_DIR}/lib + ) + if(NOT JANSSON_LIBRARY) + MESSAGE(FATAL_ERROR "Could not find libjansson.so in ${JANSSON_DIR}/lib") + endif() + + set(JANSSON_FOUND TRUE CACHE INTERNAL "") + set(JANSSON_DIR ${JANSSON_DIR} CACHE PATH "" FORCE) + include_directories(${JANSSON_INCLUDE_DIRS}) + + message(STATUS "FOUND jansson") + message(STATUS " [*] JANSSON_DIR = ${JANSSON_DIR}") + message(STATUS " [*] JANSSON_INCLUDE_DIRS = ${JANSSON_INCLUDE_DIRS}") + message(STATUS " [*] JANSSON_LIBRARY = ${JANSSON_LIBRARY}") +# If JANSSON_DIR not specified, then try to automatically find the JANSSON header +# and library +elseif(NOT JANSSON_FOUND) + find_path(JANSSON_INCLUDE_DIRS + NAMES jansson.h + ) + + find_library(JANSSON_LIBRARY + NAMES libjansson.so + ) + + if(JANSSON_INCLUDE_DIRS AND JANSSON_LIBRARY) + set(JANSSON_FOUND TRUE CACHE INTERNAL "") + set(JANSSON_INCLUDE_DIRS ${JANSSON_INCLUDE_DIRS} CACHE PATH "" FORCE) + set(JANSSON_LIBRARY ${JANSSON_LIBRARY} CACHE PATH "" FORCE) + include_directories(${JANSSON_INCLUDE_DIRS}) + + message(STATUS "FOUND jansson using find_library()") + message(STATUS " [*] JANSSON_INCLUDE_DIRS = ${JANSSON_INCLUDE_DIRS}") + message(STATUS " [*] JANSSON_LIBRARY = ${JANSSON_LIBRARY}") + endif() +endif() + +# Abort if all methods fail +if(NOT JANSSON_FOUND) + message(FATAL_ERROR "Jansson support needs explict JANSSON_DIR") +endif() diff --git a/src/c/cmake/thirdparty/FindLLVM.cmake b/src/c/cmake/thirdparty/FindLLVM.cmake new file mode 100644 index 00000000..71fe4953 --- /dev/null +++ b/src/c/cmake/thirdparty/FindLLVM.cmake @@ -0,0 +1 @@ +find_package(LLVM REQUIRED CONFIG) diff --git a/src/c/cmake/thirdparty/FindMPI.cmake b/src/c/cmake/thirdparty/FindMPI.cmake new file mode 100644 index 00000000..60510685 --- /dev/null +++ b/src/c/cmake/thirdparty/FindMPI.cmake @@ -0,0 +1,5 @@ +find_package(MPI REQUIRED) + +if(PERFFLOWASPECT_WITH_MPI) + message(STATUS "Building MPI smoketest (PERFFLOWASPECT_WITH_MPI == ON)") +endif() diff --git a/src/c/cmake/thirdparty/FindOpenSSL.cmake b/src/c/cmake/thirdparty/FindOpenSSL.cmake new file mode 100644 index 00000000..cc17ca81 --- /dev/null +++ b/src/c/cmake/thirdparty/FindOpenSSL.cmake @@ -0,0 +1 @@ +find_package(OpenSSL REQUIRED) diff --git a/src/c/cmake/thirdparty/FindThreads.cmake b/src/c/cmake/thirdparty/FindThreads.cmake new file mode 100644 index 00000000..7feb0160 --- /dev/null +++ b/src/c/cmake/thirdparty/FindThreads.cmake @@ -0,0 +1,5 @@ +find_package(Threads REQUIRED) + +if(PERFFLOWASPECT_WITH_MULTITHREADS) + message(STATUS "Building multi-threaded smoketest (PERFFLOWASPECT_WITH_MULTITHREADS == ON)") +endif() diff --git a/src/c/parser/CMakeLists.txt b/src/c/parser/CMakeLists.txt index 32d51d8a..2cbc769b 100644 --- a/src/c/parser/CMakeLists.txt +++ b/src/c/parser/CMakeLists.txt @@ -1,6 +1,3 @@ -find_package(BISON REQUIRED) -find_package(FLEX REQUIRED) - set(LEX_FLAGS "--nodefault") set(YACC_FLAGS "-t --report=none") diff --git a/src/c/runtime/CMakeLists.txt b/src/c/runtime/CMakeLists.txt index 2a8d842b..6e42303f 100644 --- a/src/c/runtime/CMakeLists.txt +++ b/src/c/runtime/CMakeLists.txt @@ -12,17 +12,12 @@ set(perfflow_runtime_sources perfflow_runtime.cpp ) -find_package(OpenSSL REQUIRED) - -set(perfflow_runtime_deps -ljansson -) - add_library(perfflow_runtime SHARED ${perfflow_runtime_sources} ${perfflow_runtime_headers} ) -target_link_libraries(perfflow_runtime ${perfflow_runtime_deps} OpenSSL::SSL OpenSSL::Crypto) +target_link_libraries(perfflow_runtime ${JANSSON_LIBRARY} OpenSSL::SSL OpenSSL::Crypto) install(TARGETS perfflow_runtime EXPORT perfflow_export diff --git a/src/c/test/CMakeLists.txt b/src/c/test/CMakeLists.txt index a93d532c..b11d0327 100644 --- a/src/c/test/CMakeLists.txt +++ b/src/c/test/CMakeLists.txt @@ -7,10 +7,9 @@ set(SMOKETESTS smoketest_MT ) -find_package(MPI REQUIRED) -find_package(Threads REQUIRED) -find_package(CUDA) -include_directories(${MPI_INCLUDE_PATH}) +if(MPI_FOUND) + include_directories(${MPI_INCLUDE_PATH}) +endif() set(perfflow_deps "-L../runtime -lperfflow_runtime -lcrypto") set(THREADS_PREFER_PTHREAD_FLAG ON) diff --git a/src/c/weaver/CMakeLists.txt b/src/c/weaver/CMakeLists.txt index f9ca5052..f04f215f 100644 --- a/src/c/weaver/CMakeLists.txt +++ b/src/c/weaver/CMakeLists.txt @@ -1,9 +1,10 @@ # support C++14 features used by LLVM 10.0.0 set(CMAKE_CXX_STANDARD 14) -find_package(LLVM REQUIRED CONFIG) -add_definitions(${LLVM_DEFINITIONS}) -include_directories(${LLVM_INCLUDE_DIRS}) -link_directories(${LLVM_LIBRARY_DIRS}) +if(LLVM_FOUND) + add_definitions(${LLVM_DEFINITIONS}) + include_directories(${LLVM_INCLUDE_DIRS}) + link_directories(${LLVM_LIBRARY_DIRS}) +endif() add_subdirectory(weave) diff --git a/src/c/weaver/weave/CMakeLists.txt b/src/c/weaver/weave/CMakeLists.txt index 2f74a117..1702a662 100644 --- a/src/c/weaver/weave/CMakeLists.txt +++ b/src/c/weaver/weave/CMakeLists.txt @@ -12,8 +12,7 @@ set_target_properties(WeavePass PROPERTIES COMPILE_FLAGS "-fno-rtti" ) -find_library(JANSSON_LIB jansson) -target_link_libraries(WeavePass perfflow_parser "${JANSSON_LIB}") +target_link_libraries(WeavePass perfflow_parser ${JANSSON_LIB}) add_library(WeavePassPlugin INTERFACE) target_compile_options(WeavePassPlugin INTERFACE From da65354c4498d40306d017748432e1584a3825c4 Mon Sep 17 00:00:00 2001 From: Stephanie Brink Date: Wed, 21 Feb 2024 22:34:02 -0800 Subject: [PATCH 2/2] fix crypto library to use defined target from SSL module --- src/c/test/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/c/test/CMakeLists.txt b/src/c/test/CMakeLists.txt index b11d0327..c5745aa3 100644 --- a/src/c/test/CMakeLists.txt +++ b/src/c/test/CMakeLists.txt @@ -11,7 +11,7 @@ if(MPI_FOUND) include_directories(${MPI_INCLUDE_PATH}) endif() -set(perfflow_deps "-L../runtime -lperfflow_runtime -lcrypto") +set(perfflow_deps "-L../runtime -lperfflow_runtime" OpenSSL::Crypto) set(THREADS_PREFER_PTHREAD_FLAG ON) message(STATUS "Adding CXX unit tests")