我有一个要编译的开源 C 库,但要设置编译器以识别 OpenMPI,必须将 C 宏设置PARALLEL
为 1,以便在头文件中:
#ifdef PARALLEL
#include <mpi.h>
#endif
将执行。下面是我正在处理的 CMAKE 文件,它将 src 目录添加为子目录,将头文件添加为 include_directory。
使用它PARELLEL
为 src 目录中的所有内容正确设置 C 宏。但是,包含目录中的所有内容都PARALLEL
未定义。
cmake_minimum_required(VERSION 3.14)
project(SDFC VERSION 14.4.2 LANGUAGES C)
option(PARALLEL "Using MPI" ON)
set(TOPLEVEL "${CMAKE_CURRENT_SOURCE_DIR}")
#file(GLOB SOURCE_ALL include/*inc CMakeLists.txt Makefile*)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fpic -g")
if(${CMAKE_C_COMPILER_ID} STREQUAL "GNU")
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -gdwarf-2")
endif()
set(SDFC_INCLUDE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/include" CACHE PATH
"Path to include files for SDF C library")
set(SDFC_LIB_DIR "${CMAKE_CURRENT_BINARY_DIR}/src" CACHE PATH
"Path to build directory for SDF C library")
include_directories(include)
add_subdirectory(src)
if(PARALLEL)
find_package(MPI REQUIRED)
include_directories(${MPI_C_INCLUDE_PATH})
add_compile_definitions(-DPARALLEL)
#add_compile_definitions(-DPARALLEL)
include(CMake/CheckMPIVersion.cmake)
endif()
install(DIRECTORY include DESTINATION . COMPONENT develop PATTERN uthash.h EXCLUDE)
install(FILES src/uthash/include/uthash.h DESTINATION include COMPONENT develop)
我用:
cmake .
make
任何帮助表示赞赏。