Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor cmake build system #134

Merged
merged 2 commits into from
Mar 6, 2024
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
43 changes: 13 additions & 30 deletions src/c/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe a single build option for all tests, tests will build only if it exists (e.g. CUDA for example)


# Fail if using Clang < 9.0
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
Expand All @@ -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}")
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Revisit setting rpath

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
Expand All @@ -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)
Expand All @@ -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::
Expand Down
21 changes: 21 additions & 0 deletions src/c/cmake/CMakeBasics.cmake
Original file line number Diff line number Diff line change
@@ -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()
21 changes: 21 additions & 0 deletions src/c/cmake/Setup3rdParty.cmake
Original file line number Diff line number Diff line change
@@ -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()
1 change: 1 addition & 0 deletions src/c/cmake/thirdparty/FindBison.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
find_package(BISON REQUIRED)
5 changes: 5 additions & 0 deletions src/c/cmake/thirdparty/FindCUDA.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
find_package(CUDA)

if(PERFFLOWASPECT_WITH_CUDA)
message(STATUS "Building CUDA smoketest (PERFFLOWASPECT_WITH_CUDA == ON)")
endif()
1 change: 1 addition & 0 deletions src/c/cmake/thirdparty/FindFlex.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
find_package(FLEX REQUIRED)
55 changes: 55 additions & 0 deletions src/c/cmake/thirdparty/FindJansson.cmake
Original file line number Diff line number Diff line change
@@ -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()
1 change: 1 addition & 0 deletions src/c/cmake/thirdparty/FindLLVM.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
find_package(LLVM REQUIRED CONFIG)
5 changes: 5 additions & 0 deletions src/c/cmake/thirdparty/FindMPI.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
find_package(MPI REQUIRED)

if(PERFFLOWASPECT_WITH_MPI)
message(STATUS "Building MPI smoketest (PERFFLOWASPECT_WITH_MPI == ON)")
endif()
1 change: 1 addition & 0 deletions src/c/cmake/thirdparty/FindOpenSSL.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
find_package(OpenSSL REQUIRED)
5 changes: 5 additions & 0 deletions src/c/cmake/thirdparty/FindThreads.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
find_package(Threads REQUIRED)

if(PERFFLOWASPECT_WITH_MULTITHREADS)
message(STATUS "Building multi-threaded smoketest (PERFFLOWASPECT_WITH_MULTITHREADS == ON)")
endif()
3 changes: 0 additions & 3 deletions src/c/parser/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
find_package(BISON REQUIRED)
find_package(FLEX REQUIRED)

set(LEX_FLAGS "--nodefault")

set(YACC_FLAGS "-t --report=none")
Expand Down
7 changes: 1 addition & 6 deletions src/c/runtime/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
slabasan marked this conversation as resolved.
Show resolved Hide resolved

install(TARGETS perfflow_runtime
EXPORT perfflow_export
Expand Down
9 changes: 4 additions & 5 deletions src/c/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,11 @@ 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(perfflow_deps "-L../runtime -lperfflow_runtime" OpenSSL::Crypto)
set(THREADS_PREFER_PTHREAD_FLAG ON)

message(STATUS "Adding CXX unit tests")
Expand Down
9 changes: 5 additions & 4 deletions src/c/weaver/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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)
3 changes: 1 addition & 2 deletions src/c/weaver/weave/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading