Skip to content

Commit

Permalink
Fix building against libc++ (#12)
Browse files Browse the repository at this point in the history
When building for libc++, the C++ runtime is still necessary for std::mutex.
By default explicitly build against libstdc++ to avoid the dependency with
an option to explicitly choose libc++.
  • Loading branch information
jprotze authored Oct 1, 2024
1 parent 9c7f09a commit fac6e26
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 10 deletions.
28 changes: 22 additions & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -74,25 +74,41 @@ set(OTFCPT_OMP_SOURCES
)


set(STDCPLUS_COMPILE_FLAGS -fno-rtti -fno-exceptions -ffunction-sections -fdata-sections)
set(STDCPLUS_LINK_FLAGS -fno-rtti -fno-exceptions -fno-rtti -fno-exceptions -nostdlib++ -Wl,--gc-sections)

if (CMAKE_C_COMPILER_ID STREQUAL "Clang")
option(OTFCPT_USE_LLVM_LIBCPP "Use LLVM libc++, which might reduce portability." OFF)
if(OTFCPT_USE_LLVM_LIBCPP)
message(STATUS "Building with LLVM libc++ was requested, which might limit portability and compatibility with application/library code compiled with gcc.")
set(STDCPLUS_COMPILE_FLAGS -stdlib=libc++)
set(STDCPLUS_LINK_FLAGS -stdlib=libc++)
else()
message(STATUS "For portability, OTF-CPT is built without dependency to a C++ runtime library")
set(STDCPLUS_COMPILE_FLAGS ${STDCPLUS_COMPILE_FLAGS} -stdlib=libstdc++)
set(STDCPLUS_LINK_FLAGS ${STDCPLUS_LINK_FLAGS} -stdlib=libstdc++)
endif()
endif ()

set(WRAP_FLAGS -s -n)
add_wrapped_file(gen-nb-wrappers.cpp gen-nb-wrappers.w)
add_wrapped_file(gen-wrappers.cpp gen-wrappers.w)

add_library(OTFCPT SHARED ${OTFCPT_SOURCES})
target_link_libraries(OTFCPT ${MPI_C_LIBRARIES})
target_compile_definitions(OTFCPT PUBLIC -DUSE_MPI=1)
target_link_options(OTFCPT PUBLIC -fno-rtti -fno-exceptions -nostdlib++ -Wl,--gc-sections)
target_compile_options(OTFCPT PUBLIC -fno-rtti -fno-exceptions -ffunction-sections -fdata-sections)
target_link_options(OTFCPT PUBLIC ${STDCPLUS_LINK_FLAGS})
target_compile_options(OTFCPT PUBLIC ${STDCPLUS_COMPILE_FLAGS})

add_library(OTFCPT_omp SHARED ${OTFCPT_OMP_SOURCES})
target_link_options(OTFCPT_omp PUBLIC -fno-rtti -fno-exceptions -nostdlib++ -Wl,--gc-sections)
target_compile_options(OTFCPT_omp PUBLIC -fno-rtti -fno-exceptions -ffunction-sections -fdata-sections)
target_link_options(OTFCPT_omp PUBLIC ${STDCPLUS_LINK_FLAGS})
target_compile_options(OTFCPT_omp PUBLIC ${STDCPLUS_COMPILE_FLAGS})

add_library(OTFCPT_static STATIC ${OTFCPT_SOURCES})
target_link_libraries(OTFCPT_static ${MPI_C_LIBRARIES})
target_compile_definitions(OTFCPT_static PUBLIC -DUSE_MPI=1)
target_link_options(OTFCPT_static PUBLIC -fno-rtti -fno-exceptions -nostdlib++ -Wl,--gc-sections)
target_compile_options(OTFCPT_static PUBLIC -fno-rtti -fno-exceptions -ffunction-sections -fdata-sections)
target_link_options(OTFCPT_static PUBLIC ${STDCPLUS_LINK_FLAGS})
target_compile_options(OTFCPT_static PUBLIC ${STDCPLUS_COMPILE_FLAGS})

if (EXISTS ${CMAKE_CURRENT_LIST_DIR}/external/FileCheck/CMakeLists.txt)
add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/external/FileCheck EXCLUDE_FROM_ALL)
Expand Down
18 changes: 14 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

Tool to collect and report model factors (aka. fundamental performance factors) for hybrid MPI + OpenMP applications on-the-fly.

## Build with CMake
## Building with CMake
The C/C++ compiler needs to support OMPT (which is provided by icc/clang and others, but not gcc)
### Basic Cmake
```
Expand All @@ -13,7 +13,7 @@ cmake ../
make -j8
```

### Cmake with Clang
### Building with Clang
To use clang with IntelMPI/OpenMPI/MPICH, export the following env variables first:
```
export MPICH_CC=clang; export MPICH_CXX=clang++;
Expand All @@ -24,7 +24,17 @@ cmake ../
make -j8
```

### Cmake with MPICH + Clang on Ubuntu
### Using libc++ with Clang-based compilers
For broad compatibility with applications and libraries built with mixed
compiler setups (e.g. gfortran + clang++), OTF-CPT tries to avoid dependency
to a C++ runtime library. If GNU C++ headers are available, they are
preferred for building OTF-CPT (which is also the default).

If no GNU C++ headers are available, OTF-CPT can be built by explicitly using
LLVM's C++ runtime library (libc++) by configuring OTF-CPT with the cmake
flag `-DOTFCPT_USE_LLVM_LIBCPP=ON`.

### Building with MPICH + Clang on Ubuntu
The MPICH compiler wrapper on Ubuntu bricks MPI detection in cmake, work-around as following:
```
export MPICH_CC=clang; export MPICH_CXX=clang++;
Expand All @@ -34,7 +44,7 @@ CC=mpicc.mpich CXX=mpicxx.mpich LDFLAGS=-flto=auto cmake ../
make -j8
```

### Cmake with OpenMPI + Clang on Ubuntu
### Building with OpenMPI + Clang on Ubuntu
```
export OMPI_CC=clang; export OMPI_CXX=clang++;
mkdir BUILD
Expand Down

0 comments on commit fac6e26

Please sign in to comment.