Skip to content

Commit 32eaebf

Browse files
author
Roberto Di Remigio
committed
Solve some issues (logger usage, BuildInfo.hpp generation) with the CMake infrastructure
1 parent 7fd0c54 commit 32eaebf

File tree

9 files changed

+74
-49
lines changed

9 files changed

+74
-49
lines changed

CMakeLists.txt

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ option(DISABLE_EIGEN_OWN "Do not use Eigen3 headers shipped with the modul
2222
option(ENABLE_EIGEN_MKL "Enable Eigen3 automatic fallback to some of Intel MKL algorithms" OFF)
2323
option(ENABLE_64BIT_INTEGERS "Enable 64-bit integers" OFF)
2424
option(ENABLE_CXX11_SUPPORT "Enable C++11 compiler support" ON)
25+
# Developers only options
26+
option(ENABLE_LOGGER "Enables logger: needs C++11 support" ON)
2527
#
2628
# CMake modules
2729
#
@@ -50,6 +52,12 @@ include(MergeStaticLibs)
5052
include(FortranEnabler)
5153
fortran_enabler()
5254

55+
# If C++11 support was not detected or was disabled by the user, disable the logger
56+
get_property(has_cxx11_support GLOBAL PROPERTY CXX11_SUPPORT)
57+
if(NOT has_cxx11_support)
58+
set(ENABLE_LOGGER OFF)
59+
endif()
60+
5361
# The Python interpreter is needed to run the MergeStaticLibs.py script
5462
# If the PYTHON_INTERPRETER variable is not empty, then the user passed a custom version
5563
# of the interpreter to be used. If that's the case, set PYTHON_EXECUTABLE accordingly and
@@ -208,7 +216,6 @@ endif()
208216
# This is the very last thing we do, i.e. DO NOT add anything depending on this target!!!
209217
merge_static_libs(pcm "${libs_to_merge}")
210218
install(TARGETS pcm ARCHIVE DESTINATION lib)
211-
add_dependencies(pcm generate_build_info)
212219

213220
# configuration time in UTC
214221
execute_process(

cmake/FortranEnabler.cmake

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@
99
# This might cause multiple, redundant, calls to the FortranCInterface_VERIFY(CXX) function
1010
# and multiple, redundant, generation of the FCMangle.h header.
1111
# To avoid this, the cache variable FORTRAN_ENABLER_CALLED is set once the macro is called
12-
# for the first time.
12+
# for the first time.
1313
# The macro checks if the variable is set to TRUE. If yes, execution is skipped.
1414

1515
macro(fortran_enabler)
1616
if(NOT FORTRAN_ENABLER_CALLED)
1717
if(CMAKE_Fortran_COMPILER)
18-
# Determine Fortran name mangling, used for external linking
18+
# Determine Fortran name mangling, used for external linking
1919
if ((${CMAKE_SYSTEM_NAME} MATCHES "Darwin") AND (CMAKE_SYSTEM_VERSION VERSION_LESS 13))
2020
# 12.5.0 broken (LAB), above should trap pre-Mavericks
2121
set(CMAKE_C_FLAGS_HOLD ${CMAKE_C_FLAGS})
@@ -24,18 +24,18 @@ macro(fortran_enabler)
2424
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -m32")
2525
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -m32")
2626
endif()
27-
27+
2828
include(FortranCInterface)
2929
FortranCInterface_VERIFY(CXX)
3030
init_FCMangle()
31-
31+
3232
if ((${CMAKE_SYSTEM_NAME} MATCHES "Darwin") AND (CMAKE_SYSTEM_VERSION VERSION_LESS 13))
3333
set(CMAKE_C_FLAGS ${CMAKE_C_FLAGS_HOLD})
3434
set(CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS_HOLD})
3535
endif()
36-
36+
3737
# Set FORTRAN_ENABLER_CALLED to TRUE
38-
set(FORTRAN_ENABLER_CALLED TRUE CACHE BOOL "Fortran enabler called")
38+
set(FORTRAN_ENABLER_CALLED TRUE CACHE BOOL "Fortran enabler called")
3939
else(CMAKE_Fortran_COMPILER)
4040
message(FATAL_ERROR "Compilation of Fortran sources requires a Fortran compiler!")
4141
endif(CMAKE_Fortran_COMPILER)

cmake/build-info/BuildInfo.cmake

Lines changed: 28 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,33 @@
11
include(ConfigGitRevision)
22

3-
execute_process(
4-
COMMAND ${PYTHON_EXECUTABLE} -c "import getpass; print getpass.getuser()"
5-
TIMEOUT 1
6-
OUTPUT_VARIABLE USER_NAME
7-
OUTPUT_STRIP_TRAILING_WHITESPACE
8-
)
3+
# Generate the BuildInfo.hpp header only if the logger was enabled
4+
if (ENABLE_LOGGER)
5+
execute_process(
6+
COMMAND ${PYTHON_EXECUTABLE} -c "import getpass; print getpass.getuser()"
7+
TIMEOUT 1
8+
OUTPUT_VARIABLE USER_NAME
9+
OUTPUT_STRIP_TRAILING_WHITESPACE
10+
)
911

10-
execute_process(
11-
COMMAND ${PYTHON_EXECUTABLE} -c "from socket import gethostname; print gethostname()"
12-
TIMEOUT 1
13-
OUTPUT_VARIABLE HOST_NAME
14-
OUTPUT_STRIP_TRAILING_WHITESPACE
15-
)
12+
execute_process(
13+
COMMAND ${PYTHON_EXECUTABLE} -c "from socket import gethostname; print gethostname()"
14+
TIMEOUT 1
15+
OUTPUT_VARIABLE HOST_NAME
16+
OUTPUT_STRIP_TRAILING_WHITESPACE
17+
)
1618

17-
configure_file(
18-
${CMAKE_SOURCE_DIR}/cmake/build-info/build_info.py.in
19-
${CMAKE_BINARY_DIR}/build_info.py
20-
)
21-
22-
add_custom_target(
23-
generate_build_info
24-
COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_BINARY_DIR}/build_info.py > ${CMAKE_SOURCE_DIR}/src/utils/BuildInfo.hpp
25-
COMMAND ${CMAKE_COMMAND} -E remove -f ${CMAKE_BINARY_DIR}/build_info.py
26-
)
19+
configure_file(
20+
${CMAKE_SOURCE_DIR}/cmake/build-info/build_info.py.in
21+
${CMAKE_BINARY_DIR}/build_info.py
22+
)
2723

28-
set_source_files_properties(${CMAKE_SOURCE_DIR}/src/utils/BuildInfo.hpp PROPERTIES GENERATED 1)
24+
add_custom_target(
25+
generate_build_info
26+
COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_BINARY_DIR}/build_info.py > ${CMAKE_SOURCE_DIR}/src/utils/BuildInfo.hpp
27+
COMMAND ${CMAKE_COMMAND} -E remove -f ${CMAKE_BINARY_DIR}/build_info.py
28+
)
29+
30+
add_dependencies(pcm generate_build_info)
31+
32+
set_source_files_properties(${CMAKE_SOURCE_DIR}/src/utils/BuildInfo.hpp PROPERTIES GENERATED 1)
33+
endif()

cmake/build-info/ConfigGitRevision.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,6 @@ if(DEVELOPMENT_CODE)
4242
COMMAND ${GIT_EXECUTABLE} status -uno
4343
OUTPUT_FILE ${PROJECT_BINARY_DIR}/GIT_STATUS_AT_BUILD
4444
ERROR_QUIET
45-
)
45+
)
4646
endif()
4747
endif()

cmake/compilers/CheckCXX11Features.cmake

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ function(cxx11_check_feature FEATURE_NAME RESULT_VAR)
5353
if(NOT DEFINED ${RESULT_VAR})
5454
set(_bindir "${CMAKE_CURRENT_BINARY_DIR}/check_cxx11/cxx11_${FEATURE_NAME}")
5555

56-
set(_location "${CMAKE_SOURCE_DIR}/cmake/compilers/CheckCXX11Features")
56+
set(_location "${CMAKE_SOURCE_DIR}/cmake/compilers/CheckCXX11Features")
5757
set(_SRCFILE_BASE "${_location}/cxx11-test-${FEATURE_NAME}")
5858
set(_LOG_NAME "\"${FEATURE_NAME}\"")
5959
#message(STATUS "Checking C++11 support for ${_LOG_NAME}")
@@ -129,18 +129,18 @@ else()
129129
check_cxx_compiler_flag("-std=c++0x" _HAS_CXX0X_FLAG)
130130
set(CXX11_COMPILER_FLAGS "-std=c++0x")
131131
endif()
132-
132+
133133
set(HAS_CXX11_SUPPORT FALSE)
134134
if(_HAS_CXX11_FLAG OR _HAS_CXX0X_FLAG)
135-
set(HAS_CXX11_SUPPORT TRUE)
136-
add_definitions(-DHAS_CXX11)
135+
set(HAS_CXX11_SUPPORT TRUE)
136+
add_definitions(-DHAS_CXX11)
137137
endif()
138-
138+
139139
cxx11_check_feature("__func__" HAS_CXX11_FUNC)
140140
cxx11_check_feature("auto" HAS_CXX11_AUTO)
141141
cxx11_check_feature("auto_ret_type" HAS_CXX11_AUTO_RET_TYPE)
142142
cxx11_check_feature("class_override_final" HAS_CXX11_CLASS_OVERRIDE)
143-
cxx11_check_feature("constexpr" HAS_CXX11_CONSTEXPR)
143+
cxx11_check_feature("constexpr" HAS_CXX11_CONSTEXPR)
144144
cxx11_check_feature("cstdint" HAS_CXX11_CSTDINT_H)
145145
cxx11_check_feature("decltype" HAS_CXX11_DECLTYPE)
146146
cxx11_check_feature("initializer_list" HAS_CXX11_INITIALIZER_LIST)
@@ -157,10 +157,11 @@ else()
157157
foreach(_feature_def ${CXX11_DEFINITIONS})
158158
add_definitions(-D${_feature_def})
159159
endforeach()
160-
160+
161161
# Print list of supported features
162162
message(STATUS "Found following supported C++11 features:")
163163
foreach(FEATURE ${feature_list})
164164
message(STATUS " ${FEATURE}")
165165
endforeach()
166+
set_property(GLOBAL PROPERTY CXX11_SUPPORT TRUE)
166167
endif()

cmake/compilers/ConfigCompilerFlags.cmake

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
include(SaveCompilerFlags)
22
if(ENABLE_CXX11_SUPPORT)
33
include(CheckCXX11Features)
4-
endif()
4+
endif()
55
include(CheckCXXCompilerFlag)
66
include(CheckCCompilerFlag)
77
include(CheckFortranCompilerFlag)
@@ -22,7 +22,7 @@ if(ENABLE_VECTORIZATION)
2222
message(STATUS " C: ${C_ARCHITECTURE_FLAGS}")
2323
message(STATUS " Fortran: ${Fortran_ARCHITECTURE_FLAGS}")
2424
set(CMAKE_REQUIRED_QUIET ${tmp})
25-
endif()
25+
endif()
2626

2727
if(CMAKE_C_COMPILER_WORKS)
2828
include(CFlags)

src/interface/Interface.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,13 +100,18 @@ extern "C" void set_up_pcm(int * host_provides_input)
100100
extern "C" void tear_down_pcm()
101101
{
102102
// Delete all the global pointers, maybe in a more refined way...
103-
104103
functions.clear();
105104

106105
safe_delete(_cavity);
107106
safe_delete(_solver);
108107
}
109108

109+
extern "C" void write_timings()
110+
{
111+
// Print out timings to pcmsolver.timer.dat
112+
timerDONE("pcmsolver.timer.dat");
113+
}
114+
110115
extern "C" void compute_asc(char * potString, char * chgString, int * irrep)
111116
{
112117
std::string potFuncName(potString);

src/interface/Interface.hpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,13 @@ extern "C" void set_up_pcm(int * host_provides_input);
6464
FortranCInterface_GLOBAL_(tear_down_pcm, TEAR_DOWN_PCM)
6565
extern "C" void tear_down_pcm();
6666

67+
#define write_timings \
68+
FortranCInterface_GLOBAL_(write_timings, WRITE_TIMINGS)
69+
/*! \fn extern "C" void write_timings()
70+
* \brief Write API timings to pcmsolver.timer.dat
71+
*/
72+
extern "C" void write_timings();
73+
6774
#define compute_asc \
6875
FortranCInterface_GLOBAL_(compute_asc, COMPUTE_ASC)
6976
/*! \fn extern "C" void compute_asc(char * potString, char * chgString, int * irrep)

tests/gepol/gepol_NH3.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,22 @@
22
/*
33
* PCMSolver, an API for the Polarizable Continuum Model
44
* Copyright (C) 2013 Roberto Di Remigio, Luca Frediani and contributors
5-
*
5+
*
66
* This file is part of PCMSolver.
7-
*
8-
* PCMSolver is free software: you can redistribute it and/or modify
7+
*
8+
* PCMSolver is free software: you can redistribute it and/or modify
99
* it under the terms of the GNU Lesser General Public License as published by
1010
* the Free Software Foundation, either version 3 of the License, or
1111
* (at your option) any later version.
12-
*
12+
*
1313
* PCMSolver is distributed in the hope that it will be useful,
1414
* but WITHOUT ANY WARRANTY; without even the implied warranty of
1515
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1616
* GNU Lesser General Public License for more details.
17-
*
17+
*
1818
* You should have received a copy of the GNU Lesser General Public License
1919
* along with PCMSolver. If not, see <http://www.gnu.org/licenses/>.
20-
*
20+
*
2121
* For information on the complete list of contributors to the
2222
* PCMSolver API, see: <http://pcmsolver.github.io/pcmsolver-doc>
2323
*/
@@ -52,9 +52,9 @@ struct GePolCavityNH3Test {
5252
double probeRadius = 1.385 / convertBohrToAngstrom;
5353
double minRadius = 0.2 / convertBohrToAngstrom;
5454
cavity = GePolCavity(molec, area, probeRadius, minRadius);
55-
LOG(cavity);
55+
LOG(cavity);
5656
cavity.saveCavity("nh3.npz");
57-
LOG_TIME;
57+
LOG_TIME;
5858
}
5959
};
6060

0 commit comments

Comments
 (0)