Merge topic 'make-fortran-preprocessor-assembly-targets'
b6b37e30 Makefile: Add assembly and preprocessed targets for Fortran 0842b084 Makefile: Refactor checks for lang-specific targets and export compile cmds
This commit is contained in:
commit
a1f964ef68
@ -8,10 +8,5 @@ set(CMAKE_Fortran_FORMAT_FREE_FLAG "-ffree-form")
|
|||||||
set(CMAKE_Fortran_FLAGS_MINSIZEREL_INIT "-Os")
|
set(CMAKE_Fortran_FLAGS_MINSIZEREL_INIT "-Os")
|
||||||
set(CMAKE_Fortran_FLAGS_RELEASE_INIT "-O3")
|
set(CMAKE_Fortran_FLAGS_RELEASE_INIT "-O3")
|
||||||
|
|
||||||
# We require updates to CMake C++ code to support preprocessing rules
|
|
||||||
# for Fortran.
|
|
||||||
set(CMAKE_Fortran_CREATE_PREPROCESSED_SOURCE)
|
|
||||||
set(CMAKE_Fortran_CREATE_ASSEMBLY_SOURCE)
|
|
||||||
|
|
||||||
# Fortran-specific feature flags.
|
# Fortran-specific feature flags.
|
||||||
set(CMAKE_Fortran_MODDIR_FLAG -J)
|
set(CMAKE_Fortran_MODDIR_FLAG -J)
|
||||||
|
@ -1,3 +1,6 @@
|
|||||||
set(CMAKE_Fortran_VERBOSE_FLAG "-v")
|
set(CMAKE_Fortran_VERBOSE_FLAG "-v")
|
||||||
set(CMAKE_Fortran_FORMAT_FIXED_FLAG "+source=fixed")
|
set(CMAKE_Fortran_FORMAT_FIXED_FLAG "+source=fixed")
|
||||||
set(CMAKE_Fortran_FORMAT_FREE_FLAG "+source=free")
|
set(CMAKE_Fortran_FORMAT_FREE_FLAG "+source=free")
|
||||||
|
|
||||||
|
set(CMAKE_Fortran_CREATE_ASSEMBLY_SOURCE "<CMAKE_Fortran_COMPILER> <DEFINES> <FLAGS> -S <SOURCE> -o <ASSEMBLY_SOURCE>")
|
||||||
|
set(CMAKE_Fortran_CREATE_PREPROCESSED_SOURCE "<CMAKE_Fortran_COMPILER> <DEFINES> <FLAGS> -E <SOURCE> > <PREPROCESSED_SOURCE>")
|
||||||
|
@ -7,3 +7,6 @@ set(CMAKE_Fortran_MODDIR_FLAG "-module ")
|
|||||||
set(CMAKE_Fortran_VERBOSE_FLAG "-v")
|
set(CMAKE_Fortran_VERBOSE_FLAG "-v")
|
||||||
set(CMAKE_Fortran_FORMAT_FIXED_FLAG "-fixed")
|
set(CMAKE_Fortran_FORMAT_FIXED_FLAG "-fixed")
|
||||||
set(CMAKE_Fortran_FORMAT_FREE_FLAG "-free")
|
set(CMAKE_Fortran_FORMAT_FREE_FLAG "-free")
|
||||||
|
|
||||||
|
set(CMAKE_Fortran_CREATE_PREPROCESSED_SOURCE "<CMAKE_Fortran_COMPILER> <DEFINES> <FLAGS> -E <SOURCE> > <PREPROCESSED_SOURCE>")
|
||||||
|
set(CMAKE_Fortran_CREATE_ASSEMBLY_SOURCE "<CMAKE_Fortran_COMPILER> <DEFINES> <FLAGS> -S <SOURCE> -o <ASSEMBLY_SOURCE>")
|
||||||
|
@ -7,9 +7,4 @@ set(CMAKE_Fortran_FORMAT_FREE_FLAG "-Mfreeform")
|
|||||||
set(CMAKE_Fortran_FLAGS_INIT "${CMAKE_Fortran_FLAGS_INIT} -Mpreprocess -Kieee")
|
set(CMAKE_Fortran_FLAGS_INIT "${CMAKE_Fortran_FLAGS_INIT} -Mpreprocess -Kieee")
|
||||||
set(CMAKE_Fortran_FLAGS_DEBUG_INIT "${CMAKE_Fortran_FLAGS_DEBUG_INIT} -Mbounds")
|
set(CMAKE_Fortran_FLAGS_DEBUG_INIT "${CMAKE_Fortran_FLAGS_DEBUG_INIT} -Mbounds")
|
||||||
|
|
||||||
# We require updates to CMake C++ code to support preprocessing rules
|
|
||||||
# for Fortran.
|
|
||||||
set(CMAKE_Fortran_CREATE_PREPROCESSED_SOURCE)
|
|
||||||
set(CMAKE_Fortran_CREATE_ASSEMBLY_SOURCE)
|
|
||||||
|
|
||||||
set(CMAKE_Fortran_MODDIR_FLAG "-module ")
|
set(CMAKE_Fortran_MODDIR_FLAG "-module ")
|
||||||
|
@ -16,3 +16,6 @@ set(CMAKE_Fortran_FLAGS_RELEASE_INIT "-xO3 -DNDEBUG")
|
|||||||
set(CMAKE_Fortran_FLAGS_RELWITHDEBINFO_INIT "-g -xO2 -DNDEBUG")
|
set(CMAKE_Fortran_FLAGS_RELWITHDEBINFO_INIT "-g -xO2 -DNDEBUG")
|
||||||
set(CMAKE_Fortran_MODDIR_FLAG "-moddir=")
|
set(CMAKE_Fortran_MODDIR_FLAG "-moddir=")
|
||||||
set(CMAKE_Fortran_MODPATH_FLAG "-M")
|
set(CMAKE_Fortran_MODPATH_FLAG "-M")
|
||||||
|
|
||||||
|
set(CMAKE_Fortran_CREATE_PREPROCESSED_SOURCE "<CMAKE_Fortran_COMPILER> <DEFINES> <FLAGS> -E <SOURCE> > <PREPROCESSED_SOURCE>")
|
||||||
|
set(CMAKE_Fortran_CREATE_ASSEMBLY_SOURCE "<CMAKE_Fortran_COMPILER> <DEFINES> <FLAGS> -S <SOURCE> -o <ASSEMBLY_SOURCE>")
|
||||||
|
@ -12,6 +12,6 @@ set(CMAKE_Fortran_DEFINE_FLAG "-WF,-D")
|
|||||||
# -qhalt=e = Halt on error messages (rather than just severe errors)
|
# -qhalt=e = Halt on error messages (rather than just severe errors)
|
||||||
set(CMAKE_Fortran_FLAGS_INIT "-qthreaded -qhalt=e")
|
set(CMAKE_Fortran_FLAGS_INIT "-qthreaded -qhalt=e")
|
||||||
|
|
||||||
# We require updates to CMake C++ code to support preprocessing rules for Fortran.
|
# xlf: 1501-214 (W) command option E reserved for future use - ignored
|
||||||
set(CMAKE_Fortran_CREATE_PREPROCESSED_SOURCE)
|
set(CMAKE_Fortran_CREATE_PREPROCESSED_SOURCE)
|
||||||
set(CMAKE_Fortran_CREATE_ASSEMBLY_SOURCE)
|
set(CMAKE_Fortran_CREATE_ASSEMBLY_SOURCE)
|
||||||
|
@ -1,2 +1,5 @@
|
|||||||
include(Platform/HP-UX-HP)
|
include(Platform/HP-UX-HP)
|
||||||
__hpux_compiler_hp(Fortran)
|
__hpux_compiler_hp(Fortran)
|
||||||
|
|
||||||
|
set(CMAKE_Fortran_CREATE_PREPROCESSED_SOURCE "<CMAKE_Fortran_COMPILER> <DEFINES> <FLAGS> -E <SOURCE> > <PREPROCESSED_SOURCE>")
|
||||||
|
set(CMAKE_Fortran_CREATE_ASSEMBLY_SOURCE "<CMAKE_Fortran_COMPILER> <DEFINES> <FLAGS> -S <SOURCE> -o <ASSEMBLY_SOURCE>")
|
||||||
|
@ -31,6 +31,14 @@ if(NOT CMAKE_COMPILER_IS_GNUCXX)
|
|||||||
)
|
)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
if(NOT CMAKE_COMPILER_IS_GNUG77)
|
||||||
|
set (CMAKE_Fortran_CREATE_PREPROCESSED_SOURCE "<CMAKE_Fortran_COMPILER> <FLAGS> -E <SOURCE> > <PREPROCESSED_SOURCE>")
|
||||||
|
set (CMAKE_Fortran_CREATE_ASSEMBLY_SOURCE
|
||||||
|
"<CMAKE_Fortran_COMPILER> <FLAGS> -S <SOURCE>"
|
||||||
|
"mv `basename \"<SOURCE>\" | sed 's/\\.[^./]*$$//'`.s <ASSEMBLY_SOURCE>"
|
||||||
|
)
|
||||||
|
endif()
|
||||||
|
|
||||||
# Initialize C link type selection flags. These flags are used when
|
# Initialize C link type selection flags. These flags are used when
|
||||||
# building a shared library, shared module, or executable that links
|
# building a shared library, shared module, or executable that links
|
||||||
# to other libraries to select whether to use the static or shared
|
# to other libraries to select whether to use the static or shared
|
||||||
|
@ -315,36 +315,43 @@ void cmLocalUnixMakefileGenerator3::WriteLocalMakefile()
|
|||||||
|
|
||||||
// Check whether preprocessing and assembly rules make sense.
|
// Check whether preprocessing and assembly rules make sense.
|
||||||
// They make sense only for C and C++ sources.
|
// They make sense only for C and C++ sources.
|
||||||
bool lang_is_c_or_cxx = false;
|
bool lang_has_preprocessor = false;
|
||||||
|
bool lang_has_assembly = false;
|
||||||
|
|
||||||
for(std::vector<LocalObjectEntry>::const_iterator ei =
|
for(std::vector<LocalObjectEntry>::const_iterator ei =
|
||||||
lo->second.begin(); ei != lo->second.end(); ++ei)
|
lo->second.begin(); ei != lo->second.end(); ++ei)
|
||||||
{
|
{
|
||||||
if(ei->Language == "C" || ei->Language == "CXX")
|
if(ei->Language == "C" ||
|
||||||
|
ei->Language == "CXX" ||
|
||||||
|
ei->Language == "Fortran")
|
||||||
{
|
{
|
||||||
lang_is_c_or_cxx = true;
|
// Right now, C, C++ and Fortran have both a preprocessor and the
|
||||||
|
// ability to generate assembly code
|
||||||
|
lang_has_preprocessor = true;
|
||||||
|
lang_has_assembly = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add convenience rules for preprocessed and assembly files.
|
// Add convenience rules for preprocessed and assembly files.
|
||||||
if(lang_is_c_or_cxx && (do_preprocess_rules || do_assembly_rules))
|
if(lang_has_preprocessor && do_preprocess_rules)
|
||||||
{
|
{
|
||||||
std::string::size_type dot_pos = lo->first.rfind(".");
|
std::string::size_type dot_pos = lo->first.rfind(".");
|
||||||
std::string base = lo->first.substr(0, dot_pos);
|
std::string base = lo->first.substr(0, dot_pos);
|
||||||
if(do_preprocess_rules)
|
this->WriteObjectConvenienceRule(
|
||||||
{
|
ruleFileStream, "target to preprocess a source file",
|
||||||
this->WriteObjectConvenienceRule(
|
(base + ".i").c_str(), lo->second);
|
||||||
ruleFileStream, "target to preprocess a source file",
|
lo->second.HasPreprocessRule = true;
|
||||||
(base + ".i").c_str(), lo->second);
|
}
|
||||||
lo->second.HasPreprocessRule = true;
|
|
||||||
}
|
if(lang_has_assembly && do_assembly_rules)
|
||||||
if(do_assembly_rules)
|
{
|
||||||
{
|
std::string::size_type dot_pos = lo->first.rfind(".");
|
||||||
this->WriteObjectConvenienceRule(
|
std::string base = lo->first.substr(0, dot_pos);
|
||||||
ruleFileStream, "target to generate assembly for a file",
|
this->WriteObjectConvenienceRule(
|
||||||
(base + ".s").c_str(), lo->second);
|
ruleFileStream, "target to generate assembly for a file",
|
||||||
lo->second.HasAssembleRule = true;
|
(base + ".s").c_str(), lo->second);
|
||||||
}
|
lo->second.HasAssembleRule = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -702,7 +702,14 @@ cmMakefileTargetGenerator
|
|||||||
|
|
||||||
vars.Defines = definesString.c_str();
|
vars.Defines = definesString.c_str();
|
||||||
|
|
||||||
bool lang_is_c_or_cxx = ((lang == "C") || (lang == "CXX"));
|
// At the moment, it is assumed that C, C++, and Fortran have both
|
||||||
|
// assembly and preprocessor capabilities. The same is true for the
|
||||||
|
// ability to export compile commands
|
||||||
|
bool lang_has_preprocessor = ((lang == "C") ||
|
||||||
|
(lang == "CXX") ||
|
||||||
|
(lang == "Fortran"));
|
||||||
|
bool const lang_has_assembly = lang_has_preprocessor;
|
||||||
|
bool const lang_can_export_cmds = lang_has_preprocessor;
|
||||||
|
|
||||||
// Construct the compile rules.
|
// Construct the compile rules.
|
||||||
{
|
{
|
||||||
@ -715,7 +722,7 @@ cmMakefileTargetGenerator
|
|||||||
cmSystemTools::ExpandListArgument(compileRule, compileCommands);
|
cmSystemTools::ExpandListArgument(compileRule, compileCommands);
|
||||||
|
|
||||||
if (this->Makefile->IsOn("CMAKE_EXPORT_COMPILE_COMMANDS") &&
|
if (this->Makefile->IsOn("CMAKE_EXPORT_COMPILE_COMMANDS") &&
|
||||||
lang_is_c_or_cxx && compileCommands.size() == 1)
|
lang_can_export_cmds && compileCommands.size() == 1)
|
||||||
{
|
{
|
||||||
std::string compileCommand = compileCommands[0];
|
std::string compileCommand = compileCommands[0];
|
||||||
this->LocalGenerator->ExpandRuleVariables(compileCommand, vars);
|
this->LocalGenerator->ExpandRuleVariables(compileCommand, vars);
|
||||||
@ -771,9 +778,9 @@ cmMakefileTargetGenerator
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool do_preprocess_rules = lang_is_c_or_cxx &&
|
bool do_preprocess_rules = lang_has_preprocessor &&
|
||||||
this->LocalGenerator->GetCreatePreprocessedSourceRules();
|
this->LocalGenerator->GetCreatePreprocessedSourceRules();
|
||||||
bool do_assembly_rules = lang_is_c_or_cxx &&
|
bool do_assembly_rules = lang_has_assembly &&
|
||||||
this->LocalGenerator->GetCreateAssemblySourceRules();
|
this->LocalGenerator->GetCreateAssemblySourceRules();
|
||||||
if(do_preprocess_rules || do_assembly_rules)
|
if(do_preprocess_rules || do_assembly_rules)
|
||||||
{
|
{
|
||||||
|
@ -66,3 +66,29 @@ if(NOT CMAKE_Fortran_COMPILER_ID STREQUAL XL)
|
|||||||
"${err}")
|
"${err}")
|
||||||
endif()
|
endif()
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
# Test generation of preprocessed sources.
|
||||||
|
if("${CMAKE_GENERATOR}" MATCHES "Makefile" AND CMAKE_MAKE_PROGRAM)
|
||||||
|
if(CMAKE_Fortran_CREATE_PREPROCESSED_SOURCE)
|
||||||
|
# Skip running this part of the test on certain platforms
|
||||||
|
# until they are fixed.
|
||||||
|
set(MAYBE_ALL ALL)
|
||||||
|
list(LENGTH CMAKE_OSX_ARCHITECTURES ARCH_COUNT)
|
||||||
|
if(ARCH_COUNT GREATER 1)
|
||||||
|
# OSX does not support preprocessing more than one architecture.
|
||||||
|
set(MAYBE_ALL)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
add_executable(preprocess preprocess.F)
|
||||||
|
|
||||||
|
# Custom target to try preprocessing invocation.
|
||||||
|
add_custom_target(test_preprocess ${MAYBE_ALL}
|
||||||
|
COMMAND ${CMAKE_COMMAND} -E remove CMakeFiles/preprocess.dir/preprocess.F.i
|
||||||
|
COMMAND ${CMAKE_MAKE_PROGRAM} preprocess.i
|
||||||
|
COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_SOURCE_DIR}/test_preprocess.cmake
|
||||||
|
# Remove bogus file some compilers leave behind.
|
||||||
|
COMMAND ${CMAKE_COMMAND} -E remove ${CMAKE_CURRENT_SOURCE_DIR}/preprocess.s
|
||||||
|
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
|
||||||
|
)
|
||||||
|
endif()
|
||||||
|
endif()
|
||||||
|
5
Tests/FortranOnly/preprocess.F
Normal file
5
Tests/FortranOnly/preprocess.F
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
PROGRAM PREPRO
|
||||||
|
#ifndef TEST_PREPROCESSOR
|
||||||
|
PRINT *, 'Hello'
|
||||||
|
#endif
|
||||||
|
END
|
7
Tests/FortranOnly/test_preprocess.cmake
Normal file
7
Tests/FortranOnly/test_preprocess.cmake
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
set(TEST_FILE CMakeFiles/preprocess.dir/preprocess.F.i)
|
||||||
|
file(READ ${TEST_FILE} CONTENTS)
|
||||||
|
if("${CONTENTS}" MATCHES "PRINT *")
|
||||||
|
message(STATUS "${TEST_FILE} created successfully!")
|
||||||
|
else()
|
||||||
|
message(FATAL_ERROR "${TEST_FILE} creation failed!")
|
||||||
|
endif()
|
Loading…
x
Reference in New Issue
Block a user