[PATCH] Initial cmake support

The attached patch adds the file, runtime/src/CMakelists.txt, which is modeled on the approach taken in the pathscale/openmprtl cmake support. This initial cmake support was designed with the goal of producing as identical of a build as possible to that obtained via build.pl using…

make compiler=clang

on both darwin and linux. The main limitation of the current implementation is that, due to the absence of integrated exported symbol list support in cmake, the cmake build doesn’t limit the exported symbols as does the build.pl method. This theoretically can be added but we will have to replicate the exact steps used by build.pl via an complex set of add_custom_command’s. The current cmake support is used by…

% cd openmp/runtime/src
% mkdir build
% cd build
% cmake …
% make VERBOSE=1

The build leaves the libiomp5.[so/dylib] shared library and omp.h header in the build directory. TODO items also include adding support for ‘make install’ to the cmake support. I chose to place the entire CMakefile.txt within a single file, unlike the pathscale ones, to keep it unified for readability and ease of coding further changes.
This has been tested on x86_64-apple-darwin12/13 against the clang from Xcode 5.1.1. and on x86_64 Fedora 15 against the current clang-omp 3.4. I plan on testing additional changes to allow powerpc cmake builds of openmp as well. Our fink llvm34-3.4.1-0f packaging with current clang-omp merged should allow this to be tested on ppc darwin9.
Jack

initial_cmake_support.patch (5.51 KB)

Thanks Jack, this is looking great..

It'll need a documentation update to make it clear that the CMake build system is as yet unsupported and not to be used for production builds.

Otherwise, there are just a few minor nits below to be addressed, review comments inline...

The attached patch adds the file, runtime/src/CMakelists.txt, which is modeled on the approach taken in the pathscale/openmprtl cmake support. This initial cmake support was designed with the goal of producing as identical of a build as possible to that obtained via build.pl <http://build.pl> using…

make compiler=clang

on both darwin and linux. The main limitation of the current implementation is that, due to the absence of integrated exported symbol list support in cmake, the cmake build doesn't limit the exported symbols as does the build.pl <http://build.pl> method. This theoretically can be added but we will have to replicate the exact steps used by build.pl <http://build.pl> via an complex set of add_custom_command's. The current cmake support is used by…

% cd openmp/runtime/src
% mkdir build
% cd build
% cmake ..
% make VERBOSE=1

The build leaves the libiomp5.[so/dylib] shared library and omp.h header in the build directory. TODO items also include adding support for 'make install' to the cmake support. I chose to place the entire CMakefile.txt within a single file, unlike the pathscale ones, to keep it unified for readability and ease of coding further changes.

We should add a top-level CMake file that includes this one, same as the other LLVM projects.

I'd prefer to do that from the get-go instead of changing the build procedure in a follow-up commit. Should only be a couple of lines and an include.

This has been tested on x86_64-apple-darwin12/13 against the clang from Xcode 5.1.1. and on x86_64 Fedora 15 against the current clang-omp 3.4. I plan on testing additional changes to allow powerpc cmake builds of openmp as well. Our fink llvm34-3.4.1-0f packaging with current clang-omp merged should allow this to be tested on ppc darwin9.
Jack

Index: runtime/src/CMakeLists.txt

--- runtime/src/CMakeLists.txt (revision 0)
+++ runtime/src/CMakeLists.txt (working copy)
@@ -0,0 +1,146 @@
+project(openmp)
+cmake_minimum_required(VERSION 2.8)
+
+set(VERSION 5)
+set(OMP_VERSION "201107")
+set(OMP_VERSION_NUM "40")
+
+execute_process(COMMAND "date" "+%Y-%m-%d %H:%M:%S" OUTPUT_VARIABLE BUILD_TIME)
+string(REGEX REPLACE "\n" "" BUILD_TIME ${BUILD_TIME})
+
+include_directories(
+ .
+ include
+ include/${OMP_VERSION}
+ i18n
+ thirdparty/ittnotify
+ ${CMAKE_CURRENT_BINARY_DIR}
+ )

Please use two leading spaces for per indentation level everywhere to match LLVM CMake style. In your patch there's a mix of 1, 2 and 8+ spaces in various places.

+
+if(WIN32)
+ set(OS_GEN "win")
+elseif(UNIX)
+ set(OS_GEN "lin")
+elseif(APPLE)
+ set(OS_GEN "mac")

Place the APPLE check above UNIX.

+endif()

It's worth handling the else() condition above with an error. Should be simple enough going by examples in LLVM's CMake.

+
+if("${ARCH}" STREQUAL "")
+ set(ARCH "32e")
+endif()
+
+set(ARCH_STR "Intel(R) 64")
+
+set(FEATURE_FLAGS "-D USE_ITT_BUILD")
+set(FEATURE_FLAGS "${FEATURE_FLAGS} -D NDEBUG")
+set(FEATURE_FLAGS "${FEATURE_FLAGS} -D KMP_ARCH_STR=\"\\\"${ARCH_STR}\\\"\"")
+set(FEATURE_FLAGS "${FEATURE_FLAGS} -D _GNU_SOURCE")
+set(FEATURE_FLAGS "${FEATURE_FLAGS} -D _REENTRANT")
+set(FEATURE_FLAGS "${FEATURE_FLAGS} -D KMP_USE_ASSERT")
+set(FEATURE_FLAGS "${FEATURE_FLAGS} -D BUILD_I8")
+set(FEATURE_FLAGS "${FEATURE_FLAGS} -D BUILD_TV")
+if(APPLE)
+ set(FEATURE_FLAGS "${FEATURE_FLAGS} -D KMP_LIBRARY_FILE=\\\"libiomp5.dylib\\\"")

We'll eventually want to use the CMake variables to detect the dylib/so/dll etc. extension, but for now I'm fine to go with what you have.

+ set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -current_version 5.0")
+ set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -compatibility_version 5.0")
+else()
+ set(FEATURE_FLAGS "${FEATURE_FLAGS} -D KMP_LIBRARY_FILE=\\\"libiomp5.so\\\"")
+endif()
+set(FEATURE_FLAGS "${FEATURE_FLAGS} -D KMP_VERSION_MAJOR=${VERSION}")
+set(FEATURE_FLAGS "${FEATURE_FLAGS} -D CACHE_LINE=64")
+set(FEATURE_FLAGS "${FEATURE_FLAGS} -D KMP_ADJUST_BLOCKTIME=1")
+set(FEATURE_FLAGS "${FEATURE_FLAGS} -D BUILD_PARALLEL_ORDERED")
+set(FEATURE_FLAGS "${FEATURE_FLAGS} -D KMP_ASM_INTRINS")
+set(FEATURE_FLAGS "${FEATURE_FLAGS} -D USE_LOAD_BALANCE")
+set(FEATURE_FLAGS "${FEATURE_FLAGS} -D USE_CBLKDATA")
+set(FEATURE_FLAGS "${FEATURE_FLAGS} -D GUIDEDLL_EXPORTS")
+set(FEATURE_FLAGS "${FEATURE_FLAGS} -D KMP_GOMP_COMPAT")
+set(FEATURE_FLAGS "${FEATURE_FLAGS} -D KMP_USE_ADAPTIVE_LOCKS=1")
+set(FEATURE_FLAGS "${FEATURE_FLAGS} -D KMP_DEBUG_ADAPTIVE_LOCKS=0")
+set(FEATURE_FLAGS "${FEATURE_FLAGS} -D OMP_50_ENABLED=0")
+set(FEATURE_FLAGS "${FEATURE_FLAGS} -D OMP_41_ENABLED=0")
+set(FEATURE_FLAGS "${FEATURE_FLAGS} -D OMP_40_ENABLED=1")
+set(FEATURE_FLAGS "${FEATURE_FLAGS} -D OMP_30_ENABLED=1")
+set(FEATURE_FLAGS "${FEATURE_FLAGS} -D USE_ITT_NOTIFY=1")
+set(FEATURE_FLAGS "${FEATURE_FLAGS} -D INTEL_ITTNOTIFY_PREFIX=__kmp_itt_")
+if (NOT APPLE)
+ set(FEATURE_FLAGS "${FEATURE_FLAGS} -D KMP_TDATA_GTID")
+endif()
+set(FEATURE_FLAGS "${FEATURE_FLAGS} -D _KMP_BUILD_TIME=\"\\\"${BUILD_TIME} UTC\\\"\"")
+
+set(COMMON_FLAGS "-fPIC")
+set(COMMON_FLAGS "${COMMON_FLAGS} -Wno-unused-value")
+set(COMMON_FLAGS "${COMMON_FLAGS} -Wno-switch")
+set(COMMON_FLAGS "${COMMON_FLAGS} -Wno-deprecated-register")
+set(COMMON_FLAGS "${COMMON_FLAGS} -fno-exceptions")
+
+set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${FEATURE_FLAGS} ${COMMON_FLAGS}")
+set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${FEATURE_FLAGS} ${COMMON_FLAGS}")
+
+set(ASM_SOURCES
+ z_Linux_asm.s
+)
+set(SOURCES
+ thirdparty/ittnotify/ittnotify_static.c
+ kmp_affinity.cpp
+ kmp_alloc.c
+ kmp_atomic.c
+ kmp_cancel.cpp
+ kmp_csupport.c
+ kmp_debug.c
+ kmp_dispatch.cpp
+ kmp_environment.c
+ kmp_error.c
+ kmp_ftn_cdecl.c
+ kmp_ftn_extra.c
+ kmp_global.c
+ kmp_gsupport.c
+ kmp_global.c
+ kmp_i18n.c
+ kmp_io.c
+ kmp_itt.c
+ kmp_lock.cpp
+ kmp_runtime.c
+ kmp_sched.cpp
+ kmp_settings.c
+ kmp_str.c
+ kmp_taskdeps.cpp
+ kmp_tasking.c
+ kmp_taskq.c
+ kmp_threadprivate.c
+ kmp_utility.c
+ kmp_version.c
+ z_Linux_util.c
+)
+
+set_source_files_properties(${SOURCES} PROPERTIES LANGUAGE CXX)
+set_source_files_properties(${ASM_SOURCES} PROPERTIES LANGUAGE CXX)
+
+set(CMAKE_CXX_COMPILER "clang++")

This is kind of weird. Doesn't it work without setting CMAKE_CXX_COMPILER?

Alp.