diff options
author | Jonathan Peyton <jonathan.l.peyton@intel.com> | 2015-07-15 16:05:30 +0000 |
---|---|---|
committer | Jonathan Peyton <jonathan.l.peyton@intel.com> | 2015-07-15 16:05:30 +0000 |
commit | 2e0133526e85e53ff67a25511b9789d2e10f17d2 (patch) | |
tree | 773e372c749314de37743dd3fc45b62f133d2f9a /openmp/runtime/src | |
parent | 8da737a18a7b543e0c5b54e3e609d1a5eda8dddc (diff) | |
download | bcm5719-llvm-2e0133526e85e53ff67a25511b9789d2e10f17d2.tar.gz bcm5719-llvm-2e0133526e85e53ff67a25511b9789d2e10f17d2.zip |
Large Refactor of CMake build system
This commit improves numerous functionalities of the OpenMP CMake build
system to be more conducive with LLVM's build system and build philosophies.
The CMake build system, as it was before this commit, was not up to LLVM's
standards and did not implement the configuration stage like most CMake based
build systems offer (check for compiler flags, libraries, etc.) In order to
improve it dramatically in a short period of time, a large refactoring had
to be done.
The main changes done with this commit are as follows:
* Compiler flag checks - The flags are no longer grabbed from compiler specific
directories. They are checked for availability in config-ix.cmake and added
accordingly inside LibompHandleFlags.cmake.
* Feature checks were added in config-ix.cmake. For example, the standard CMake
module FindThreads is probed for the threading model to use inside the OpenMP
library.
* OS detection - There is no longer a LIBOMP_OS variable, OS-specifc build logic
is wrapped around the WIN32 and APPLE macros with !(WIN32 OR APPLE) meaning
a Unix flavor of some sort.
* Got rid of vestigial functions/macros/variables
* Added new libomp_append() function which is used everywhere to conditionally
or undconditionally append to a list
* All targets have the libomp prefix so as not to interfere with any other
project
* LibompCheckLinkerFlag.cmake module was added which checks for linker flags
specifically for building shared libraries.
* LibompCheckFortranFlag.cmake module was added which checks for fortran flag
availability.
* Removed most of the cruft from the translation between the perl+Makefile based
build system and this one. The remaining components that they share are
perl scripts which I'm in the process of removing.
There is still more left to do. The perl scripts still need to be removed, and
a config.h.in file (or similarly named) needs to be added with #cmakedefine lines
in it. But this is a much better first step than the previous system.
Differential Revision: http://reviews.llvm.org/D10656
llvm-svn: 242298
Diffstat (limited to 'openmp/runtime/src')
-rw-r--r-- | openmp/runtime/src/CMakeLists.txt | 506 |
1 files changed, 241 insertions, 265 deletions
diff --git a/openmp/runtime/src/CMakeLists.txt b/openmp/runtime/src/CMakeLists.txt index 81d69925181..26af3510dcb 100644 --- a/openmp/runtime/src/CMakeLists.txt +++ b/openmp/runtime/src/CMakeLists.txt @@ -9,294 +9,263 @@ #//===----------------------------------------------------------------------===// # -#################### -# --- Create all --- -add_custom_target(libomp-lib ALL DEPENDS omp) -if(${LIBOMP_FORTRAN_MODULES}) - add_custom_target(libomp-mod ALL DEPENDS ${export_mod_files}) -endif() - -############################# -# --- Create Common Files --- -add_custom_target(libomp-common ALL DEPENDS ${export_cmn_files}) -add_custom_target(libomp-clean-common COMMAND ${CMAKE_COMMAND} -E remove -f ${export_cmn_files}) - -# --- Put headers in convenient locations post build --- -if(${LIBOMP_COPY_EXPORTS}) - add_custom_command(TARGET common POST_BUILD - COMMAND ${CMAKE_COMMAND} -E make_directory ${export_cmn_dir} - COMMAND ${CMAKE_COMMAND} -E copy omp.h ${export_cmn_dir} - COMMAND ${CMAKE_COMMAND} -E copy omp_lib.h ${export_cmn_dir} - COMMAND ${CMAKE_COMMAND} -E copy omp_lib.f ${export_cmn_dir} - COMMAND ${CMAKE_COMMAND} -E copy omp_lib.f90 ${export_cmn_dir} - ) - if(${LIBOMP_OMPT_SUPPORT}) - add_custom_command(TARGET common POST_BUILD - COMMAND ${CMAKE_COMMAND} -E copy ompt.h ${export_cmn_dir} - ) +# Using expand-vars.pl to generate files +# - 'file' is generated using expand-vars.pl and 'file'.var +# - Any .var file should use this recipe +# TODO: Use CMake's configure_file() instead +macro(libomp_expand_vars_recipe file_dir filename) + get_source_file_property(libomp_extra_evflags ${filename} EV_COMPILE_DEFINITIONS) + if("${libomp_extra_evflags}" MATCHES "NOTFOUND") + set(libomp_extra_evflags) + else() + libomp_string_to_list("${libomp_extra_evflags}" libomp_extra_evflags) endif() - if(${LIBOMP_FORTRAN_MODULES}) - add_custom_command(TARGET mod POST_BUILD - COMMAND ${CMAKE_COMMAND} -E make_directory ${export_mod_dir} - COMMAND ${CMAKE_COMMAND} -E copy omp_lib.mod ${export_mod_dir} - COMMAND ${CMAKE_COMMAND} -E copy omp_lib_kinds.mod ${export_mod_dir} + if(NOT "${filename}" STREQUAL "") + add_custom_command( + OUTPUT ${filename} + COMMAND ${PERL_EXECUTABLE} ${LIBOMP_TOOLS_DIR}/expand-vars.pl + --strict ${LIBOMP_EVFLAGS} ${libomp_extra_evflags} ${file_dir}/${filename}.var ${filename} + DEPENDS ${file_dir}/${filename}.var kmp_version.c ${LIBOMP_TOOLS_DIR}/expand-vars.pl ) endif() -endif() - -###################################################### -# --- Build the main library --- -# $(lib_file) <== Main library file to create - -# preprocessor flags (-D definitions and -I includes) -# Grab environment variable CPPFLAGS and append those to definitions -set(include_dirs ${CMAKE_CURRENT_BINARY_DIR} ${src_dir} ${src_dir}/i18n ${inc_dir} ${src_dir}/thirdparty/ittnotify) -include_directories(${include_dirs}) - -# objects depend on : .inc files and omp.h -# This way the *.inc and omp.h are generated before any compilations take place -add_custom_target(libomp-needed-headers DEPENDS kmp_i18n_id.inc kmp_i18n_default.inc omp.h) +endmacro() +libomp_get_evflags(LIBOMP_EVFLAGS) +libomp_string_to_list("${LIBOMP_EVFLAGS}" LIBOMP_EVFLAGS) +set_source_files_properties(omp_lib.h PROPERTIES EV_COMPILE_DEFINITIONS "-D KMP_INT_PTR_KIND=\"int_ptr_kind()\"") +set_source_files_properties(libomp.rc PROPERTIES EV_COMPILE_DEFINITIONS "-D KMP_FILE=${LIBOMP_LIB_FILE}" GENERATED TRUE) +libomp_expand_vars_recipe(${LIBOMP_INC_DIR} omp.h) +libomp_expand_vars_recipe(${LIBOMP_INC_DIR} ompt.h) +libomp_expand_vars_recipe(${LIBOMP_INC_DIR} omp_lib.h) +libomp_expand_vars_recipe(${LIBOMP_INC_DIR} omp_lib.f) +libomp_expand_vars_recipe(${LIBOMP_INC_DIR} omp_lib.f90) +libomp_expand_vars_recipe(${LIBOMP_SRC_DIR} libomp.rc) -# For Windows, there is a definitions file (.def) and resource file (.res) created using generate-def.pl and rc.exe respectively. -if(${WINDOWS}) - add_custom_target(libomp-needed-windows-files DEPENDS ${def_file} ${CMAKE_CURRENT_BINARY_DIR}/libomp.rc) - list(APPEND lib_src_files ${CMAKE_CURRENT_BINARY_DIR}/libomp.rc) -endif() +# Generate message catalog files: kmp_i18n_id.inc and kmp_i18n_default.inc +add_custom_command( + OUTPUT kmp_i18n_id.inc + COMMAND ${PERL_EXECUTABLE} ${LIBOMP_TOOLS_DIR}/message-converter.pl --os=${LIBOMP_PERL_SCRIPT_OS} + --arch=${LIBOMP_ARCH} --prefix=kmp_i18n --enum=kmp_i18n_id.inc ${LIBOMP_SRC_DIR}/i18n/en_US.txt + DEPENDS ${LIBOMP_SRC_DIR}/i18n/en_US.txt ${LIBOMP_TOOLS_DIR}/message-converter.pl +) +add_custom_command( + OUTPUT kmp_i18n_default.inc + COMMAND ${PERL_EXECUTABLE} ${LIBOMP_TOOLS_DIR}/message-converter.pl --os=${LIBOMP_PERL_SCRIPT_OS} + --arch=${LIBOMP_ARCH} --prefix=kmp_i18n --default=kmp_i18n_default.inc ${LIBOMP_SRC_DIR}/i18n/en_US.txt + DEPENDS ${LIBOMP_SRC_DIR}/i18n/en_US.txt ${LIBOMP_TOOLS_DIR}/message-converter.pl +) -# Remove any cmake-automatic linking of libraries by linker, This is so linux -# and mac don't include libstdc++ just because we compile c++ files. -if(${LIBOMP_USE_PREDEFINED_LINKER_FLAGS}) - set(CMAKE_C_IMPLICIT_LINK_LIBRARIES "") - set(CMAKE_CXX_IMPLICIT_LINK_LIBRARIES "") - set(CMAKE_ASM_IMPLICIT_LINK_LIBRARIES "") -endif() +# Set the -D definitions for all sources +libomp_get_definitions_flags(LIBOMP_CONFIGURED_DEFINITIONS_FLAGS) +add_definitions(${LIBOMP_CONFIGURED_DEFINITIONS_FLAGS}) -# --- ${lib_file} rule --- -add_library(omp SHARED ${lib_src_files}) -set_target_properties(omp PROPERTIES - PREFIX "" SUFFIX "" # Take control - OUTPUT_NAME "${lib_file}" # of output name - LINK_FLAGS "${LD_FLAGS}" - LINKER_LANGUAGE C # use C Compiler for linking step - SKIP_BUILD_RPATH true # have Mac linker -install_name just be "-install_name libomp.dylib" +# Set the -I includes for all sources +include_directories( + ${CMAKE_CURRENT_BINARY_DIR} + ${LIBOMP_SRC_DIR} + ${LIBOMP_SRC_DIR}/i18n + ${LIBOMP_INC_DIR} + ${LIBOMP_SRC_DIR}/thirdparty/ittnotify ) -# --- Copy libomp into exports directory post build --- -if(${WINDOWS}) - get_target_property(LIBOMP_OUTPUT_DIRECTORY omp RUNTIME_OUTPUT_DIRECTORY) +# Getting correct source files to build library +set(LIBOMP_CFILES) +set(LIBOMP_CXXFILES) +set(LIBOMP_ASMFILES) +if(${STUBS_LIBRARY}) + set(LIBOMP_CFILES kmp_stub.c) else() - get_target_property(LIBOMP_OUTPUT_DIRECTORY omp LIBRARY_OUTPUT_DIRECTORY) -endif() -if(NOT LIBOMP_OUTPUT_DIRECTORY) - set(LIBOMP_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) -endif() - -if(${LIBOMP_COPY_EXPORTS}) - add_custom_command(TARGET omp POST_BUILD - COMMAND ${CMAKE_COMMAND} -E make_directory ${export_lib_dir} - COMMAND ${CMAKE_COMMAND} -E copy ${LIBOMP_OUTPUT_DIRECTORY}/${lib_file} ${export_lib_dir} + # Get C files + set(LIBOMP_CFILES + kmp_alloc.c + kmp_atomic.c + kmp_csupport.c + kmp_debug.c + kmp_itt.c + kmp_environment.c + kmp_error.c + kmp_global.c + kmp_i18n.c + kmp_io.c + kmp_runtime.c + kmp_settings.c + kmp_str.c + kmp_tasking.c + kmp_taskq.c + kmp_threadprivate.c + kmp_utility.c ) + if(WIN32) + # Windows specific files + libomp_append(LIBOMP_CFILES z_Windows_NT_util.c) + libomp_append(LIBOMP_CFILES z_Windows_NT-586_util.c) + libomp_append(LIBOMP_ASMFILES z_Windows_NT-586_asm.asm) # Windows assembly file + else() + # Unix specific files + libomp_append(LIBOMP_CFILES z_Linux_util.c) + libomp_append(LIBOMP_CFILES kmp_gsupport.c) + libomp_append(LIBOMP_ASMFILES z_Linux_asm.s) # Unix assembly file + endif() + libomp_append(LIBOMP_CFILES thirdparty/ittnotify/ittnotify_static.c LIBOMP_USE_ITT_NOTIFY) + libomp_append(LIBOMP_CFILES kmp_debugger.c LIBOMP_USE_DEBUGGER) + # Get C++ files + set(LIBOMP_CXXFILES + kmp_barrier.cpp + kmp_wait_release.cpp + kmp_affinity.cpp + kmp_dispatch.cpp + kmp_lock.cpp + kmp_sched.cpp + ) + libomp_append(LIBOMP_CXXFILES kmp_stats.cpp LIBOMP_STATS) + libomp_append(LIBOMP_CXXFILES kmp_stats_timing.cpp LIBOMP_STATS) + if(${LIBOMP_OMP_VERSION} GREATER 40 OR ${LIBOMP_OMP_VERSION} EQUAL 40) + libomp_append(LIBOMP_CXXFILES kmp_taskdeps.cpp) + libomp_append(LIBOMP_CXXFILES kmp_cancel.cpp) + endif() endif() +# Files common to stubs and normal library +libomp_append(LIBOMP_CFILES kmp_ftn_cdecl.c) +libomp_append(LIBOMP_CFILES kmp_ftn_extra.c) +libomp_append(LIBOMP_CFILES kmp_version.c) +libomp_append(LIBOMP_CFILES ompt-general.c IF_TRUE LIBOMP_OMPT_SUPPORT) -# Linking command will include libraries in LD_LIB_FLAGS -target_link_libraries(omp ${LD_LIB_FLAGS} ${CMAKE_DL_LIBS}) - -# Create *.inc and omp.h before compiling any sources -add_dependencies(omp libomp-needed-headers) -if(${WINDOWS}) -# Create .def and .rc file before compiling any sources - add_dependencies(omp libomp-needed-windows-files) -endif() +set(LIBOMP_SOURCE_FILES ${LIBOMP_CFILES} ${LIBOMP_CXXFILES} ${LIBOMP_ASMFILES}) +# For Windows, there is a resource file (.rc -> .res) that is also compiled +libomp_append(LIBOMP_SOURCE_FILES libomp.rc WIN32) +# Get compiler and assembler flags +libomp_get_cflags(LIBOMP_CONFIGURED_CFLAGS) +libomp_get_cxxflags(LIBOMP_CONFIGURED_CXXFLAGS) +libomp_get_asmflags(LIBOMP_CONFIGURED_ASMFLAGS) # Set the compiler flags for each type of source -set_source_files_properties(${lib_c_items} - ${imp_c_items} PROPERTIES COMPILE_FLAGS "${C_FLAGS}") -set_source_files_properties(${lib_cxx_items} PROPERTIES COMPILE_FLAGS "${CXX_FLAGS}") -if(${WINDOWS}) - # Windows operating system has to use MASM assembler - set_source_files_properties(${lib_asm_items} PROPERTIES COMPILE_FLAGS "${ASM_FLAGS}") -else() - # Non-Windows operating systems can use compiler to assemble the assembly files - set_source_files_properties(${lib_asm_items} PROPERTIES COMPILE_FLAGS "${ASM_FLAGS}" LANGUAGE C) +set_source_files_properties(${LIBOMP_CFILES} PROPERTIES COMPILE_FLAGS "${LIBOMP_CONFIGURED_CFLAGS}") +set_source_files_properties(${LIBOMP_CXXFILES} PROPERTIES COMPILE_FLAGS "${LIBOMP_CONFIGURED_CXXFLAGS}") +set_source_files_properties(${LIBOMP_ASMFILES} PROPERTIES COMPILE_FLAGS "${LIBOMP_CONFIGURED_ASMFLAGS}") +# Let the compiler handle the assembly files on Unix-like systems +if(NOT WIN32) + set_source_files_properties(${LIBOMP_ASMFILES} PROPERTIES LANGUAGE C) endif() -# Set the -D definitions for all sources -add_definitions(${DEFINITIONS_FLAGS}) -# If creating a build that imitates build.pl's rules then set USE_BUILDPL_RULES to true -if(${LIBOMP_USE_BUILDPL_RULES}) - include(BuildPLRules) +# Remove any cmake-automatic linking of the standard C++ library. +# We neither need (nor want) the standard C++ library dependency even though we compile c++ files. +if(NOT ${LIBOMP_USE_STDCPPLIB}) + set(CMAKE_CXX_IMPLICIT_LINK_LIBRARIES) endif() -###################################################### -# --- Source file specific flags --- -# kmp_version.o : -D _KMP_BUILD_TIME="\"$(date)}\"" -set_source_files_properties(kmp_version.c PROPERTIES COMPILE_DEFINITIONS "_KMP_BUILD_TIME=\"\\\"${date}\\\"\"") +# Add the OpenMP library +libomp_get_ldflags(LIBOMP_CONFIGURED_LDFLAGS) +add_library(omp SHARED ${LIBOMP_SOURCE_FILES}) +set_target_properties(omp PROPERTIES + PREFIX "" SUFFIX "" OUTPUT_NAME "${LIBOMP_LIB_FILE}" + LINK_FLAGS "${LIBOMP_CONFIGURED_LDFLAGS}" + LINKER_LANGUAGE C # use C Compiler for linking step + SKIP_BUILD_RPATH true # have Mac linker -install_name just be "-install_name libomp.dylib" +) -if(${WINDOWS}) - set_source_files_properties(thirdparty/ittnotify/ittnotify_static.c PROPERTIES COMPILE_DEFINITIONS "UNICODE") -endif() +# Linking command will include libraries in LIBOMP_CONFIGURED_LIBFLAGS +libomp_get_libflags(LIBOMP_CONFIGURED_LIBFLAGS) +target_link_libraries(omp ${LIBOMP_CONFIGURED_LIBFLAGS} ${CMAKE_DL_LIBS}) -###################################################### -# MAC specific build rules -if(${MAC}) - # fat library rules - if(${INTEL64}) - _export_lib_fat_dir("mac_32e" export_fat_mac_32e) - _export_lib_dir("mac_32" export_mac_32) - _export_lib_dir("mac_32e" export_mac_32e) - add_custom_target(fat - COMMAND ${CMAKE_COMMAND} -E echo Building 32 and 32e fat libraries from ${export_mac_32}/${lib_file} and ${export_mac_32e}/${lib_file} - COMMAND ${CMAKE_COMMAND} -E echo Will put fat library in ${export_fat_mac_32e} directory - COMMAND ${CMAKE_COMMAND} -E make_directory ${export_fat_mac_32e} - COMMAND lipo -create -output ${export_fat_mac_32e}/${lib_file} ${export_mac_32}/${lib_file} ${export_mac_32e}/${lib_file} - ) - endif() -endif() +# Create *.inc and omp.h before compiling any sources +# objects depend on : .inc files and omp.h (and ompt.h if LIBOMP_OMPT_SUPPORT is on) +# This way the *.inc and omp.h are generated before any compilations take place +set(LIBOMP_NEEDED_HEADERS kmp_i18n_id.inc kmp_i18n_default.inc omp.h) +libomp_append(LIBOMP_NEEDED_HEADERS ompt.h LIBOMP_OMPT_SUPPORT) +add_custom_target(libomp-needed-headers DEPENDS ${LIBOMP_NEEDED_HEADERS}) +add_dependencies(omp libomp-needed-headers) -###################################################### # Windows specific build rules -if(${WINDOWS}) - - # --- Create $(imp_file) --- - # This file is first created in the unstripped/${lib_file} creation step. - # It is then "re-linked" to include kmp_import.c which prevents linking of both Visual Studio OpenMP and newly built OpenMP - if(NOT "${imp_file}" STREQUAL "") - set(generated_import_file ${lib_file}${lib}) - add_library(ompimp STATIC ${generated_import_file} ${imp_src_files}) - set_source_files_properties(${generated_import_file} PROPERTIES GENERATED TRUE EXTERNAL_OBJECT TRUE) - set_target_properties(ompimp PROPERTIES - PREFIX "" SUFFIX "" - OUTPUT_NAME "${imp_file}" - STATIC_LIBRARY_FLAGS "${AR_FLAGS}" - LINKER_LANGUAGE C - SKIP_BUILD_RPATH true - ) - add_custom_command(TARGET ompimp PRE_BUILD COMMAND ${CMAKE_COMMAND} -E remove -f ${imp_file}) - add_dependencies(ompimp omp) - get_target_property(LIBOMPIMP_OUTPUT_DIRECTORY ompimp ARCHIVE_OUTPUT_DIRECTORY) - if(NOT LIBOMPIMP_OUTPUT_DIRECTORY) - set(LIBOMPIMP_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) - endif() - if(${LIBOMP_COPY_EXPORTS}) - add_custom_command(TARGET ompimp POST_BUILD - COMMAND ${CMAKE_COMMAND} -E make_directory ${export_lib_dir} - COMMAND ${CMAKE_COMMAND} -E copy ${LIBOMPIMP_OUTPUT_DIRECTORY}/${imp_file} ${export_lib_dir} - ) - endif() +if(WIN32) + # Create .def and .rc file before compiling any sources + add_custom_target(libomp-needed-windows-files DEPENDS ${LIBOMP_LIB_NAME}.def libomp.rc) + add_dependencies(omp libomp-needed-windows-files) + # z_Windows_NT-586_asm.asm (masm file) send it i386 or x86_64 architecture definition flag + if(${IA32}) + set_source_files_properties(z_Windows_NT-586_asm.asm PROPERTIES COMPILE_DEFINITIONS "_M_IA32") + elseif(${INTEL64}) + set_source_files_properties(z_Windows_NT-586_asm.asm PROPERTIES COMPILE_DEFINITIONS "_M_AMD64") endif() + set_source_files_properties(thirdparty/ittnotify/ittnotify_static.c PROPERTIES COMPILE_DEFINITIONS "UNICODE") - # --- Create $(def_file) --- - if(NOT "${def_file}" STREQUAL "") - string_to_list("${gd_flags}" gd_flags) - add_custom_command( - OUTPUT ${def_file} - COMMAND ${PERL_EXECUTABLE} ${tools_dir}/generate-def.pl ${gd_flags} -o ${def_file} ${CMAKE_CURRENT_SOURCE_DIR}/dllexports - DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/dllexports ${tools_dir}/generate-def.pl - ) + # Create Windows import library + # the import library is "re-linked" to include kmp_import.c which prevents + # linking of both Visual Studio OpenMP and newly built OpenMP + set_source_files_properties(kmp_import.c PROPERTIES COMPILE_FLAGS "${LIBOMP_CONFIGURED_CFLAGS}") + set(LIBOMP_IMP_LIB_FILE ${LIBOMP_LIB_NAME}${CMAKE_STATIC_LIBRARY_SUFFIX}) + set(LIBOMP_GENERATED_IMP_LIB_FILENAME ${LIBOMP_LIB_FILE}${CMAKE_STATIC_LIBRARY_SUFFIX}) + set_target_properties(omp PROPERTIES + VERSION ${LIBOMP_VERSION}.0 # uses /version flag + IMPORT_PREFIX "" IMPORT_SUFFIX "" # control generated import library name when building omp + ARCHIVE_OUTPUT_NAME ${LIBOMP_GENERATED_IMP_LIB_FILENAME} + ) + # Get generated import library from creating omp + get_target_property(LIBOMP_IMPORT_LIB_DIRECTORY omp ARCHIVE_OUTPUT_DIRECTORY) + if(LIBOMP_IMPORT_LIB_DIRECTORY) + set(LIBOMP_GENERATED_IMP_LIB ${LIBOMP_IMPORT_LIB_DIRECTORY}/${LIBOMP_GENERATED_IMP_LIB_FILENAME}) + else() + set(LIBOMP_GENERATED_IMP_LIB ${CMAKE_CURRENT_BINARY_DIR}/${LIBOMP_GENERATED_IMP_LIB_FILENAME}) endif() + set_source_files_properties(${LIBOMP_GENERATED_IMP_LIB} PROPERTIES GENERATED TRUE EXTERNAL_OBJECT TRUE) + # Create new import library that is just the previously created one + kmp_import.c + add_library(ompimp STATIC ${LIBOMP_GENERATED_IMP_LIB} kmp_import.c) + set_target_properties(ompimp PROPERTIES + PREFIX "" SUFFIX "" OUTPUT_NAME "${LIBOMP_IMP_LIB_FILE}" + LINKER_LANGUAGE C + SKIP_BUILD_RPATH true + ) + add_dependencies(ompimp omp) # ensure generated import library is created first + # Create def file to designate exported functions + libomp_get_gdflags(LIBOMP_GDFLAGS) # generate-def.pl flags (Windows only) + libomp_string_to_list("${LIBOMP_GDFLAGS}" LIBOMP_GDFLAGS) + add_custom_command( + OUTPUT ${LIBOMP_LIB_NAME}.def + COMMAND ${PERL_EXECUTABLE} ${LIBOMP_TOOLS_DIR}/generate-def.pl ${LIBOMP_GDFLAGS} + -o ${LIBOMP_LIB_NAME}.def ${CMAKE_CURRENT_SOURCE_DIR}/dllexports + DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/dllexports ${LIBOMP_TOOLS_DIR}/generate-def.pl + ) endif() -###################################################### -# kmp_i18n_id.inc and kmp_i18n_default.inc -set(perlcmd "${PERL_EXECUTABLE}" "${tools_dir}/message-converter.pl" "${oa_opts}" "--prefix=kmp_i18n" "--enum=kmp_i18n_id.inc" "${src_dir}/i18n/en_US.txt") -add_custom_command( - OUTPUT kmp_i18n_id.inc - COMMAND ${perlcmd} - DEPENDS ${src_dir}/i18n/en_US.txt ${tools_dir}/message-converter.pl -) -set(perlcmd "${PERL_EXECUTABLE}" "${tools_dir}/message-converter.pl" "${oa_opts}" "--prefix=kmp_i18n" "--default=kmp_i18n_default.inc" "${src_dir}/i18n/en_US.txt") -add_custom_command( - OUTPUT kmp_i18n_default.inc - COMMAND ${perlcmd} - DEPENDS ${src_dir}/i18n/en_US.txt ${tools_dir}/message-converter.pl -) - -###################################################### -# Micro test rules for after library has been built (cmake/MicroTests.cmake) -# - Only perform if ${LIBOMP_MICRO_TESTS} == true (specify when invoking: cmake -Dtests=on ...) -if(${LIBOMP_MICRO_TESTS}) - include(MicroTests) - add_custom_target(libomp-micro-tests) - if(NOT ${MIC} AND ${LIBOMP_TEST_TOUCH}) - add_dependencies(libomp-micro-tests libomp-test-touch) - endif() - if(${LINUX} AND ${LIBOMP_TEST_RELO}) - add_dependencies(libomp-micro-tests libomp-test-relo) - endif() - if(${LINUX} AND ${LIBOMP_TEST_EXECSTACK}) - add_dependencies(libomp-micro-tests libomp-test-execstack) - endif() - if(${MIC} AND ${LIBOMP_TEST_INSTR}) - add_dependencies(libomp-micro-tests libomp-test-instr) - endif() - if(${LIBOMP_TEST_DEPS}) - add_dependencies(libomp-micro-tests libomp-test-deps) - endif() -endif() - -###################################################### -# --- Create Fortran Files --- -# omp_lib.mod +# Building the Fortran module files +# One compilation step creates both omp_lib.mod and omp_lib_kinds.mod if(${LIBOMP_FORTRAN_MODULES}) - # Grab fortran-compiler-dependent flags - # Cmake will look for cmake/${CMAKE_Fortran_COMPILER_ID}/FortranFlags.cmake to append additional fortran flags. - enable_language(Fortran) - set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake/${CMAKE_Fortran_COMPILER_ID} ${CMAKE_MODULE_PATH}) - find_file(fortran_specific_include_file_found FortranFlags.cmake ${CMAKE_MODULE_PATH}) - if(fortran_specific_include_file_found) - include(FortranFlags) - append_fortran_compiler_specific_fort_flags(F_FLAGS) + add_custom_target(libomp-mod ALL DEPENDS omp_lib.mod omp_lib_kinds.mod) + libomp_get_fflags(LIBOMP_CONFIGURED_FFLAGS) + if(CMAKE_Fortran_COMPILER_SUPPORTS_F90) + set(LIBOMP_FORTRAN_SOURCE_FILE omp_lib.f90) else() - warning_say("Could not find cmake/${CMAKE_Fortran_COMPILER_ID}/FortranFlags.cmake: will only use default flags in CommonFlags.cmake") + set(LIBOMP_FORTRAN_SOURCE_FILE omp_lib.f) endif() - set(omp_lib_f "omp_lib.f90" ) - add_custom_command( - OUTPUT "omp_lib.mod" - COMMAND ${CMAKE_Fortran_COMPILER} -c ${F_FLAGS} ${omp_lib_f} - DEPENDS ${omp_lib_f} - ) add_custom_command( - OUTPUT "omp_lib_kinds.mod" - COMMAND ${CMAKE_Fortran_COMPILER} -c ${F_FLAGS} ${omp_lib_f} - DEPENDS ${omp_lib_f} + OUTPUT omp_lib.mod omp_lib_kinds.mod + COMMAND ${CMAKE_Fortran_COMPILER} -c ${LIBOMP_CONFIGURED_FFLAGS} ${LIBOMP_FORTRAN_SOURCE_FILE} + DEPENDS ${LIBOMP_FORTRAN_SOURCE_FILE} omp_lib.h ) - # clean omp_lib.o from build directory when "make clean" - set_directory_properties(PROPERTIES ADDITIONAL_MAKE_CLEAN_FILES omp_lib${obj}) + set_directory_properties(PROPERTIES ADDITIONAL_MAKE_CLEAN_FILES omp_lib${CMAKE_C_OUTPUT_EXTENSION}) endif() -############################################################### -# --- Using expand-vars.pl to generate files --- -# - 'file' is generated using expand-vars.pl and 'file'.var -# - Any .h .f .f90 .rc files should be created with this recipe -macro(expand_vars_recipe file_dir filename) - get_source_file_property(extra_ev_flags ${filename} EV_COMPILE_DEFINITIONS) - if("${extra_ev_flags}" MATCHES "NOTFOUND") - set(extra_ev_flags) - else() - string_to_list("${extra_ev_flags}" extra_ev_flags) - endif() - if(NOT "${filename}" STREQUAL "") - add_custom_command( - OUTPUT ${filename} - COMMAND ${PERL_EXECUTABLE} ${tools_dir}/expand-vars.pl --strict ${ev_flags} ${extra_ev_flags} ${file_dir}/${filename}.var ${filename} - DEPENDS ${file_dir}/${filename}.var kmp_version.c ${tools_dir}/expand-vars.pl - ) - endif() -endmacro() -string_to_list("${ev_flags}" ev_flags) -# omp_lib.h : ev-flags += -D KMP_INT_PTR_KIND="int_ptr_kind()" -set_source_files_properties(omp_lib.h PROPERTIES EV_COMPILE_DEFINITIONS "-D KMP_INT_PTR_KIND=\"int_ptr_kind()\"") -# libomp.rc : ev-flags += -D KMP_FILE=$(lib_file) -set_source_files_properties(libomp.rc PROPERTIES EV_COMPILE_DEFINITIONS "-D KMP_FILE=${lib_file}") -expand_vars_recipe(${CMAKE_CURRENT_SOURCE_DIR}/include/${LIBOMP_OMP_VERSION} omp.h) -expand_vars_recipe(${CMAKE_CURRENT_SOURCE_DIR}/include/${LIBOMP_OMP_VERSION} ompt.h) -expand_vars_recipe(${CMAKE_CURRENT_SOURCE_DIR}/include/${LIBOMP_OMP_VERSION} omp_lib.h) -expand_vars_recipe(${CMAKE_CURRENT_SOURCE_DIR}/include/${LIBOMP_OMP_VERSION} omp_lib.f) -expand_vars_recipe(${CMAKE_CURRENT_SOURCE_DIR}/include/${LIBOMP_OMP_VERSION} omp_lib.f90) -expand_vars_recipe(${CMAKE_CURRENT_SOURCE_DIR} libomp.rc) +# Move files to exports/ directory if requested +if(${LIBOMP_COPY_EXPORTS}) + include(LibompExports) +endif() + +# Micro test rules for after library has been built (cmake/LibompMicroTests.cmake) +include(LibompMicroTests) +add_custom_target(libomp-micro-tests) +if(NOT ${MIC} AND NOT CMAKE_CROSSCOMPILING) + add_dependencies(libomp-micro-tests libomp-test-touch) +endif() +if(NOT WIN32 AND NOT APPLE) + add_dependencies(libomp-micro-tests libomp-test-relo) +endif() +if(NOT WIN32 AND NOT APPLE) + add_dependencies(libomp-micro-tests libomp-test-execstack) +endif() +if(${MIC}) + add_dependencies(libomp-micro-tests libomp-test-instr) +endif() +add_dependencies(libomp-micro-tests libomp-test-deps) -#################################################################### # Install rules # We want to install libomp in DESTDIR/CMAKE_INSTALL_PREFIX/lib # We want to install headers in DESTDIR/CMAKE_INSTALL_PREFIX/include @@ -306,34 +275,41 @@ else() string(REGEX MATCH "[0-9]+\\.[0-9]+(\\.[0-9]+)?" CLANG_VERSION ${PACKAGE_VERSION}) set(LIBOMP_HEADERS_INSTALL_PATH lib${LIBOMP_LIBDIR_SUFFIX}/clang/${CLANG_VERSION}/include) endif() -if(${WINDOWS}) +if(WIN32) install(TARGETS omp RUNTIME DESTINATION bin) - if(NOT "${imp_file}" STREQUAL "") - install(TARGETS ompimp ARCHIVE DESTINATION lib${LIBOMP_LIBDIR_SUFFIX}) - endif() + install(TARGETS ompimp ARCHIVE DESTINATION lib${LIBOMP_LIBDIR_SUFFIX}) # Create aliases (regular copies) of the library for backwards compatibility set(LIBOMP_ALIASES "libiomp5md") foreach(alias IN LISTS LIBOMP_ALIASES) - install(CODE "execute_process(COMMAND \"\${CMAKE_COMMAND}\" -E copy \"${lib_file}\" \"${alias}${dll}\" - WORKING_DIRECTORY \${CMAKE_INSTALL_PREFIX}/bin)") - install(CODE "execute_process(COMMAND \"\${CMAKE_COMMAND}\" -E copy \"${imp_file}\" \"${alias}${lib}\" - WORKING_DIRECTORY \${CMAKE_INSTALL_PREFIX}/lib${LIBOMP_LIBDIR_SUFFIX})") + install(CODE "execute_process(COMMAND \"\${CMAKE_COMMAND}\" -E copy \"${LIBOMP_LIB_FILE}\" + \"${alias}${CMAKE_SHARED_LIBRARY_SUFFIX}\" WORKING_DIRECTORY \${CMAKE_INSTALL_PREFIX}/bin)") + install(CODE "execute_process(COMMAND \"\${CMAKE_COMMAND}\" -E copy \"${LIBOMP_IMP_LIB_FILE}\" + \"${alias}${CMAKE_STATIC_LIBRARY_SUFFIX}\" WORKING_DIRECTORY \${CMAKE_INSTALL_PREFIX}/lib${LIBOMP_LIBDIR_SUFFIX})") endforeach() else() - install(TARGETS omp LIBRARY DESTINATION lib${LIBOMP_LIBDIR_SUFFIX}) + install(TARGETS omp LIBRARY DESTINATION lib${LIBOMP_LIBDIR_SUFFIX}) # Create aliases (symlinks) of the library for backwards compatibility set(LIBOMP_ALIASES "libgomp;libiomp5") foreach(alias IN LISTS LIBOMP_ALIASES) - install(CODE "execute_process(COMMAND \"\${CMAKE_COMMAND}\" -E create_symlink \"${lib_file}\" \"${alias}${dll}\" - WORKING_DIRECTORY \$ENV{DESTDIR}\${CMAKE_INSTALL_PREFIX}/lib${LIBOMP_LIBDIR_SUFFIX})") + install(CODE "execute_process(COMMAND \"\${CMAKE_COMMAND}\" -E create_symlink \"${LIBOMP_LIB_FILE}\" + \"${alias}${CMAKE_SHARED_LIBRARY_SUFFIX}\" WORKING_DIRECTORY + \$ENV{DESTDIR}\${CMAKE_INSTALL_PREFIX}/lib${LIBOMP_LIBDIR_SUFFIX})") endforeach() endif() install( - FILES - ${CMAKE_CURRENT_BINARY_DIR}/omp.h + FILES + ${CMAKE_CURRENT_BINARY_DIR}/omp.h DESTINATION ${LIBOMP_HEADERS_INSTALL_PATH} ) if(${LIBOMP_OMPT_SUPPORT}) install(FILES ${CMAKE_CURRENT_BINARY_DIR}/ompt.h DESTINATION ${LIBOMP_HEADERS_INSTALL_PATH}) endif() +if(${LIBOMP_FORTRAN_MODULES}) + install(FILES + ${CMAKE_CURRENT_BINARY_DIR}/omp_lib.h + ${CMAKE_CURRENT_BINARY_DIR}/omp_lib.mod + ${CMAKE_CURRENT_BINARY_DIR}/omp_lib_kinds.mod + DESTINATION ${LIBOMP_HEADERS_INSTALL_PATH} + ) +endif() |