[flang] Add simple recursive CMake directory structure
authorStephane Chauveau <stephane@chauveau-central.net>
Mon, 19 Feb 2018 13:28:12 +0000 (14:28 +0100)
committerStephane Chauveau <stephane@chauveau-central.net>
Mon, 19 Feb 2018 13:28:12 +0000 (14:28 +0100)
Original-commit: flang-compiler/f18@a021b2ca768c2b8c03d626739d0754ba99e463d2
Reviewed-on: https://github.com/flang-compiler/f18/pull/13
Tree-same-pre-rewrite: false

flang/CMakeLists.txt
flang/include/flang/CMakeLists.txt [new file with mode: 0644]
flang/lib/CMakeLists.txt [new file with mode: 0644]
flang/lib/parser/CMakeLists.txt [new file with mode: 0644]
flang/lib/semantics/CMakeLists.txt [new file with mode: 0644]
flang/tools/CMakeLists.txt [new file with mode: 0644]
flang/tools/f18/CMakeLists.txt [new file with mode: 0644]

index 1f74767..a793493 100644 (file)
@@ -1,42 +1,62 @@
 cmake_minimum_required(VERSION 3.9.0)
 
-set(GCC /home/sw/thirdparty/gcc/gcc-7.3.0/linux86-64/redhat)
-set(CMAKE_CXX_COMPILER "${GCC}/bin/g++")
-set(CMAKE_INSTALL_RPATH "${GCC}/lib64")
-set(CMAKE_BUILD_WITH_INSTALL_RPATH true)
-
-# project(f18)
-set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -pedantic -std=c++17")
-set(CMAKE_CXX_FLAGS_RELEASE "-O2 -DDEBUG")
-set(CMAKE_CXX_FLAGS_MINSIZEREL "-O2 '-DCHECK=(void)'")
-set(CMAKE_CXX_FLAGS_DEBUG "-g -DDEBUG")
-
-set(SOURCES_F18
-  tools/f18/f18.cc
-  lib/parser/char-buffer.cc
-  lib/parser/idioms.cc
-  lib/parser/message.cc
-  lib/parser/parse-tree.cc
-  lib/parser/preprocessor.cc
-  lib/parser/prescan.cc
-  lib/parser/provenance.cc
-  lib/parser/source.cc
-  lib/parser/token-sequence.cc
-)
-add_executable(f18 ${SOURCES_F18})
-
-set(SOURCES_TEST_TYPE
-  tools/f18/test-type.cc
-  lib/semantics/type.cc
-  lib/semantics/attr.cc
-  lib/parser/char-buffer.cc
-  lib/parser/idioms.cc
-  lib/parser/message.cc
-  lib/parser/parse-tree.cc
-  lib/parser/preprocessor.cc
-  lib/parser/prescan.cc
-  lib/parser/provenance.cc
-  lib/parser/source.cc
-  lib/parser/token-sequence.cc
-)
-add_executable(test-type ${SOURCES_TEST_TYPE})
+#
+# Reminder: The normal way to set the compiler is via the CXX environment variable
+#  
+#   CXX=/opt/gcc-7.2.0/bin/g++ cmake .../f18  
+#
+# but for convenience we provide the following cmake variables to 
+# use an existing gcc installation directory.
+#
+
+# Pass '-DPGI=1' to cmake to use the latest gcc installation at PGI 
+if( PGI )  
+  set(GCC /home/sw/thirdparty/gcc/gcc-7.3.0/linux86-64/redhat)
+endif()
+
+# Pass -DGCC=... to cmake to use a specific gcc installation 
+if( GCC ) 
+  set(CMAKE_CXX_COMPILER "${GCC}/bin/g++")
+  set(CMAKE_CC_COMPILER "${GCC}/bin/gcc")
+  set(CMAKE_INSTALL_RPATH "${GCC}/lib64")
+  set(CMAKE_BUILD_WITH_INSTALL_RPATH true)
+endif()
+
+# Reminder: Setting CMAKE_CXX_COMPILER must be done before calling project() 
+
+project(f18 CXX)
+
+if( NOT CMAKE_BUILD_TYPE )
+  set( CMAKE_BUILD_TYPE Debug )
+endif()
+message(STATUS "Build Type: ${CMAKE_BUILD_TYPE}")
+
+if(CMAKE_COMPILER_IS_GNUCXX)
+   set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17")
+   set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -pedantic")
+   set(CMAKE_CXX_FLAGS_RELEASE    "-O2 -DDEBUG")
+   set(CMAKE_CXX_FLAGS_MINSIZEREL "-O2 '-DCHECK=(void)'")
+   set(CMAKE_CXX_FLAGS_DEBUG      "-g -DDEBUG")
+endif()
+
+set(FLANG_VERSION_MAJOR      "0")
+set(FLANG_VERSION_MINOR      "1")
+set(FLANG_VERSION_PATCHLEVEL "0")
+set(FLANG_VERSION "${FLANG_VERSION_MAJOR}.${FLANG_VERSION_MINOR}.${FLANG_VERSION_PATCHLEVEL}")
+message(STATUS "FLANG version: ${FLANG_VERSION}")
+
+set(FLANG_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
+set(FLANG_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR})
+
+include_directories(BEFORE
+  ${FLANG_BINARY_DIR}/include
+  ${FLANG_SOURCE_DIR}/include
+  )
+
+add_subdirectory(include/flang)
+add_subdirectory(lib)
+add_subdirectory(tools)
+
+configure_file(
+  ${FLANG_SOURCE_DIR}/include/flang/Config/config.h.cmake
+  ${FLANG_BINARY_DIR}/include/flang/Config/config.h)
diff --git a/flang/include/flang/CMakeLists.txt b/flang/include/flang/CMakeLists.txt
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/flang/lib/CMakeLists.txt b/flang/lib/CMakeLists.txt
new file mode 100644 (file)
index 0000000..b856b35
--- /dev/null
@@ -0,0 +1,3 @@
+
+add_subdirectory(parser)
+add_subdirectory(semantics)
diff --git a/flang/lib/parser/CMakeLists.txt b/flang/lib/parser/CMakeLists.txt
new file mode 100644 (file)
index 0000000..6ab876f
--- /dev/null
@@ -0,0 +1,12 @@
+
+add_library( FlangParser
+  char-buffer.cc
+  idioms.cc
+  message.cc
+  parse-tree.cc
+  preprocessor.cc
+  prescan.cc
+  provenance.cc
+  source.cc
+  token-sequence.cc
+)
diff --git a/flang/lib/semantics/CMakeLists.txt b/flang/lib/semantics/CMakeLists.txt
new file mode 100644 (file)
index 0000000..99ac06e
--- /dev/null
@@ -0,0 +1,5 @@
+
+add_library( FlangSemantics
+  type.cc
+  attr.cc
+)
diff --git a/flang/tools/CMakeLists.txt b/flang/tools/CMakeLists.txt
new file mode 100644 (file)
index 0000000..5f9f2e5
--- /dev/null
@@ -0,0 +1,2 @@
+
+add_subdirectory(f18)
diff --git a/flang/tools/f18/CMakeLists.txt b/flang/tools/f18/CMakeLists.txt
new file mode 100644 (file)
index 0000000..4e1aa40
--- /dev/null
@@ -0,0 +1,22 @@
+
+######## f18 ##########
+
+add_executable( f18  
+  f18.cc
+)
+target_link_libraries( f18
+  FlangParser
+  )
+
+######## test-type ##########
+
+add_executable( test-type  
+  test-type.cc
+)
+
+target_link_libraries( test-type
+  FlangParser
+  FlangSemantics
+  )
+
+