Skip to content

Commit

Permalink
Merge pull request #17 from dsm/develop
Browse files Browse the repository at this point in the history
refactoring cmake
  • Loading branch information
ra3xdh authored Sep 3, 2024
2 parents df79ce7 + 0e9cd82 commit 3ecb782
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 238 deletions.
69 changes: 21 additions & 48 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,6 @@ project(qucs-core CXX)
include(CheckSymbolExists)
include(CheckCXXSymbolExists)

# ignore the project() managed VERSION (new in CMake 3.0)
if(POLICY CMP0048)
cmake_policy(SET CMP0048 OLD)
endif(POLICY CMP0048)


# otherwise qucsator cannot generate qucsdefs.h
add_definitions(-DDEBUG)
Expand Down Expand Up @@ -248,63 +243,41 @@ ENDIF()
# CMake adds --enable-all-exports on Cygwin (since Cygwin is supposed to be
# UNIX-like), but we need to add it explicitly for a native windows build with
# the MinGW tools.
if(WIN32)
if(WIN32 AND NOT MSVC)
set(CMAKE_SHARED_LIBRARY_CREATE_C_FLAGS
"-shared -Wl,--export-all-symbols -Wl,--enable-auto-import")
set(CMAKE_SHARED_LIBRARY_CREATE_CXX_FLAGS
"-shared -Wl,--export-all-symbols -Wl,--enable-auto-import")
set(CMAKE_EXE_LINKER_FLAGS "-Wl,--enable-auto-import")
endif()

# ~~~
# indiscriminate copy/paste from:
# http://stackoverflow.com/questions/10984442/how-to-detect-c11-support-of-a-compiler-with-cmake/20165220#20165220

# Initialize CXXFLAGS.

# \todo fix headers and use standard C++ methods * strdup is not C or C++
# standard, it is POSIX adding -fpermissive let it compile with a ton of
# warnings * problem with non-starndart _stricmp using -stdr=c++0x set g++ into
# strict ANSY, relax that with -U__STRICT_ANSI__. Could use -std=gnu++0x
# ~~~
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS ON)

if (WIN32)
if(MSVC)
add_compile_options(/Zc:__cplusplus /permissive- /MP /Zc:preprocessor)
else(MSVC)
set(CMAKE_CXX_FLAGS "-Wall -Wextra -std=c++11 -fpermissive -U__STRICT_ANSI__")
endif(MSVC)
else(WIN32)
# additional warnings
add_compile_options(-Wall -Wextra)
endif(WIN32)



# indiscriminate copy/paste from:
# http://stackoverflow.com/questions/10984442/how-to-detect-c11-support-of-a-
# compiler-with-cmake/20165220#20165220
set(CMAKE_CXX_FLAGS_DEBUG "-O0 -g")
set(CMAKE_CXX_FLAGS_MINSIZEREL "-Os -DNDEBUG")
set(CMAKE_CXX_FLAGS_RELEASE "-O3 -DNDEBUG")
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O2 -g")

# Compiler-specific C++11 activation.
if("${CMAKE_CXX_COMPILER_ID}" MATCHES "GNU")
execute_process(COMMAND ${CMAKE_CXX_COMPILER} -dumpversion
OUTPUT_VARIABLE GCC_VERSION)
if(NOT (GCC_VERSION VERSION_GREATER 4.7 OR GCC_VERSION VERSION_EQUAL 4.7))
message(FATAL_ERROR "${PROJECT_NAME} requires g++ 4.7 or greater.")
endif()
elseif("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++")
else()
message(FATAL_ERROR "Your C++ compiler does not support C++11.")
if (CMAKE_BUILD_TYPE STREQUAL "Debug")
if (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
add_compile_definitions(_CRT_SECURE_NO_WARNINGS _SCL_SECURE_NO_WARNINGS)
add_compile_options(/permissive- /Zc:__cplusplus /Zc:preprocessor /MP /Od /vmg)
add_compile_options(/wd4244 /wd4267 /wd4312)
else()
add_compile_options(-Wall -Wextra -O0 -g)
if (CMAKE_CXX_COMPILER_ID MATCHES "^AppleClang$|^Clang$")
add_compile_options(-Wno-ignored-attributes)
endif()
endif()
elseif(CMAKE_BUILD_TYPE STREQUAL "Release")
if (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
add_compile_definitions(_CRT_SECURE_NO_WARNINGS _SCL_SECURE_NO_WARNINGS)
string(REGEX REPLACE "/W3" "/w" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
add_compile_options(/permissive- /Zc:__cplusplus /Zc:preprocessor /MP /vmg)
else()
add_compile_options(-w)
endif()
endif()


#
# Set position independent code PIC
#
Expand Down
190 changes: 0 additions & 190 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,52 +14,10 @@ if(NOT WIN32)
endif()
endif()

#
# Checks for header files. AC_HEADER_STDC !! obsolete, need to check? Define
# STDC_HEADERS if the system has ANSI C header files. Specifically, this macro
# checks for `stdlib.h', `stdarg.h', `string.h', and `float.h'; Lifted the cmake
# checks from gd-libdg, Lua https://bitbucket.org/libgd/gd-libgd
# https://github.com/LuaDist/libgd/tree/master/cmake/modules
include(CheckIncludeFiles)
set(CMAKE_REQUIRED_INCLUDES "/usr/include" "/usr/local/include")
set(CMAKE_MODULE_PATH "${qucs-core_SOURCE_DIR}/cmake/modules")
include(AC_HEADER_STDC)

#
# Further header checks
#
include(CheckIncludeFile)

# list of headers to be checked
set(INCLUDES ieeefp.h memory.h stddef.h stdlib.h string.h unistd.h)

#
# Check if header can be included. * Define HAVE_[basename]_H to 1 if you have
# the header.
#
foreach(header ${INCLUDES})
get_filename_component(base ${header} NAME_WE)
string(TOUPPER ${base} base)
check_include_file(${header} HAVE_${base}_H)
# MESSAGE(STATUS "${header} --> ${HAVE_${base}_H}")
endforeach()

# Checks for typedefs, structures, and compiler characteristics. AC_C_CONST
# !!obsolete AC_C_CONST "This macro is obsolescent, as current C compilers
# support `const'. New programs need not use this macro."

#
# Check for type sizes.
#
include(CheckTypeSize)
check_type_size("short" SIZEOF_SHORT)
check_type_size("int" SIZEOF_INT)
check_type_size("long" SIZEOF_LONG)
check_type_size("double" SIZEOF_DOUBLE)
check_type_size("long double" SIZEOF_LONG_DOUBLE)
# MESSAGE(STATUS "short ${SIZEOF_SHORT}" ) MESSAGE(STATUS "int ${SIZEOF_INT}"
# ) MESSAGE(STATUS "long ${SIZEOF_LONG}" ) MESSAGE(STATUS "double
# ${SIZEOF_DOUBLE}" ) MESSAGE(STATUS "long double ${SIZEOF_LONG_DOUBLE}" )

#
# Check for double type. * valid types are: double, float and long double. *
Expand Down Expand Up @@ -107,154 +65,6 @@ set(QUCS_DOUBLE_SIZE ${DoubleSize})
configure_file("${qucs-core_SOURCE_DIR}/qucs_typedefs.h.cmake"
"${qucs-core_BINARY_DIR}/qucs_typedefs.h")

#
# Check for library functions * not all functions seem to be used after defined.
# TODO check for HAVE_{func}
#
include(CheckFunctionExists)
set(REQUIRED_FUNCTIONS
floor
pow
exp
sqrt
log10
log
cos
sin
acos
asin # for real.cpp
tan
atan
sinh
cosh
tanh
fabs
modf
atan2
jn
yn
erf
erfc # for fspecial.cpp
round
trunc
acosh
asinh # for real.cpp
)

foreach(func ${REQUIRED_FUNCTIONS})
string(TOUPPER ${func} FNAME)
check_cxx_symbol_exists(${func} cmath HAVE_${FNAME})
# message(STATUS "${func} --> ${HAVE_${FNAME}}")
endforeach()

#
# Checks for complex classes and functions, as in the Autotools scripts.
#
# AC_CXX_NAMESPACES !!custom m4 AC_CXX_HAVE_COMPLEX !!custom m4
# AC_CXX_HAVE_TR1_COMPLEX !!custom m4 AC_CHECK_CXX_COMPLEX_FUNCS([cos cosh exp
# log log10 sin sinh sqrt tan tanh]) !!custom m4
# AC_CHECK_CXX_COMPLEX_FUNCS([acos acosh asin asinh atan atanh])
# AC_CHECK_CXX_COMPLEX_FUNCS([log2 norm]) AC_CHECK_CXX_COMPLEX_POW
# AC_CHECK_CXX_COMPLEX_ATAN2 !failed, need libstdc?
# AC_CHECK_CXX_COMPLEX_FMOD !failed: AC_CHECK_CXX_COMPLEX_POLAR
# AC_CHECK_CXX_COMPLEX_POLAR_COMPLEX !failed

#
# Check whether the compiler has complex<T>
#
try_compile(HAVE_COMPLEX ${CMAKE_BINARY_DIR}
${qucs-core_SOURCE_DIR}/cmake/complex.cpp OUTPUT_VARIABLE TRY_OUT)
if(NOT HAVE_COMPLEX)
message(SEND_ERROR "HAVE_COMPLEX failed") # ${TRY_OUT}")
endif()

#
# Check std::vector::erase iterator type [const_iterator | iterator]
#
message(STATUS "Checking HAVE_ERASE_CONSTANT_ITERATOR")
try_compile(
HAVE_ERASE_CONSTANT_ITERATOR ${CMAKE_BINARY_DIR}
${qucs-core_SOURCE_DIR}/cmake/erase_iterator_type.cpp OUTPUT_VARIABLE TRY_OUT)
if(HAVE_ERASE_CONSTANT_ITERATOR)
message(STATUS "Using std::vector:erase iterator type : const_iterator")
else()
message(STATUS "Using std::vector:erase iterator type : iterator")
endif()

#
# Check for list of complex functions.
#
set(COMPLEX_FUNCS_GRP1
acos
acosh
asin
asinh
atan
atanh
cos
cosh
exp
log
log10
sin
sinh
sqrt
tan
tanh
log2
norm)
set(COMPLEX_FUNCS_GRP2 pow atan2 fmod polar polar_complex)

#
# test complex function group 1 code inlined to easily replace '${func}'
#
foreach(func ${COMPLEX_FUNCS_GRP1})
set(code
" #include <complex>
using namespace std\;
#ifdef log2
#undef log2
#endif
int main() {
complex<double> a\;
${func}(a)\;
return 0\;
}")

file(WRITE ${qucs-core_SOURCE_DIR}/cmake/test_${func}.cpp ${code})

string(TOUPPER ${func} FNAME)

message(STATUS "Checking HAVE_CXX_COMPLEX_${FNAME}")

try_compile(
HAVE_CXX_COMPLEX_${FNAME} ${CMAKE_BINARY_DIR}
${qucs-core_SOURCE_DIR}/cmake/test_${func}.cpp OUTPUT_VARIABLE TRY_OUT)
if(NOT HAVE_CXX_COMPLEX_${FNAME})
message(STATUS "HAVE_CXX_COMPLEX_${FNAME} failed") # ${TRY_OUT}")
endif()

file(REMOVE ${qucs-core_SOURCE_DIR}/cmake/test_${func}.cpp ${code})
endforeach()

#
# test complex function group 2 use prepared source file.
#
foreach(func ${COMPLEX_FUNCS_GRP2})
string(TOUPPER ${func} FNAME)

message(STATUS "Checking HAVE_CXX_COMPLEX_${FNAME}")

try_compile(
HAVE_CXX_COMPLEX_${FNAME} ${CMAKE_BINARY_DIR}
${qucs-core_SOURCE_DIR}/cmake/complex_${func}.cpp
COMPILE_DEFINITIONS -DHAVE_NAMESPACES -DHAVE_COMPLEX -DHAVE_TR1_COMPLEX
OUTPUT_VARIABLE TRY_OUT)
if(NOT HAVE_CXX_COMPLEX_${FNAME})
message(STATUS "HAVE_CXX_COMPLEX_${FNAME} failed") # ${TRY_OUT}")
endif()
endforeach()

#
# Configure the header config.h, interpolate above definitions.
Expand Down

0 comments on commit 3ecb782

Please sign in to comment.