Giter Site home page Giter Site logo

cmake-xcode-openmp's Introduction

CMakeLists Generating Xcode Project with OpenMP Support

This repository contains a CMakeLists.txt that can generate Xcode projects where the open source LLVM compiler (instead of the default Clang on Mac OS) is used for compilation, with OpenMP support. It generally follows this post by Menshov for integration, where the sample code included is also borrowed from his post.

Usage

  1. Install the open source LLVM compiler with Homebrew, with brew install llvm command in a terminal.
  2. Download and install CMake GUI.
  3. Download and install libomp.
  4. Open CMake GUI, point the source code to the folder containing this CMakeLists.txt, and use a subdirectory (say, "build", for example) to build the binaries.
  5. Configure using Xcode generator. The CMakeLists.txt will use /usr/local/opt/llvm as the default root directory for the compiler. If Homebrew has installed the compiler into somewhere else, this root directory should be changed correspondingly.
  6. Generate and open the Xcode project under the subdirectory to build the binaries.

Screenshots

Select Xcode as the generator. Select Xcode as the generator

CMake GUI after configured CMake GUI after configured

OpenMP can be used with the open source LLVM compiler under Xcode 10 and MacOS 10.14 OpenMP can be used with the open source LLVM compiler under Xcode 10 and MacOS 10.14

Details

There are two parts in the CMakeLists.txt that are necessary. The first part would find the compiler, include the directory containing OpenMP header and link with the OpenMP library, as following

set (LLVM_ROOT_DIR "/usr/local/opt/llvm")
find_package( LLVM )
if( LLVM_FOUND )
	include_directories (${LLVM_LIBRARY_DIRS}/clang/${LLVM_VERSION_BASE_STRING}/include)
	set ( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fopenmp" )
	find_library(IOMP5LIB
		NAMES "iomp5" "iomp5md" "libiomp5" "libiomp5md" "libomp"
		HINTS ${LLVM_LIBRARY_DIRS})
	set (TESTOMP_LIBRARIES ${TESTOMP_LIBRARIES} ${IOMP5LIB})
endif( LLVM_FOUND )

where the LLVM_ROOT_DIR is the directory at which the open source LLVM compiler is located, provided by the user.

The second part would override the Xcode setting for compilers to use, and turn off the index-while-building feature (introduced since Xcode 9) that is incompatible with the open source LLVM compiler, as following

set_target_properties(<your target name> PROPERTIES XCODE_ATTRIBUTE_CC ${LLVM_ROOT_DIR}/bin/clang)
set_target_properties(<your target name> PROPERTIES XCODE_ATTRIBUTE_CXX ${LLVM_ROOT_DIR}/bin/clang)
set_target_properties(<your target name> PROPERTIES XCODE_ATTRIBUTE_COMPILER_INDEX_STORE_ENABLE "No")

cmake-xcode-openmp's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

cmake-xcode-openmp's Issues

Generation Error

Hi there,
I encountered a generation error when following the steps.
CMake Error: The following variables are used in this project, but they are set to NOTFOUND. Please set them or make sure they are set and tested correctly in the CMake files: IOMP5LIB linked by target "TestOMP" in directory /Users/Song/Developer/cmake-xcode-openmp
Configuration can be done correct. I think I have followed the steps correctly.
Really appreciate if you can solve the error.

Thanks in advance

Screen Shot 2022-02-22 at 19 05 34

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.