Skip to content

Commit

Permalink
Get batch executable compiling/working on Windows; fix a few issues/.
Browse files Browse the repository at this point in the history
Get InterSpec_batch compiling/linking on Windows; this includes having CMake build LibInterSpec as a shared library, tuning compile and linking definitions to get this to work right, adding DLL exports to the headers (so .lib files with those functions will be produced).  Changing some functions around to avoid linking issues that came up.
  • Loading branch information
wcjohns committed Sep 8, 2024
1 parent e3cb8b1 commit e207544
Show file tree
Hide file tree
Showing 19 changed files with 214 additions and 75 deletions.
19 changes: 15 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -136,15 +136,15 @@ set(MAX_SPECTRUM_MEMMORY_SIZE_MB 256
)

if( (USE_BATCH_TOOLS AND NOT BUILD_AS_ELECTRON_APP) OR BUILD_AS_OSX_APP )
set( INTERSPEC_LIB_TYPE "SHARED" )
set( INTERSPEC_LIB_TYPE SHARED )
else()
set( INTERSPEC_LIB_TYPE "STATIC" )
set( INTERSPEC_LIB_TYPE STATIC )
endif()


if(WIN32)
#0x0601==Win7, 0x0501=WinXP (Wt CMakeLists.txt uses 0x0501x)
add_definitions(-D _WIN32_WINNT=0x0601 -D WINVER=0x0601 -D _SCL_SECURE_NO_WARNINGS /bigobj /MP )
#target_compile_definitions( InterSpecLib PUBLIC -D _WIN32_WINNT=0x0601 -D WINVER=0x0601 -D _SCL_SECURE_NO_WARNINGS /bigobj /MP )

# set(EXECUTABLE_OUTPUT_PATH . CACHE PATH "Path to executables" FORCE)
# set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /bigobj /MP /wd4996 /wd4267" )
Expand Down Expand Up @@ -640,7 +640,18 @@ target_compile_options(InterSpecLib PRIVATE
-Wno-inconsistent-missing-override> # Turn off a bunch of warnings like: WTreeView:399:20: warning: 'headerWidget' overrides a member function but is not marked 'override' [-Winconsistent-missing-override]
$<$<CXX_COMPILER_ID:MSVC>:
>)
if(WIN32)
#0x0601==Win7, 0x0501=WinXP (Wt CMakeLists.txt uses 0x0501x)
target_compile_definitions( InterSpecLib PUBLIC -D _WIN32_WINNT=0x0601 -D WINVER=0x0601 -D _SCL_SECURE_NO_WARNINGS )
target_compile_definitions( InterSpecLib PRIVATE InterSpec_EXPORTS )

if( USE_BATCH_TOOLS )
target_compile_options( InterSpecLib PUBLIC /bigobj )
target_compile_options( InterSpecLib PUBLIC $<$<CONFIG:Release>:/MP> )
else( USE_BATCH_TOOLS )
add_definitions( /MP )
endif( USE_BATCH_TOOLS )
endif(WIN32)

target_link_libraries(
InterSpecLib
Expand Down Expand Up @@ -875,7 +886,7 @@ configure_file(

if( WIN32 )
# The following are only needed for Wt 3.7.1, not 3.3.4
target_link_libraries( InterSpecLib PRIVATE opengl32.lib d2d1.lib windowscodecs.lib Dwrite.lib )
target_link_libraries( InterSpecLib PUBLIC opengl32.lib d2d1.lib windowscodecs.lib Dwrite.lib )
endif( WIN32 )

#if( ${PERFORM_DEVELOPER_CHECKS} EQUAL ${SpecUtils_ENABLE_EQUALITY_CHECKS} )
Expand Down
22 changes: 14 additions & 8 deletions InterSpec/AppUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ namespace AppUtils
You should url-decode the uri, before passing it in, because, for example the '?' character
is not in the allowed QR code ascii set
*/
void split_uri( std::string uri, std::string &host, std::string &path,
InterSpec_API void split_uri( std::string uri, std::string &host, std::string &path,
std::string &query, std::string &fragment );


Expand All @@ -62,15 +62,15 @@ namespace AppUtils
If a key value is empty (i.e., either '=' or ':' is first character in field), or the same key is specified multiple times
an exception will be thrown (this isnt standard - but specific to how we use URIs in InterSpec).
*/
std::map<std::string,std::string> query_str_key_values( const std::string &query );
InterSpec_API std::map<std::string,std::string> query_str_key_values( const std::string &query );

/** Similar to #query_str_key_values, but keeps key-value pairs in original order, allows duplicates, and empty values. */
// std::vector<std::pair<std::string,std::string>> query_key_values( const std::string &query );


#if( USE_BATCH_TOOLS || BUILD_AS_LOCAL_SERVER )
/** Returns the terminal character width */
unsigned terminal_width();
InterSpec_API unsigned terminal_width();
#endif

/** Returns a int, representing compile date of AppUtils.cpp.
Expand All @@ -80,14 +80,14 @@ namespace AppUtils
Note that this may differ from actual compile time of executable, if AppUtils.cpp
didnt need to get built for the current compile.
*/
uint32_t compile_date_as_int();
InterSpec_API uint32_t compile_date_as_int();

#if( !ANDROID && !IOS && !BUILD_FOR_WEB_DEPLOYMENT )
/** Returns the path of the currently running executable.
Will throw exception on failure
*/
std::string current_exe_path();
InterSpec_API std::string current_exe_path();

/** Looks at the file path passed and searches around to try and find that file, if it is a relative path.
Expand All @@ -103,7 +103,7 @@ namespace AppUtils
A value of zero means to only search in the same directory as the executable.
@param include_path [in] If the "PATH" environment variable should be searched.
*/
bool locate_file( std::string &filename,
InterSpec_API bool locate_file( std::string &filename,
const bool is_dir,
size_t max_levels_up,
const bool include_path );
Expand All @@ -119,11 +119,17 @@ namespace AppUtils
wchar_t *wenvstrings = GetEnvironmentStringsW();
...
*/
void getUtf8Args( int &argc, char **&argv );
InterSpec_API void getUtf8Args( int &argc, char **&argv );

InterSpec_API void getUtf8Args( int &argc, wchar_t **argvw, char **&argv );

/** Frees the memory allopcated by #getUtf8Args */
void cleanupUtf8Args( int &argc, char **&argv );
InterSpec_API void cleanupUtf8Args( int &argc, char **&argv );

/** Returns the standard user data directory from the OS
C:\Users\username\AppData\Roaming\InterSpec
*/
InterSpec_API std::string user_data_dir();
#endif
}//namespace AppUtils

Expand Down
12 changes: 6 additions & 6 deletions InterSpec/BatchActivity.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,24 +55,24 @@ namespace BatchActivity
Throws exception if DRF file is invalid, or specified detector could not be loaded.
If both input strings are empty, returns nullptr.
*/
std::shared_ptr<DetectorPeakResponse> init_drf_from_name( std::string drf_file, std::string drf_name );
InterSpec_API std::shared_ptr<DetectorPeakResponse> init_drf_from_name( std::string drf_file, std::string drf_name );

struct BatchActivityFitOptions
struct InterSpec_API BatchActivityFitOptions
: public BatchPeak::BatchPeakFitOptions
{
bool use_bq = false;
std::shared_ptr<DetectorPeakResponse> drf_override;
};//struct BatchActivityFitOptions


void fit_activities_in_files( const std::string &exemplar_filename,
InterSpec_API void fit_activities_in_files( const std::string &exemplar_filename,
const std::set<int> &exemplar_sample_nums,
const std::vector<std::string> &files,
const BatchActivityFitOptions &options );

struct BatchActivityFitResult
struct InterSpec_API BatchActivityFitResult
{
enum class ResultCode
enum class InterSpec_API ResultCode
{
CouldntInitializeStaticResources,
NoExemplar,
Expand Down Expand Up @@ -144,7 +144,7 @@ namespace BatchActivity
@param options The options to use for fitting peaks; note, not all options are used, as some of them are only applicable to
#fit_peaks_in_files
*/
BatchActivityFitResult fit_activities_in_file( const std::string &exemplar_filename,
InterSpec_API BatchActivityFitResult fit_activities_in_file( const std::string &exemplar_filename,
std::set<int> exemplar_sample_nums,
std::shared_ptr<const SpecMeas> cached_exemplar_n42,
const std::string &filename,
Expand Down
2 changes: 1 addition & 1 deletion InterSpec/BatchCommandLine.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

namespace BatchCommandLine
{
int run_batch_command( int argc, char **argv );
InterSpec_API int run_batch_command( int argc, char **argv );
}//namespace BatchCommandLine

#endif //BatchCommandLine_h
8 changes: 4 additions & 4 deletions InterSpec/BatchPeak.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ namespace BatchPeak
- When peaks are not fit for, print out their Currie detection limit
*/

struct BatchPeakFitOptions
struct InterSpec_API BatchPeakFitOptions
{
bool to_stdout;
bool refit_energy_cal;
Expand All @@ -85,12 +85,12 @@ namespace BatchPeak
};//struct BatchPeakFitOptions


void fit_peaks_in_files( const std::string &exemplar_filename,
InterSpec_API void fit_peaks_in_files( const std::string &exemplar_filename,
const std::set<int> &exemplar_sample_nums,
const std::vector<std::string> &files,
const BatchPeakFitOptions &options );

struct BatchPeakFitResult
struct InterSpec_API BatchPeakFitResult
{
std::string file_path;
BatchPeakFitOptions options;
Expand Down Expand Up @@ -129,7 +129,7 @@ namespace BatchPeak
@param options The options to use for fitting peaks; note, not all options are used, as some of them are only applicable to
#fit_peaks_in_files
*/
BatchPeakFitResult fit_peaks_in_file( const std::string &exemplar_filename,
InterSpec_API BatchPeakFitResult fit_peaks_in_file( const std::string &exemplar_filename,
std::set<int> exemplar_sample_nums,
std::shared_ptr<const SpecMeas> cached_exemplar_n42,
const std::string &filename,
Expand Down
2 changes: 1 addition & 1 deletion InterSpec/DecayDataBaseServer.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
//Since all operations on the database are const, with the exception of
// initialization, there is no reason to not share a single copy between all
// sessions/threads/users, so we'll do this through the following class.
class DecayDataBaseServer
class InterSpec_API DecayDataBaseServer
{
public:
//database() will throw if it is unable to initialse the database
Expand Down
10 changes: 5 additions & 5 deletions InterSpec/InterSpec.h
Original file line number Diff line number Diff line change
Expand Up @@ -184,15 +184,15 @@ class InterSpec : public Wt::WContainerWidget
ReactionGammaServer, and MassAttenuation. Other tools call
InterSpec::dataDirectory() to find the appropriate directory.
*/
static void setStaticDataDirectory( const std::string &dir );
static InterSpec_API void setStaticDataDirectory( const std::string &dir );

/** Directory where files like cross sections, materials, detector response
function, nuclear decay information, and similar are stored.
*/
static std::string staticDataDirectory();
static InterSpec_API std::string staticDataDirectory();

/** Returns if the staticDataDirectory has been explicitly set. */
static bool haveSetStaticDataDirectory();
static InterSpec_API bool haveSetStaticDataDirectory();

#if( BUILD_AS_ELECTRON_APP || IOS || ANDROID || BUILD_AS_OSX_APP || BUILD_AS_LOCAL_SERVER || BUILD_AS_WX_WIDGETS_APP || BUILD_AS_UNIT_TEST_SUITE )
/** Sets the directory were we can write write the user preference database
Expand All @@ -201,7 +201,7 @@ class InterSpec : public Wt::WContainerWidget
Will throw exception if not empty string and its an invalid directory.
*/
static void setWritableDataDirectory( const std::string &dir );
static InterSpec_API void setWritableDataDirectory( const std::string &dir );

/** Returns the location you can write files to, such as user preferences.
Expand All @@ -212,7 +212,7 @@ class InterSpec : public Wt::WContainerWidget
Will throw exception if hasnt been set (or set with empty string)
*/
static std::string writableDataDirectory();
static InterSpec_API std::string writableDataDirectory();
#endif //if( not a webapp )

/** Function called by Wt when the client reports a change in widget size. */
Expand Down
8 changes: 7 additions & 1 deletion InterSpec/InterSpecApp.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@
#include <Wt/WApplication>
#include <Wt/WContainerWidget>

#if( BUILD_AS_WX_WIDGETS_APP )
#include <functional>
#endif

class InterSpec;
namespace Wt
Expand All @@ -59,7 +62,7 @@ class SpectrumViewerTester;
#define PROMPT_USER_BEFORE_LOADING_PREVIOUS_STATE 0
#endif

class InterSpecApp : public Wt::WApplication
class InterSpec_API InterSpecApp : public Wt::WApplication
{
public:
InterSpecApp( const Wt::WEnvironment& env );
Expand Down Expand Up @@ -127,6 +130,9 @@ class InterSpecApp : public Wt::WApplication
// other not-super-fast actions.
static std::string tempDirectory();

#if( BUILD_AS_WX_WIDGETS_APP )
static void setJavascriptErrorHandler( std::function<void(std::string, std::string)> fctn );
#endif

#if( !BUILD_FOR_WEB_DEPLOYMENT )
/** Returns the token passed as part of url using parameter 'externalid' or 'apptoken'.
Expand Down
Loading

0 comments on commit e207544

Please sign in to comment.