From 7b8b71e9847bfee9b402ee3153b2100cb86adee9 Mon Sep 17 00:00:00 2001 From: Nils Wentzell Date: Mon, 2 Dec 2019 17:53:17 -0500 Subject: [PATCH] [cmake] Fix various issues occuring when using a skeleton based app as a subproject --- CMakeLists.txt | 15 ++++++++------- c++/app4triqs/CMakeLists.txt | 2 +- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 22796f04..b3b1bfdd 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -27,6 +27,7 @@ endif() # ############ # Define Project project(APP4TRIQS VERSION 2.2.0 LANGUAGES C CXX) +get_directory_property(IS_SUBPROJECT PARENT_DIRECTORY) # ############ # Load TRIQS and CPP2PY @@ -47,6 +48,7 @@ endif() if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT OR (NOT IS_ABSOLUTE ${CMAKE_INSTALL_PREFIX})) message(STATUS "No install prefix given (or invalid). Defaulting to TRIQS_ROOT") set(CMAKE_INSTALL_PREFIX ${TRIQS_ROOT} CACHE PATH "default install path" FORCE) + set(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT FALSE) endif() message(STATUS "-------- CMAKE_INSTALL_PREFIX: ${CMAKE_INSTALL_PREFIX} --------") @@ -59,9 +61,6 @@ if(NOT CMAKE_BUILD_TYPE) endif() message(STATUS "-------- BUILD-TYPE: ${CMAKE_BUILD_TYPE} --------") -# Build static libraries -set(BUILD_SHARED_LIBS OFF) - # Export the list of compile-commands into compile_commands.json set(CMAKE_EXPORT_COMPILE_COMMANDS ON) @@ -72,7 +71,9 @@ add_compile_options( ) # Create an Interface target for compiler warnings -add_library(project_warnings INTERFACE) +if(NOT TARGET project_warnings) + add_library(project_warnings INTERFACE) +endif() install(TARGETS project_warnings EXPORT app4triqs-targets) target_compile_options(project_warnings INTERFACE @@ -93,7 +94,7 @@ add_subdirectory(c++/app4triqs) # Tests option(Build_Tests "Build tests" ON) -if(Build_Tests) +if(Build_Tests AND NOT IS_SUBPROJECT) enable_testing() add_subdirectory(test) endif() @@ -104,7 +105,7 @@ if(TRIQS_WITH_PYTHON_SUPPORT) # Build the documentation option(Build_Documentation "Build documentation" OFF) - if(Build_Documentation) + if(Build_Documentation AND NOT IS_SUBPROJECT) if(NOT TRIQS_WITH_DOCUMENTATION) message(WARNING "TRIQS was installed without documentation! Cannot build documentation.") else() @@ -123,7 +124,7 @@ add_subdirectory(share) # Debian Package option(BUILD_DEBIAN_PACKAGE "Build a deb package" OFF) -if(BUILD_DEBIAN_PACKAGE) +if(BUILD_DEBIAN_PACKAGE AND NOT IS_SUBPROJECT) if(NOT CMAKE_INSTALL_PREFIX STREQUAL "/usr") message(FATAL_ERROR "CMAKE_INSTALL_PREFIX must be /usr for packaging") endif() diff --git a/c++/app4triqs/CMakeLists.txt b/c++/app4triqs/CMakeLists.txt index eecbd50f..1818f87a 100644 --- a/c++/app4triqs/CMakeLists.txt +++ b/c++/app4triqs/CMakeLists.txt @@ -1,5 +1,5 @@ file(GLOB_RECURSE sources *.cpp) -add_library(app4triqs_c ${sources}) +add_library(app4triqs_c STATIC ${sources}) # Link against triqs and enable warnings target_link_libraries(app4triqs_c PUBLIC triqs PRIVATE project_warnings)